"""Check TM packet for a given SID Syntax: python check_SID.py yyyy-mm-dd SID - Extract and display TM packets for this SID - Display SID_counter and delta SID_counter - Compute and display delta time Display maximum delta SIC_counter and timetags """ from solar import * from CCSDS import CCSDS_reader, TM import struct from functools import partial def make_sid_filter (sid): """ Create a filter for a given SID Tm packets """ def fun (packet): return TM (packet) and packet.sid == sid return partial (filter, fun) def make_daily_filter (day): t1 = datetime.datetime.combine (day, datetime.time (0,0,0)) t2 = t1 + datetime.timedelta (days = 1) def fun (packet): return TM (packet) and t1 <= packet.dt < t2 return partial (filter, fun) def check_SID (day, sid): """ Check SID sequence for a given date """ filter_SID = make_sid_filter (sid) daily = make_daily_filter (day) filename = get_L0_filename (day, "swa-pas-tm", "bin") if not filename: filename = get_L0_filename (day, "swa-pas-tm", "hex") max_delta = 0 max_dt = datetime.timedelta (seconds = 0) last_count = None last_dt = None output_file = "check_SID_%02d_%s.log" % (sid, ymd (day)) data_file = "SID_%02d_%s.txt" % (sid, ymd(day)) with open (output_file, "w") as log, open (data_file, "w") as data: for packet in daily (filter_SID (CCSDS_reader (filename))): if last_count is None: last_count = packet.sid_count last_dt = packet.dt delta = packet.sid_count - last_count dt = packet.dt - last_dt if delta > max_delta: max_delta = delta if dt > max_dt: max_dt = dt print (packet, "-- SID_count = %5d Delta = %d %8.3f" % (packet.sid_count, delta, dt.total_seconds()), file = log) print ("%s, %10.3f" % (isotime (packet.dt), dt.total_seconds()), file = data) last_count = packet.sid_count last_dt = packet.dt print ("Maximum delta SID_count =", max_delta, file = log) print ("Maximum delta time = %.3f" % max_dt.total_seconds(), file = log) print ("Generation", output_file) if __name__ == "__main__": from sys import argv, exit try: day = str_to_date (argv[1]) except: print (__doc__) exit (100) SIDS = [11, 14, 15, 255] for sid in SIDS: check_SID (day, sid)