Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/genus2_curves/load_ratpts.py
1127 views
1
# -*- coding: utf-8 -*-
2
3
import lmfdb
4
import ast
5
import pymongo
6
from data_mgt.utilities.rewrite import rewrite_collection
7
8
# expected input file format is
9
# label:eqn:rank:ratpts:ratpts-verified:mwgroup:mwgens:mwgroup-verified:rank-verified
10
# ratpts contains a list of triples of ints representing projective points
11
# mwgroup is a list of invariants for finitely generated abelian group (0 means Z/0 = Z)
12
# mwgens is a list of degree 0 divisors on the Jacobian in Magma's Mumford representation
13
14
def load_ratpts_data(filename):
15
db = lmfdb.base.getDBConnection().genus2_curves
16
with open(filename,'r') as input_file:
17
data = input_file.read()
18
outrecs = []
19
for inrec in data.split('\n'):
20
if not inrec:
21
break
22
items = inrec.split(':')
23
# assert len(items) == 9
24
assert len(items) == 5
25
label = items[0]
26
# Lrank = int(items[2])
27
ratpts = ast.literal_eval(items[3])
28
ratpts_v = True if int(items[4]) == 1 else False
29
# mwgroup = ast.literal_eval(items[5])
30
# mwrank = len([n for n in mwgroup if n == 0])
31
# mwgens = ast.literal_eval(items[6])
32
# mwgroup_v = True if int(items[7]) == 1 else False
33
# mwrank_v = True if int(items[8]) == 1 else False
34
# if mwrank < Lrank and not mwrank_v:
35
# print "Skipping record for %s with unverified mwrank %d < Lrank %d"%(label,mwrank,Lrank)
36
# continue
37
# if mwrank != Lrank:
38
# "Hooray you have found a counterexample to BSD! Or your data is wrong/incomplete :("
39
# print inrec
40
# return
41
rec = { 'label': label,
42
'num_rat_pts': int(len(ratpts)),
43
'rat_pts': [[str(c) for c in p] for p in ratpts],
44
'rat_pts_v': bool(ratpts_v) }
45
# 'mw_group' : [int(a) for a in mwgroup],
46
# 'mw_rank' : int(mwrank),
47
# 'mw_gens' : mwgens, # divisor coefficients should already be encoded as strings
48
# 'mw_group_v': bool(mwgroup_v),
49
# 'mw_rank_v': bool(mwrank_v) }
50
outrecs.append(rec)
51
if db.ratpts.new.count() > 0:
52
print("overwriting existing ratpts.new")
53
db.ratpts.new.drop()
54
db.ratpts.new.insert_many(outrecs)
55
assert db.ratpts.new.count() == len(outrecs)
56
db.ratpts.new.create_index([('label',pymongo.ASCENDING)])
57
if db.ratpts.old.count() > 0:
58
db.ratpts.old.drop()
59
if db.ratpts.count() > 0:
60
db.ratpts.rename('ratpts.old')
61
db.ratpts.new.rename('ratpts')
62
63
# function to be passed to rewrite_collection
64
def ratpts_update(rec):
65
db = lmfdb.base.getDBConnection().genus2_curves
66
r = db.ratpts.find_one({'label':rec['label']})
67
rec['num_rat_pts'] = r['num_rat_pts']
68
return rec
69
print("Updating num_rat_pts in curves collection")
70
rewrite_collection(db, "curves","curves.new", ratpts_update)
71
print("renaming curves.new to curves")
72
db.curves.old.drop()
73
db.curves.rename("curves.old")
74
db.curves.new.rename("curves")
75
db.curves.create_index([('num_rat_pts',int(1))])
76
print("Done!")
77
78