Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/modlmf/modlmf.py
1127 views
1
# -*- coding: utf-8 -*-
2
r""" Import mod l modular forms.
3
4
Note: This code can be run on all files in any order. Even if you
5
rerun this code on previously entered files, it should have no affect.
6
This code checks if the entry exists, if so returns that and updates
7
with new information. If the entry does not exist then it creates it
8
and returns that.
9
10
"""
11
12
import sys
13
import re
14
import json
15
import os
16
import gzip
17
18
from lmfdb.base import getDBConnection
19
20
C= getDBConnection()
21
import yaml
22
pw_dict = yaml.load(open(os.path.join(os.getcwd(), "passwords.yaml")))
23
username = pw_dict['data']['username']
24
password = pw_dict['data']['password']
25
C['mod_l_eigenvalues'].authenticate('editor', password)
26
modlmf = C['mod_l_eigenvalues'].modlmf
27
28
saving = True
29
30
def sd(f):
31
for k in f.keys():
32
print('%s ---> %s'%(k, f[k]))
33
34
def makels(li):
35
li2 = [str(x) for x in li]
36
return ','.join(li2)
37
38
def string2list(s):
39
s = str(s)
40
if s=='': return []
41
return [int(a) for a in s.split(',')]
42
43
44
def base_label(characteristic, deg, level, weight, dirchar):
45
field=str(characteristic)
46
dirchar_index=str(dirchar).split('.')[2]
47
if int(deg)!=1:
48
field=str(characteristic)+"e"+str(deg)
49
return ".".join([field,str(level),str(weight),dirchar_index])
50
51
def last_label(base_label, n):
52
return ".".join([str(base_label),str(n)])
53
54
# The following create_index command checks if there is an index on
55
# label, dimension, determinant and level.
56
57
58
modlmf.create_index('characteristic')
59
modlmf.create_index('deg')
60
modlmf.create_index('level')
61
modlmf.create_index('weight_grading')
62
modlmf.create_index('dirchar')
63
64
print("finished indices")
65
66
67
## Main importing function
68
69
label_dict={}
70
71
def label_lookup(base_label):
72
if base_label in label_dict:
73
n=label_dict[base_label]+1
74
label_dict[base_label]=n
75
return n
76
label_dict[base_label]=1
77
return 1
78
79
def do_import(ll):
80
characteristic,deg,level,weight_grading,reducible,cuspidal_lift,dirchar,atkinlehner,n_coeffs,coeffs,ordinary,min_theta_weight,theta_cycle = ll
81
mykeys =['characteristic','deg','level','weight_grading','reducible','cuspidal_lift','dirchar','atkinlehner','n_coeffs','coeffs','ordinary','min_theta_weight','theta_cycle']
82
data = {}
83
for j in range(len(mykeys)):
84
data[mykeys[j]] = ll[j]
85
86
blabel = base_label(data['characteristic'],data['deg'],data['level'], data['weight_grading'], data['dirchar'])
87
data['base_label'] = blabel
88
data['index'] = label_lookup(blabel)
89
label= last_label(blabel, data['index'])
90
data['label'] = label
91
# we need still to organize this better with respect to tie breaks
92
93
modl_mf = modlmf.find_one({'label': label})
94
95
if modl_mf is None:
96
print("new mod l modular form")
97
modl_mf = data
98
else:
99
print("mod l modular form already in the database")
100
modl_mf.update(data)
101
if saving:
102
modlmf.update({'label': label} , {"$set": modl_mf}, upsert=True)
103
104
105
106
# Loop over files
107
108
for path in sys.argv[1:]:
109
print(path)
110
filename = os.path.basename(path)
111
fn = gzip.open(path) if filename[-3:] == '.gz' else open(path)
112
for line in fn.readlines():
113
line.strip()
114
if re.match(r'\S',line):
115
l = json.loads(line)
116
do_import(l)
117
118