From ecbf80e933a65a089768affe22078e1da2dc5d91 Mon Sep 17 00:00:00 2001
From: Bruce Flynn <brucef@ssec.wisc.edu>
Date: Thu, 19 Aug 2021 13:13:11 -0500
Subject: [PATCH] merge: don't crash for non-order apids

---
 edosl0util/merge.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/edosl0util/merge.py b/edosl0util/merge.py
index 27afc53..6096b18 100644
--- a/edosl0util/merge.py
+++ b/edosl0util/merge.py
@@ -10,8 +10,7 @@
 """
 import logging
 import os
-from collections import deque, OrderedDict
-from functools import total_ordering
+from collections import deque
 
 from . import eos as _eos
 
@@ -71,17 +70,18 @@ class _Ptr(object):
 def _sort_key(p, order=None, eos=False):
     if eos and p.apid == 64:
         return _eos._modis_sort_key(p)
-    return (p.stamp, order.index(p.apid) if order else p.apid)
+    apid_order = order.index(p.apid) if p.apid in order else 0
+    return (p.stamp, apid_order if order else p.apid)
 
 
 def read_packet_index(stream, order=None, eos=False):
+    order = tuple(order) if order else tuple()
     index = deque()
     try:
         # drop any leading hanging packets
         count = 0
         packet = stream.next()
         while not packet.stamp:
-        #while not (packet.is_first() or packet.is_standalone()):
             packet = stream.next()
             count += 1
         if count:
@@ -89,7 +89,6 @@ def read_packet_index(stream, order=None, eos=False):
 
         while True:
             if not packet.stamp:
-            #if not (packet.is_first() or packet.is_standalone()):
                 # corrupt packet groups can cause apid mismatch
                 # so skip until we get to the next group
                 packet = stream.next()
@@ -107,7 +106,6 @@ def read_packet_index(stream, order=None, eos=False):
             # collect all packets for this timecode/group
             packet = stream.next()
             while not packet.stamp:
-            #while not (packet.is_first() or packet.is_standalone()):
                 # Bail if we're collecting group packets and apids don't match
                 # This means group is corrupt
                 if ptr.apid != packet.apid:
-- 
GitLab