From cba827cf74e020072f5a8a6ac14508fcdd531d28 Mon Sep 17 00:00:00 2001 From: Jamie Forth Date: Fri, 22 Nov 2024 10:01:54 +0000 Subject: [PATCH 1/2] Swap dimensions of empty stream arrays to match non-empty streams This ensures the length of empty streams is zero, and not equal to the number of channels. --- pyxdf/pyxdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyxdf/pyxdf.py b/pyxdf/pyxdf.py index 40c0431..e68ca28 100644 --- a/pyxdf/pyxdf.py +++ b/pyxdf/pyxdf.py @@ -348,7 +348,7 @@ def load_xdf( if stream.fmt == "string": stream.time_series = [] else: - stream.time_series = np.zeros((stream.nchns, 0)) + stream.time_series = np.zeros((0, stream.nchns)) # perform (fault-tolerant) clock synchronization if requested if synchronize_clocks: From f86622e5469ddfbc978281efdf88452022c65fde Mon Sep 17 00:00:00 2001 From: Jamie Forth Date: Fri, 22 Nov 2024 10:24:06 +0000 Subject: [PATCH 2/2] Fix duplicate and spurious segments * Ensure segment array is initialised only once * Empty streams return empty segment arrays --- pyxdf/pyxdf.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pyxdf/pyxdf.py b/pyxdf/pyxdf.py index e68ca28..4703415 100644 --- a/pyxdf/pyxdf.py +++ b/pyxdf/pyxdf.py @@ -364,10 +364,6 @@ def load_xdf( ) # perform jitter removal if requested - for tmp in temp.values(): - # initialize segment list in case jitter_removal was not selected - tmp.segments = [(0, len(stream.time_series) - 1)] # inclusive - if dejitter_timestamps: logger.info(" performing jitter removal...") temp = _jitter_removal( @@ -382,6 +378,10 @@ def load_xdf( stream.effective_srate = len(stream.time_stamps) / duration else: stream.effective_srate = 0.0 + # initialize segment list in case jitter_removal was not selected + stream.segments = [] + if len(stream.time_stamps) > 0: + stream.segments.append((0, len(stream.time_series) - 1)) # inclusive for k in streams.keys(): stream = streams[k] @@ -629,6 +629,7 @@ def _jitter_removal(streams, threshold_seconds=1, threshold_samples=500): for stream_id, stream in streams.items(): stream.effective_srate = 0 # will be recalculated if possible nsamples = len(stream.time_stamps) + stream.segments = [] if nsamples > 0 and stream.srate > 0: # Identify breaks in the time_stamps diffs = np.diff(stream.time_stamps) @@ -663,8 +664,6 @@ def _jitter_removal(streams, threshold_seconds=1, threshold_samples=500): stream.time_stamps[seg_stops] + stream.tdiff ) - stream.time_stamps[seg_starts] stream.effective_srate = np.sum(counts) / np.sum(durations) - else: - stream.segments = [0, nsamples - 1] srate, effective_srate = stream.srate, stream.effective_srate if srate != 0 and np.abs(srate - effective_srate) / srate > 0.1: