-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_bad_start_stop_times.py
70 lines (52 loc) · 2.05 KB
/
get_bad_start_stop_times.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
#!/usr/bin/env python
import argparse
import csv
import datetime
import json
from argparse import RawTextHelpFormatter
from ait.core import dmc
def get_utc_time_from_gps(gps_time):
# Convert gps_time in seconds to a timestamp in utc
d = dmc.GPS_Epoch + datetime.timedelta(seconds=gps_time)
offset = dmc.LeapSeconds.get_GPS_offset_for_date(d)
utc_time = d - datetime.timedelta(seconds=offset)
return utc_time
def main():
parser = argparse.ArgumentParser(
description="Description: This script gets the start and stop times of the input BAD stream file.\n"
"Operating Environment: Python 3.x. See setup.py file for specific dependencies.\n"
"Outputs:\n"
" * A JSON formatted file containing start and stop times.\n",
formatter_class=RawTextHelpFormatter
)
parser.add_argument(
"input_path",
help="CSV file from which BAD data will be read",
)
parser.add_argument(
"output_path",
help="Output path where to write start/stop values in JSON format",
)
args = parser.parse_args()
with open(args.input_path, newline="") as csv_file:
reader = csv.reader(csv_file, delimiter=',')
headers = next(reader)
rows = list(reader)
index = None
for i, header in enumerate(headers):
# LADP06MD2378W is the header for the coarse time (in GPS seconds)
if header == "LADP06MD2378W":
index = i
break
if index is None:
raise RuntimeError("Unable to find coarse time column (LADP06MD2378W) in data")
gps_times = [float(row[index]) for row in rows if len(row) > index and float(row[index]) > 0]
start_time = get_utc_time_from_gps(min(gps_times))
stop_time = get_utc_time_from_gps(max(gps_times))
output = {
"start_time": start_time.strftime("%Y-%m-%dT%H:%M:%S"),
"stop_time": stop_time.strftime("%Y-%m-%dT%H:%M:%S")}
with open(args.output_path, "w") as f:
json.dump(output, f)
if __name__ == "__main__":
main()