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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


# perform (fault-tolerant) clock synchronization if requested
if synchronize_clocks:
Expand All @@ -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.

👌🏼

# 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(
Expand All @@ -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]

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]
Expand Down Expand Up @@ -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

if nsamples > 0 and stream.srate > 0:
# Identify breaks in the time_stamps
diffs = np.diff(stream.time_stamps)
Expand Down Expand Up @@ -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:
Expand Down