-
Notifications
You must be signed in to change notification settings - Fork 6
/
makeValidNT.py
75 lines (58 loc) · 1.83 KB
/
makeValidNT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import json
import sys
import argparse
parser = argparse.ArgumentParser(description='Makes a valid normtag given a CSV from brilcalc')
parser.add_argument('-i', '--input', type=str, default="", help='CSV file from brilcalc.')
parser.add_argument('-o', '--output', type=str, default="mynormtag.json", help='output file name')
parser.add_argument('-n', '--normtag', type=str, default="pccLUM15001", help='String of normtag')
args = parser.parse_args()
def CondensedList(fullList):
condensedList=[]
lastLS=0
for iLS in fullList:
if iLS==fullList[0]:
condensedList.append([iLS,-1])
elif iLS-lastLS>1:
condensedList[-1][1]=lastLS
condensedList.append([iLS,-1])
if iLS==fullList[-1]:
condensedList[-1][1]=iLS
lastLS=iLS
return condensedList
if args.input=="":
print "File needed to analyze"
sys.exit(-1)
else:
try:
csvfile=open(args.input)
except:
print "Can't open",args.input,"... exiting"
sys.exit(-1)
lines=csvfile.readlines()
csvfile.close()
validData={}
for line in lines:
try:
items=line.split(",")
run=int(items[0].split(":")[0])
LS=int(items[1].split(":")[0])
except:
print "Can't parse",line
continue
if run not in validData.keys():
validData[run]=[]
validData[run].append(LS)
runs=validData.keys()
runs.sort()
outputFile=open(args.output,"w")
outputFile.write("[\n")
for run in runs:
validData[run].sort()
print run,
print "condensed",CondensedList(validData[run])
# example line: ["hfoc16v1",{"271037":[[1,15]]}],
outputFile.write("[\""+args.normtag+"\",{\""+str(run)+"\":"+str(CondensedList(validData[run]))+"}]")
if run != runs[-1]:
outputFile.write(",\n")
outputFile.write("\n]\n")
outputFile.close()