diff --git a/edosl0util/cli/merge.py b/edosl0util/cli/merge.py index 44ddf1d4efc4398ec106e706f1b8c982d578a9b1..f67b8dea5eef091c40dd12ef3af77af936390264 100644 --- a/edosl0util/cli/merge.py +++ b/edosl0util/cli/merge.py @@ -3,6 +3,8 @@ from datetime import datetime from edosl0util.cli import util from edosl0util import merge, stream +VIIRS_APID_ORDER = [826, 821] + range(800, 826) + def main(): parser = util.default_parser() @@ -15,14 +17,22 @@ def main(): help=('Truncate to the interval given as coma separated timestamps of ' 'the format YYYY-MM-DD HH:MM:SS. The begin time is inclusive, the ' 'end time is exclusive.')) + parser.add_argument( + '-a', '--apid-order', choices=['viirs', 'numerical'], default='numerical', + help=('Packets will be sorted by time and the named order provided. ' + '"viirs" will sort packets in APID order as expectet by the VIIRS ' + 'L1 software. "numerical" will simply sort APIDs in numerical ' + 'order')) parser.add_argument('pds', nargs='+') args = parser.parse_args() util.configure_logging(args) + apid_order = {'viirs': VIIRS_APID_ORDER, 'numerical': None}[args.apid_order] streams = [stream.jpss_packet_stream(io.open(f, 'rb')) for f in args.pds] merge.merge( - streams, output=io.open(args.output, 'wb'), trunc_to=args.trunc_to) + streams, output=io.open(args.output, 'wb'), + trunc_to=args.trunc_to, apid_order=apid_order) if __name__ == '__main__': diff --git a/edosl0util/merge.py b/edosl0util/merge.py index ee68ee7d228b9e2180df4d5971ccb33d7693bc15..d2c40e8a94e4b83a54a172c14e7e73b01f6e5ce9 100644 --- a/edosl0util/merge.py +++ b/edosl0util/merge.py @@ -86,7 +86,7 @@ def read_packet_index(stream): def _sort_by_time_apid(index, order=None): if order: - index = sorted(index, key=lambda p: order.index(p.apid)) + index = sorted(index, key=lambda p: order.index(p.apid) if p.apid in order else -1) else: index = sorted(index, key=lambda p: p.apid) return sorted(index, key=lambda p: p.stamp)