-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathp2030_summary.py
More file actions
81 lines (60 loc) · 2.63 KB
/
p2030_summary.py
File metadata and controls
81 lines (60 loc) · 2.63 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# /usr/bin/env python
# Purpose: parse p2030 cima log file and extract observers,
# sources, and observation times into a file
# observation delimiter
DLMT = "BEGIN executive: CIMA executive starting ..."
def summarize(logfile):
'''
create summary of cima log file `logfile`
Parameters
==========
logfile: str
path to cima log file to summarize
Returns
======
(columns, log_records): tuple
columns is a tuple of strings. Each string is the column title for each respective tuple element in the tuples in log_records.
log_records is a list of tuples for each pointing found in the cima log file.
each element will have the following format: (timestamp, ra (deg), dec (deg), observers),
where timestamp is a datetime.datetime object, ra & dec are floats, and observers is a string.
'''
columns = ("timestamp", "ra (deg)", "dec (deg)", "observers")
with open(logfile, 'r') as f:
# get observation blocks from log file
blks = [x.split('\n') for x in f.read().split(DLMT)]
blks = blks[1:] # ignore the first element
log_records = []
for blk in blks:
# (timestamp, ra, dec, observers)
blk_records = []
observers = [x.split('mode for ')[1].strip("'") for x in [l for l in blk if "e: CIMA session" in l]][0]
src_lines = [l for l in blk if "pnt tr" in l and len(l.split()) > 10 and "vw_send" in l]
for src in src_lines:
src = src.split()
timestamp = src[0]+' '+src[1]
sra = src[8]
sdec = src[9]
ra_deg = float(sra[:2]) * 15.0
ra_deg += float(sra[2:4]) * 15.0 / 60.0
ra_deg += float(sra[4:]) * 15.0 / 3600.0
dec_deg = float(sdec[:2])
dec_deg += float(sdec[2:4]) * 15.0 / 60.0
dec_deg += float(sdec[4:]) * 15.0 / 3600.0
blk_records.append((str(x) for x in (timestamp, ra_deg, dec_deg, observers))) # appends a tuple
log_records.extend(blk_records)
return (columns, log_records)
if __name__ == "__main__":
import os
import argparse
p = argparse.ArgumentParser()
p.add_argument('logfile', type=str)
p.add_argument('-o', dest='outdir', type=str, default=os.getcwd(),
help="output directory. default is {}".format(os.getcwd()))
args = p.parse_args()
of = os.path.join(args.outdir, os.path.basename(args.logfile) + '_summary.txt')
buf = '' # write buffer
cols, log_records = summarize(args.logfile)
for r in log_records:
buf += ' '.join(r) + '\n'
with open(of, 'w') as f:
f.write(buf)