From 7daeceef4a2b80f4d849ec55a72a6450020c8c0c Mon Sep 17 00:00:00 2001 From: Roy Eric <139973278+Randomidous@users.noreply.github.com> Date: Fri, 24 Jan 2025 17:05:25 +0100 Subject: [PATCH] BUGFIX: return events if provided when current = desired sfreq (#13070) Co-authored-by: Eric Larson Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel McCloy --- doc/changes/devel/13070.bugfix.rst | 1 + doc/changes/names.inc | 1 + mne/io/base.py | 5 ++++- mne/io/fiff/tests/test_raw_fiff.py | 10 ++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 doc/changes/devel/13070.bugfix.rst diff --git a/doc/changes/devel/13070.bugfix.rst b/doc/changes/devel/13070.bugfix.rst new file mode 100644 index 00000000000..3c6a3c25082 --- /dev/null +++ b/doc/changes/devel/13070.bugfix.rst @@ -0,0 +1 @@ +Return events when requested even when current matches the desired sfreq in :meth:`mne.io.Raw.resample` by :newcontrib:`Roy Eric Wieske`. \ No newline at end of file diff --git a/doc/changes/names.inc b/doc/changes/names.inc index eb444c5e594..5a58ac0fa34 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -258,6 +258,7 @@ .. _Roman Goj: https://romanmne.blogspot.co.uk .. _Ross Maddox: https://www.urmc.rochester.edu/labs/maddox-lab.aspx .. _Rotem Falach: https://github.com/Falach +.. _Roy Eric Wieske: https://github.com/Randomidous .. _Sammi Chekroud: https://github.com/schekroud .. _Samu Taulu: https://phys.washington.edu/people/samu-taulu .. _Samuel Deslauriers-Gauthier: https://github.com/sdeslauriers diff --git a/mne/io/base.py b/mne/io/base.py index 280330367f7..b3052b80aff 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -1386,7 +1386,10 @@ def resample( sfreq = float(sfreq) o_sfreq = float(self.info["sfreq"]) if _check_resamp_noop(sfreq, o_sfreq): - return self + if events is not None: + return self, events.copy() + else: + return self # When no event object is supplied, some basic detection of dropped # events is performed to generate a warning. Finding events can fail diff --git a/mne/io/fiff/tests/test_raw_fiff.py b/mne/io/fiff/tests/test_raw_fiff.py index 1ae0cc52901..3ae49189161 100644 --- a/mne/io/fiff/tests/test_raw_fiff.py +++ b/mne/io/fiff/tests/test_raw_fiff.py @@ -23,6 +23,7 @@ concatenate_events, create_info, equalize_channels, + events_from_annotations, find_events, make_fixed_length_epochs, pick_channels, @@ -1318,6 +1319,15 @@ def test_crop(): assert raw.n_times - 1 == raw3.n_times +@testing.requires_testing_data +def test_resample_with_events(): + """Test resampling raws with events.""" + raw = read_raw_fif(fif_fname) + raw.resample(250) # pretend raw is recorded at 250 Hz + events, _ = events_from_annotations(raw) + raw, events = raw.resample(250, events=events) + + @testing.requires_testing_data def test_resample_equiv(): """Test resample (with I/O and multiple files)."""