Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/expose segments #121

Merged
merged 2 commits into from
Nov 25, 2024
Merged

Conversation

jamieforth
Copy link
Contributor

This addresses a couple of small issues with segment metadata.

When dejitter_timestamps=False reported segments now have the correct sample stop.

When dejitter_timestamps=True

  • non-empty streams no longer contain duplicate segment tuples
  • empty stream now return segments as an empty array, rather than [0, -1]

This ensures the length of empty streams is zero, and not equal to
the number of channels.
* Ensure segment array is initialised only once

* Empty streams return empty segment arrays
@cbrnr
Copy link
Contributor

cbrnr commented Nov 22, 2024

@agricolab do you have time to look?

@@ -364,10 +364,6 @@ def load_xdf(
)

# perform jitter removal if requested
for tmp in temp.values():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏼

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏼
catches empty streams and returns [] instead of [0,-1]

@@ -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 = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏼 catches empty streams and returns [] instead of [0,-1] (when _jitter_removal was called, i.e. dejitter_timestamps=True

@@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏼 good catch. we probably need a test for empty streams eventually to catch such issues

@agricolab
Copy link
Member

agricolab commented Nov 25, 2024

Did a manual test and it passes now unduplicated segments

import pyxdf; 
s, h = pyxdf.load_xdf("minimal.xdf", jitter_break_threshold_seconds=0.001, jitter_break_threshold_samples=1);
assert s[0]["info"]["segments"] == [(0, 0), (1, 3), (4, 8)]

We might need a test with an empty stream though, eventually.

@agricolab agricolab merged commit 3fd2f82 into xdf-modules:main Nov 25, 2024
5 checks passed
@agricolab
Copy link
Member

Thanks @jamieforth !

agricolab added a commit that referenced this pull request Nov 25, 2024
@cbrnr
Copy link
Contributor

cbrnr commented Nov 25, 2024

Thanks @jamieforth and @agricolab! Does the test you mentioned pass with this change but fail without it? If so, could you add it to pyxdf/test/test_data.py?

@agricolab
Copy link
Member

Yes, could be a good regression test. I'd also like if we'd had a minimal.xdf (or empty.xdf) with an empty stream.

@cbrnr cbrnr mentioned this pull request Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants