Skip to content

Commit d596b6d

Browse files
Backport PR #13070 on branch maint/1.9 (BUGFIX: return events if provided when current = desired sfreq) (#13081)
Co-authored-by: Roy Eric <139973278+Randomidous@users.noreply.github.com>
1 parent 4dc9fe4 commit d596b6d

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

doc/changes/devel/13070.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Return events when requested even when current matches the desired sfreq in :meth:`mne.io.Raw.resample` by :newcontrib:`Roy Eric Wieske`.

doc/changes/names.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
.. _Roman Goj: https://romanmne.blogspot.co.uk
258258
.. _Ross Maddox: https://www.urmc.rochester.edu/labs/maddox-lab.aspx
259259
.. _Rotem Falach: https://github.com/Falach
260+
.. _Roy Eric Wieske: https://github.com/Randomidous
260261
.. _Sammi Chekroud: https://github.com/schekroud
261262
.. _Samu Taulu: https://phys.washington.edu/people/samu-taulu
262263
.. _Samuel Deslauriers-Gauthier: https://github.com/sdeslauriers

mne/io/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,10 @@ def resample(
13871387
sfreq = float(sfreq)
13881388
o_sfreq = float(self.info["sfreq"])
13891389
if _check_resamp_noop(sfreq, o_sfreq):
1390-
return self
1390+
if events is not None:
1391+
return self, events.copy()
1392+
else:
1393+
return self
13911394

13921395
# When no event object is supplied, some basic detection of dropped
13931396
# events is performed to generate a warning. Finding events can fail

mne/io/fiff/tests/test_raw_fiff.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
concatenate_events,
2424
create_info,
2525
equalize_channels,
26+
events_from_annotations,
2627
find_events,
2728
make_fixed_length_epochs,
2829
pick_channels,
@@ -1326,6 +1327,15 @@ def test_crop():
13261327
assert raw.n_times - 1 == raw3.n_times
13271328

13281329

1330+
@testing.requires_testing_data
1331+
def test_resample_with_events():
1332+
"""Test resampling raws with events."""
1333+
raw = read_raw_fif(fif_fname)
1334+
raw.resample(250) # pretend raw is recorded at 250 Hz
1335+
events, _ = events_from_annotations(raw)
1336+
raw, events = raw.resample(250, events=events)
1337+
1338+
13291339
@testing.requires_testing_data
13301340
def test_resample_equiv():
13311341
"""Test resample (with I/O and multiple files)."""

0 commit comments

Comments
 (0)