From 5253fe2e068e8225c14960ebf1cb1f218270704b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Kl=C3=B6ckl?= Date: Sat, 21 Dec 2024 16:50:47 +0100 Subject: [PATCH] add support for multi-channel marker streams in .xdf files --- CHANGELOG.md | 1 + src/mnelab/dialogs/xdf_streams.py | 1 - src/mnelab/io/xdf.py | 25 +++++++++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bb556cd..0789cf8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/mnelab/dialogs/xdf_streams.py b/src/mnelab/dialogs/xdf_streams.py index fd6eb3c9..aacb81c6 100644 --- a/src/mnelab/dialogs/xdf_streams.py +++ b/src/mnelab/dialogs/xdf_streams.py @@ -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 diff --git a/src/mnelab/io/xdf.py b/src/mnelab/io/xdf.py index 01466e27..12594461 100644 --- a/src/mnelab/io/xdf.py +++ b/src/mnelab/io/xdf.py @@ -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: @@ -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):