-
Notifications
You must be signed in to change notification settings - Fork 2
/
read_write.py
58 lines (52 loc) · 1.25 KB
/
read_write.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
import csv
from os import makedirs
import numpy as np
output_columns = [
"time",
"eci_x",
"eci_y",
"eci_z",
"eci_vx",
"eci_vy",
"eci_vz",
"kep_sma",
"kep_ecc",
"kep_inc",
"kep_aop",
"kep_raan",
"kep_ta",
"ecef_x",
"ecef_y",
"ecef_z",
"ecef_vx",
"ecef_vy",
"ecef_vz",
]
def write_results(spacecraft_name, orbit_name, dates_name, array):
"""
Export propagation results to a CSV file.
"""
makedirs("results/", exist_ok=True)
for ii in enumerate(output_columns):
np.savetxt(
f"results/{spacecraft_name}_{orbit_name}_{dates_name}_{ii[1]}.csv",
array,
delimiter=",",
)
# Function to open csv file and convert data to float array
def open_csv(path, target_file, is_string=False):
tmp = []
with open(path + "\\" + target_file, "r") as file:
reader = csv.reader(file)
for row in reader:
if is_string:
tmp.append(",".join(row))
else:
if len(row) == 1:
tmp.append(float(row[0]))
else:
tmp.append([float(ii) for ii in row])
if is_string:
return tmp
else:
return np.array(tmp)