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

Read MIT Annotations #13030

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
20 changes: 19 additions & 1 deletion mne/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
_check_option,
_check_pandas_installed,
_check_time_format,
_check_wfdb_installed,
_convert_times,
_DefaultEventParser,
_dt_to_stamp,
Expand Down Expand Up @@ -1140,7 +1141,13 @@ def _write_annotations_txt(fname, annot):

@fill_doc
def read_annotations(
fname, sfreq="auto", uint16_codec=None, encoding="utf8", ignore_marker_types=False
fname,
sfreq="auto",
withmywoessner marked this conversation as resolved.
Show resolved Hide resolved
uint16_codec=None,
encoding="utf8",
ignore_marker_types=False,
fmt="auto",
suffix=None,
) -> Annotations:
r"""Read annotations from a file.

Expand Down Expand Up @@ -1222,6 +1229,7 @@ def read_annotations(
".bdf": {"encoding": encoding},
".gdf": {"encoding": encoding},
}
print(fname.suffix)
if fname.suffix in readers:
annotations = readers[fname.suffix](fname, **kwargs.get(fname.suffix, {}))
elif fname.name.endswith(("fif", "fif.gz")):
Expand All @@ -1231,6 +1239,8 @@ def read_annotations(
annotations = _read_annotations_fif(fid, tree)
elif fname.name.startswith("events_") and fname.suffix == ".mat":
annotations = _read_brainstorm_annotations(fname)
elif fmt == "wfdb":
annotations = _read_wfdb_annotations(fname, suffix=suffix)
else:
raise OSError(f'Unknown annotation file format "{fname}"')

Expand Down Expand Up @@ -1513,6 +1523,14 @@ def _check_event_description(event_desc, events):
return event_desc


def _read_wfdb_annotations(fname, suffix=None):
"""Read annotations from wfdb format."""
wfdb = _check_wfdb_installed(strict=True)
anno = wfdb.io.rdann(fname.stem, extension=suffix)
print(anno)
print(anno.__dict__)


@verbose
def events_from_annotations(
raw,
Expand Down
2 changes: 2 additions & 0 deletions mne/utils/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ __all__ = [
"_check_preload",
"_check_pybv_installed",
"_check_pymatreader_installed",
"_check_wfdb_installed",
"_check_qt_version",
"_check_range",
"_check_rank",
Expand Down Expand Up @@ -254,6 +255,7 @@ from .check import (
_check_stc_units,
_check_subject,
_check_time_format,
_check_wfdb_installed,
_ensure_events,
_ensure_int,
_import_h5io_funcs,
Expand Down
5 changes: 5 additions & 0 deletions mne/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ def _check_edfio_installed(strict=True):
return _soft_import("edfio", "exporting to EDF", strict=strict)


def _check_wfdb_installed(strict=True):
"""Aux function."""
return _soft_import("wfdb", "MIT WFDB IO", strict=strict)


def _check_pybv_installed(strict=True):
"""Aux function."""
return _soft_import("pybv", "exporting to BrainVision", strict=strict)
Expand Down
Loading