-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccis_io.py
More file actions
53 lines (46 loc) · 1.65 KB
/
accis_io.py
File metadata and controls
53 lines (46 loc) · 1.65 KB
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
import json
import numpy as np
import build.accis as accis
class numpy_encoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
elif isinstance(obj, np.floating):
return float(obj)
elif isinstance(obj, np.ndarray):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
def make_gen_file(filename) :
gen = accis.generator()
d = gen.get_param()
with open('inputs/' + filename + '.json', 'w') as f :
json.dump(d, f, indent = 4, cls = numpy_encoder)
def accis_get_gen(filename) :
gen = accis.generator()
with open('inputs/' + filename + '.json') as f :
d = json.load(f)
gen.set_param(d)
return gen
def make_sat_file(filename) :
sat = accis.sat()
d = sat.get_param()
with open('inputs/' + filename + '.json', 'w') as f :
json.dump(d, f, indent = 4, cls = numpy_encoder)
def accis_get_sat(filename) :
sat = accis.sat()
with open('inputs/' + filename + '.json') as f :
d = json.load(f)
sat.set_param(d)
return sat
def accis_save_results(sats) :
print('-- Saving Results --')
sat_ids = []
for sat in sats :
param = sat.get_param()
sat_id = param["Satellite ID"]
sat_ids.append(sat_id)
for key, val in sat.get_results().items() :
k = key.replace(" ", "_").replace("(", "").replace(")", "").lower()
filename = "results/sat_" + str(sat_id) + "_" + k + ".csv"
np.savetxt(filename, np.array(val), delimiter=",")
np.savetxt("results/sat_ids.csv", np.array(sat_ids), delimiter=",", fmt="%d")