From 8aecfac44622b475150907401dc01c098efcde11 Mon Sep 17 00:00:00 2001 From: Rasmus Aagaard Date: Fri, 3 Nov 2023 14:12:18 +0100 Subject: [PATCH 1/2] Changed casting rule in np.clip to allow reading of raw GDF files + a type in error messag from the `read_raw_gdf` functions extension checking --- mne/io/edf/edf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index e507a651676..c5a80af97dd 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -1443,7 +1443,7 @@ def _read_gdf_header(fname, exclude, include=None): else: chn = np.zeros(n_events, dtype=np.uint32) dur = np.ones(n_events, dtype=np.uint32) - np.clip(dur, 1, np.inf, out=dur) + np.clip(dur, 1, np.inf, out=dur, casting="unsafe") events = [n_events, pos, typ, chn, dur] edf_info["event_sfreq"] = event_sr @@ -1878,7 +1878,7 @@ def read_raw_gdf( input_fname = os.path.abspath(input_fname) ext = os.path.splitext(input_fname)[1][1:].lower() if ext != "gdf": - raise NotImplementedError(f"Only BDF files are supported, got {ext}.") + raise NotImplementedError(f"Only GDF files are supported, got {ext}.") return RawGDF( input_fname=input_fname, eog=eog, From 425e31c6b3c4438cb9750133c3c129ad76cd857e Mon Sep 17 00:00:00 2001 From: roraa Date: Fri, 3 Nov 2023 15:08:50 +0100 Subject: [PATCH 2/2] changed improper use of `np.clip` to use `np.maximum` to read raw gdf files --- doc/changes/devel.rst | 1 + doc/changes/names.inc | 2 ++ mne/io/edf/edf.py | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index 57a9b1fcb41..1a0892132a4 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -49,6 +49,7 @@ Enhancements Bugs ~~~~ +- Fix bug where :func:`mne.io.read_raw_gdf` would fail due to improper usage of ``np.clip`` (:gh:`12168` by :newcontrib:`Rasmus Aagaard`) - Fix bugs with :func:`mne.preprocessing.realign_raw` where the start of ``other`` was incorrectly cropped; and onsets and durations in ``other.annotations`` were left unsynced with the resampled data (:gh:`11950` by :newcontrib:`Qian Chu`) - Fix bug where ``encoding`` argument was ignored when reading annotations from an EDF file (:gh:`11958` by :newcontrib:`Andrew Gilbert`) - Mark tests ``test_adjacency_matches_ft`` and ``test_fetch_uncompressed_file`` as network tests (:gh:`12041` by :newcontrib:`Maksym Balatsko`) diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 82910422954..925e38bfd22 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -442,6 +442,8 @@ .. _ramonapariciog: https://github.com/ramonapariciog +.. _Rasmus Aagaard: https://github.com/rasgaard + .. _Rasmus Zetter: https://people.aalto.fi/rasmus.zetter .. _Reza Nasri: https://github.com/rznas diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index c5a80af97dd..d27aabae8a5 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -1443,7 +1443,7 @@ def _read_gdf_header(fname, exclude, include=None): else: chn = np.zeros(n_events, dtype=np.uint32) dur = np.ones(n_events, dtype=np.uint32) - np.clip(dur, 1, np.inf, out=dur, casting="unsafe") + np.maximum(dur, 1, out=dur) events = [n_events, pos, typ, chn, dur] edf_info["event_sfreq"] = event_sr