-
Notifications
You must be signed in to change notification settings - Fork 0
/
atlas_SSC_Clock_Adjusted.py
executable file
·55 lines (45 loc) · 1.67 KB
/
atlas_SSC_Clock_Adjusted.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
#!/usr/bin/env python
# Author: Daryn White, [email protected]
"""
Take a block of clock adjust times from the module log file
and convert them to a .lst file for bash processing
THIS SCRIPT ASSUMES THAT ONLY ONE MODULE HAS CLOCK ADJUSTMENTS
"""
import argparse
import re
from datetime import datetime as dt
# Argparsing
parser = argparse.ArgumentParser(
prog="atlas_SSC_Clock_Adjusted",
description="""
Take a block of clock adjust times from the module log file
and convert them to a .lst file for bash processing.
THIS SCRIPT ASSUMES THAT ONLY ONE MODULE HAS CLOCK ADJUSTMENTS
""",
)
parser.add_argument("logfile", metavar="file")
parser.add_argument("--outfile", default="SSC_ClockAdjusted")
args = parser.parse_args()
# Regex building
adjustment_patt = re.compile(r"(?<=Clock adjusted by )[\-\d]{,4}(?= samples)")
datetimes_patt = re.compile(r"(?<= buffer at )\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(?=!)")
# File opening
with open(args.logfile, mode="r", encoding="utf8") as log_file:
# Pattern matching
adjustments_list = re.findall(adjustment_patt, log_file.read())
log_file.seek(0)
datetimes_list = re.findall(datetimes_patt, log_file.read())
# Convert text dates to Julian & adjust times
dt_out_list = []
for d in datetimes_list:
dt_out_list.append(dt.strptime(d, "%Y/%m/%d %H:%M:%S").strftime("%Y%j%H1000"))
# Invert the offsets
adj_out_list = []
for a in adjustments_list:
adj_out_list.append(str(-int(a)))
# Mash the lists together
out_list = [a[0] + " " + a[1] for a in zip(dt_out_list, adj_out_list)]
# Output a .lst file
with open(args.outfile + ".lst", mode="w", encoding="utf8") as out_file:
for i in out_list:
out_file.write(i + " \n")