Skip to content

Commit

Permalink
add support for multi-channel marker streams in .xdf files
Browse files Browse the repository at this point in the history
  • Loading branch information
bkloeckl committed Dec 21, 2024
1 parent d0b6e54 commit 5253fe2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Remove Python 3.9 support ([#457](https://github.com/cbrnr/mnelab/pull/457) by [Clemens Brunner](https://github.com/cbrnr))

### Fixed
- Fix an issue where some .xdf files were not loaded correctly (wrong dtype or multi-channel marker) ([#464](https://github.com/cbrnr/mnelab/pull/464) by [Benedikt Klöckl](https://github.com/bkloeckl))
- Fix a bug where appending data would not be correctly displayed in the history ([#446](https://github.com/cbrnr/mnelab/pull/446) by [Benedikt Klöckl](https://github.com/bkloeckl))
- Fix resetting the settings to default values ([#456](https://github.com/cbrnr/mnelab/pull/456) by [Clemens Brunner](https://github.com/cbrnr))

Expand Down
1 change: 0 additions & 1 deletion src/mnelab/dialogs/xdf_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def selected_markers(self):
markers = []
for row in self.view.selectionModel().selectedRows():
type_ = self.view.item(row.row(), 2).text()
# fs = self.view.item(row.row(), 5).value()
if _is_marker(type_):
markers.append(self.view.item(row.row(), 0).value())
return markers
Expand Down
25 changes: 15 additions & 10 deletions src/mnelab/io/xdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(
for stream_id in stream_ids:
stream = streams[stream_id]

# check if the dtype is valid
# check if the dtype is valid, try convertion otherwise
dtype = stream["time_series"].dtype
if dtype not in [np.float64, np.complex128]:
try:
Expand Down Expand Up @@ -111,17 +111,22 @@ def __init__(

# convert marker streams to annotations
for marker_id in marker_ids:
if int(stream["info"]["channel_count"][0]) == 1:
marker = streams[marker_id]
onsets = marker["time_stamps"] - first_time
prefix = f"{marker_id}-" if prefix_markers else ""
descriptions = [
f"{prefix}{item}" for sub in marker["time_series"] for item in sub
]
stream = streams[marker_id]
channel_count = int(stream["info"]["channel_count"][0])
onsets = stream["time_stamps"] - first_time
prefix = f"{marker_id}-" if prefix_markers else ""

if channel_count == 1:
# handle single-channel markers
descriptions = [f"{prefix}{item[0]}" for item in stream["time_series"]]
self.annotations.append(onsets, [0] * len(onsets), descriptions)
else:
# handle multi-channel marker streams
continue
# handle multi-channel markers
for sample in stream["time_series"]:
for _, description in enumerate(sample):
self.annotations.append(
onsets, [0] * len(onsets), str(description)
)


def _resample_streams(streams, stream_ids, fs_new):
Expand Down

0 comments on commit 5253fe2

Please sign in to comment.