Skip to content

Commit

Permalink
Expose information about segments in info and "print_metadata" (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
agricolab authored Oct 21, 2024
1 parent 44190d3 commit 13ab943
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyxdf/examples/print_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ def main(fname: str):

print("Found {} streams:".format(len(streams)))
for ix, stream in enumerate(streams):
msg = "Stream {}: {} - type {} - uid {} - shape {} at {} (effective {}) Hz"
msg = "Stream {}: {} - type {} - uid {} - shape {} in {} segments at {} (effective {}) Hz"
print(
msg.format(
ix + 1,
stream["info"]["name"][0],
stream["info"]["type"][0],
stream["info"]["uid"][0],
(int(stream["info"]["channel_count"][0]), len(stream["time_stamps"])),
len(stream["info"]["segments"]),
stream["info"]["nominal_srate"][0],
stream["info"]["effective_srate"],
)
Expand Down
10 changes: 9 additions & 1 deletion pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ 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(
Expand Down Expand Up @@ -397,6 +401,7 @@ def load_xdf(
)
stream["info"]["stream_id"] = k
stream["info"]["effective_srate"] = tmp.effective_srate
stream["info"]["segments"] = tmp.segments
stream["time_series"] = tmp.time_series
stream["time_stamps"] = tmp.time_stamps
stream["clock_times"] = tmp.clock_times
Expand Down Expand Up @@ -646,7 +651,8 @@ def _jitter_removal(streams, threshold_seconds=1, threshold_samples=500):
# 0th sample is a segment start and last sample is a segment stop
seg_starts = np.hstack(([0], break_inds))
seg_stops = np.hstack((break_inds - 1, nsamples - 1)) # inclusive

for a, b in zip(seg_starts, seg_stops):
stream.segments.append((a, b))
# Process each segment separately
for start_ix, stop_ix in zip(seg_starts, seg_stops):
# Calculate time stamps assuming constant intervals within each
Expand All @@ -666,6 +672,8 @@ 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

0 comments on commit 13ab943

Please sign in to comment.