forked from stefco/geco_data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeco_add_time_column
More file actions
executable file
·35 lines (29 loc) · 1.34 KB
/
geco_add_time_column
File metadata and controls
executable file
·35 lines (29 loc) · 1.34 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
#!/usr/bin/env python
# (c) Stefan Countryman 2018
"""
Add a time column to a timeseries.
"""
import argparse
import sys
# DESC = """Read an input list of newline-delimited values from STDIN and write
# them to STDOUT as a CSV-formatted table where the 1st column is the time in
# GPS seconds (rounded down to the nearest integer), the 2nd column is the extra
# nanoseconds since the last integer second, and the 3rd column is the value of
# the input timeseries at that time.
# """
DESC = """Read an input list of newline-delimited values from STDIN and write
them to STDOUT as a CSV-formatted table where the 1st column is the time and
the 2nd column is the value of the input timeseries at that time.
"""
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=DESC)
parser.add_argument("-s", "--starttime", type=int,
help="The GPS time of the first datapoint.")
parser.add_argument("-b", "--bitrate", type=int,
help="The bitrate in [Hz] of the timeseries.")
args = parser.parse_args()
ns_per_datapoint = 1e9 / args.bitrate
for lineno, line in enumerate(sys.stdin):
seconds = args.starttime + (lineno // args.bitrate)
nanoseconds = int((lineno % args.bitrate) * ns_per_datapoint)
sys.stdout.write('{}.{:09d}, {}'.format(seconds, nanoseconds, line))