From c1247b2bc295d7541680d7a88bd13be211bd4c7e Mon Sep 17 00:00:00 2001
From: "E. Joshua Rigler" <erigler@usgs.gov>
Date: Wed, 27 Sep 2023 14:53:39 -0600
Subject: [PATCH] fixes #102

---
 geomagio/edge/MiniSeedFactory.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/geomagio/edge/MiniSeedFactory.py b/geomagio/edge/MiniSeedFactory.py
index f7a8ac83..11cf5aeb 100644
--- a/geomagio/edge/MiniSeedFactory.py
+++ b/geomagio/edge/MiniSeedFactory.py
@@ -372,7 +372,23 @@ class MiniSeedFactory(TimeseriesFactory):
         )
         for trace in data:
             trace.data = trace.data.astype(data[0].data.dtype)
-        data.merge()
+
+        # force potentially overlapping samples in traces found later in
+        # the Stream to override samples in traces found earlier
+        # (this is not possible with single calls to Stream.merge())
+        st_tmp = Stream()
+        for tr in data:
+            # add tr to temporary stream
+            st_tmp += tr
+            # replace time overlaps with gaps
+            st_tmp.merge(0)
+            # add tr to temporary stream again
+            st_tmp += tr
+            # replace gaps with tr's data
+            st_tmp.merge(0)
+        # point `data` to the new stream and continue processing
+        data = st_tmp
+
         if data.count() == 0 and add_empty_channels:
             data += self._get_empty_trace(
                 starttime=starttime,
-- 
GitLab