forked from STAC-IITMandi/9th-Inter-iit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat_json.py
73 lines (61 loc) · 2.56 KB
/
cat_json.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
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 20 13:12:38 2021
@author: dell
"""
import cat_functions
import json
import os
import sys
def catA_json(data_dir="data", Fields=['Type', 'RAh', 'RAm', 'RAs', 'u_RAs', 'DE-', 'DEd', 'DEm', 'DEs', 'u_DEs', 'GLON', 'GLAT', 'Pos', 'e_Pos', 'Opt', 'r_Opt', 'Vmag', 'Vmagl', 'u_Vmag', 'B-V', 'u_B-V', 'B-Vl', 'U-B', 'l_E(B-V)', 'E(B-V)', 'l_E(B-V)2', 'E(B-V)2', 'u_E(B-V)', 'r_Vmag', 'l_Fx', 'Fx', 'Fxu', 'Range', 'r_Fx', 'Porb', 'Porb2', 'u_Porb', 'Ppulse', 'u_Ppulse', 'r_Ppulse', 'Cat', 'SpType', 'Name2', 'u_Name2', 'Name3']):
A=cat_functions.catA(dir_name=data_dir)
data=[]
for i in range(280):
data.append({'Name': A.index[i]})
for field in Fields:
data[-1].update({field: A[field][i]})
objects={"objects":data}
with open(os.path.join(data_dir, "Dataset.json"), 'w') as f:
json.dump(objects, f, indent=3)
def catB_json(data_dir="data", Fields=['DnT','ProposalId','TargetID','Ra','Dec','Observation_Id','Source_Name','Instrument']):
B=cat_functions.catB(dir_name=data_dir)
data=[]
for i in range(900):
data.append({})
for field in Fields:
data[-1].update({field: B[field][i]})
objects={"objects":data}
with open(os.path.join(data_dir, "Astrosat.json"), 'w') as f:
json.dump(objects, f, indent=3)
def catC_json(data_dir="data"):
publications=cat_functions.catC(dir_name=data_dir)
with open(os.path.join(data_dir, "Astrosat_Pubs.json"), 'w') as f:
json.dump(publications, f, indent=3)
def BtoC_json(data_dir="data"):
B=json.load(open(os.path.join(data_dir, "Astrosat.json")))
C=json.load(open(os.path.join(data_dir, "Astrosat_Pubs.json")))
B = B['objects']
C = C['publications']
search=cat_functions.MatchingBtoC(B,C)
with open(os.path.join(data_dir, "BtoC.json"), 'w') as f:
json.dump(search, f, indent=3)
def AtoB_json(data_dir="data"):
A=json.load(open(os.path.join(data_dir, "Dataset.json")))
B=json.load(open(os.path.join(data_dir, "Astrosat.json")))
A = A['objects']
B = B['objects']
search = cat_functions.MatchingBtoA(A, B)
with open(os.path.join(data_dir, 'Dataset.json'), 'w') as outfile:
json.dump(search, outfile, indent=3)
if __name__ == "__main__" :
try:
data_dir_ = sys.argv[1]
catA_json(data_dir=data_dir_)
catB_json(data_dir=data_dir_)
catC_json(data_dir=data_dir_)
except:
catA_json()
catB_json()
catC_json()
BtoC_json()
AtoB_json()