Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
withmywoessner committed Dec 16, 2024
1 parent f3a7fde commit 4abd83c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
15 changes: 14 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,7 @@ 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", 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 +1223,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 +1233,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 @@ -1512,6 +1516,15 @@ 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(
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 @@ -246,6 +247,7 @@ from .check import (
_check_preload,
_check_pybv_installed,
_check_pymatreader_installed,
_check_wfdb_installed,
_check_qt_version,
_check_range,
_check_rank,
Expand Down
4 changes: 4 additions & 0 deletions mne/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ def _check_edfio_installed(strict=True):
"""Aux function."""
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."""
Expand Down

0 comments on commit 4abd83c

Please sign in to comment.