Path: blob/main/scripts/number_fields/import_galois_modules.py
1128 views
# -*- coding: utf-8 -*-1r""" Import data from Alex Bartel on the Galois module structure2of unit groups of Galois number fields. This script imports information3on the Galois modules themselves.45Initial version 7/1467Data is imported to the collection 'fields' in the database 'numberfields'.8The structure of the database entries is described in lmfdb/Database-info.910Each file is a list of lists11[[n,t], name, generator matrices...]1213The number of generator matrices depends on the group1415This expects there to be one group per file1617Database entries have fields n, t, index, name, gens1819The first entry should be the trivial representation, and it has a fourth20argument 1=complete, 0=incomplete (inf many), -1 =incomplete (just partial21list)2223"""2425import sys26import re27import json28import gzip29from sage.all import os3031from pymongo.mongo_client import MongoClient32gmods = MongoClient(port=37010).transitivegroups.Gmodules3334def sd(f):35for k in f.keys():36print('%s ---> %s'%(k, f[k]))3738def string2list(s):39s = str(s)40if s=='': return []41return [int(a) for a in s.split(',')]4243def list2string(li):44li2 = [str(x) for x in li]45return ','.join(li2)4647def do_import(ll):48global count49#print "Importing data %s" % str(ll)50data = {}51data['n'] = ll[0][0]52data['t'] = ll[0][1]53data['name'] = ll[1]54data['index'] = count55# gens = []56# for j in range(2,len(ll)):57# gens.append(ll[j])58# data['gens'] = gens59data['gens'] = ll[2]60data['dim']= len(ll[2][0][1][0])61data['complete'] = -162if len(ll)>3:63data['complete'] = ll[3]64gmods.save(data)65#print data66count += 16768# Do the main work6970for path in sys.argv[1:]:71print(path)72filename = os.path.basename(path)73fn = gzip.open(path) if filename[-3:] == '.gz' else open(path)74count = 075for line in fn.readlines():76line = line.strip()77if re.match(r'\S',line):78l = json.loads(line)79do_import(l)80818283