forked from gnarayan/decat_pointings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editjson.py
29 lines (25 loc) · 1.12 KB
/
editjson.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
import json
import os
from copy import copy
def edit(file,priority,filters,exptimes,outfile):
with open(file) as f:
data = json.load(f)
pointing = copy(data[0])
outlist = []
for filt,e in zip(filters,exptimes):
pointing['filter'] = filt
pointing['exptime'] = float(e)
pointing['comment'] = pointing['comment'].replace('_P1','_P%s'%priority).replace('_P2','_P%s'%priority).replace('_P3','_P%s'%priority)
pointing['object'] = pointing['object'].replace('_P1','_P%s'%priority).replace('_P2','_P%s'%priority).replace('_P3','_P%s'%priority)
outlist.append(copy(pointing))
with open(outfile, 'w') as json_file:
json.dump(outlist, json_file, indent=4)
def getfiltersexptimes(file):
dict = {}
with open(file) as f:
data = json.load(f)
for d in data:
dict[d['filter']] = d['exptime']
return dict
if __name__ == '__main__':
edit('jsons/2020B-0053_DEBASS_Brout/TEMPLATE/2021inj.json',1,['g','r','i','z','Y'],['15','15','15','15','15'],'jsons/2020B-0053_DEBASS_Brout/test/2021inj_P1.json')