Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/number_fields/import_galois_modules.py
1128 views
1
# -*- coding: utf-8 -*-
2
r""" Import data from Alex Bartel on the Galois module structure
3
of unit groups of Galois number fields. This script imports information
4
on the Galois modules themselves.
5
6
Initial version 7/14
7
8
Data is imported to the collection 'fields' in the database 'numberfields'.
9
The structure of the database entries is described in lmfdb/Database-info.
10
11
Each file is a list of lists
12
[[n,t], name, generator matrices...]
13
14
The number of generator matrices depends on the group
15
16
This expects there to be one group per file
17
18
Database entries have fields n, t, index, name, gens
19
20
The first entry should be the trivial representation, and it has a fourth
21
argument 1=complete, 0=incomplete (inf many), -1 =incomplete (just partial
22
list)
23
24
"""
25
26
import sys
27
import re
28
import json
29
import gzip
30
from sage.all import os
31
32
from pymongo.mongo_client import MongoClient
33
gmods = MongoClient(port=37010).transitivegroups.Gmodules
34
35
def sd(f):
36
for k in f.keys():
37
print('%s ---> %s'%(k, f[k]))
38
39
def string2list(s):
40
s = str(s)
41
if s=='': return []
42
return [int(a) for a in s.split(',')]
43
44
def list2string(li):
45
li2 = [str(x) for x in li]
46
return ','.join(li2)
47
48
def do_import(ll):
49
global count
50
#print "Importing data %s" % str(ll)
51
data = {}
52
data['n'] = ll[0][0]
53
data['t'] = ll[0][1]
54
data['name'] = ll[1]
55
data['index'] = count
56
# gens = []
57
# for j in range(2,len(ll)):
58
# gens.append(ll[j])
59
# data['gens'] = gens
60
data['gens'] = ll[2]
61
data['dim']= len(ll[2][0][1][0])
62
data['complete'] = -1
63
if len(ll)>3:
64
data['complete'] = ll[3]
65
gmods.save(data)
66
#print data
67
count += 1
68
69
# Do the main work
70
71
for path in sys.argv[1:]:
72
print(path)
73
filename = os.path.basename(path)
74
fn = gzip.open(path) if filename[-3:] == '.gz' else open(path)
75
count = 0
76
for line in fn.readlines():
77
line = line.strip()
78
if re.match(r'\S',line):
79
l = json.loads(line)
80
do_import(l)
81
82
83