diff --git a/edosl0util/rdrgen.py b/edosl0util/rdrgen.py index ee2e60147587197b4bdd7a6ea102d7f251f5ac2a..8492ff1513b79fd988fdbbed693242f603385f63 100644 --- a/edosl0util/rdrgen.py +++ b/edosl0util/rdrgen.py @@ -1,5 +1,4 @@ import ctypes -import itertools import os import tempfile from collections import OrderedDict @@ -32,11 +31,11 @@ def packets_to_rdrs(sat, pkt_files): # make RDRs one granule at a time get_jpss_packet_time = GetJpssPacketTime() - for rdr_pkt_file in rdr_pkt_files.process_files(): + for (rdr_type, gran), rdr_pkt_file in rdr_pkt_files.process_files(): pkts = list(jpss_packet_stream(rdr_pkt_file)) pkt_times = {p: get_jpss_packet_time(p) for p in pkts} pkts.sort(key=(lambda p: (pkt_times[p], p.apid))) - blob = build_rdr_blob(sat, pkts) + blob = build_rdr_blob(sat, pkts, rdr_type, gran) write_rdr(sat, blob) @@ -70,9 +69,9 @@ class BinnedTemporaryFileManager(object): self._process_files_called = True for file_obj in self._file_objs.values(): file_obj.close() - for _, file_name in sorted(self._file_paths.items()): + for bin_key, file_name in sorted(self._file_paths.items()): file_obj = open(file_name) - yield file_obj + yield bin_key, file_obj file_obj.close() os.remove(file_name) os.rmdir(self.dir) @@ -170,12 +169,8 @@ def set_h5_attrs(h5_obj, attrs): h5_obj.attrs[name] = value -def build_rdr_blob(sat, pkt_stream): - pkt_stream = iter(pkt_stream) +def build_rdr_blob(sat, pkt_stream, rdr_type, granule_iet): get_jpss_packet_time = GetJpssPacketTime() - first_pkt = next(pkt_stream) # FIXME: what if there are no packets? - rdr_type = get_rdr_type(first_pkt.apid) - granule_iet = calc_rdr_granule(sat, rdr_type, get_jpss_packet_time(first_pkt)) granule_iet_end = granule_iet + rdr_type.gran_len total_pkt_size = 0 @@ -190,7 +185,7 @@ def build_rdr_blob(sat, pkt_stream): 'pkt_info': [{} for _ in range(apid.max_expected)]} total_trackers += apid.max_expected - for pkt in itertools.chain([first_pkt], pkt_stream): + for pkt in pkt_stream: if pkt.apid not in apid_info: raise ValueError( 'APID {} not expected for {}'.format(pkt.apid, rdr_type.short_name))