Skip to content

Commit

Permalink
FIX : set event onset to first_samp not 0 with initial_value is True (m…
Browse files Browse the repository at this point in the history
…ne-tools#10289)

* FIX : set event onset to first_samp not 0 with initial_value is True

* update what's new

* pep8
  • Loading branch information
agramfort authored Feb 2, 2022
1 parent 1938027 commit 258b462
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ Bugs

- :func:`mne.read_trans` now correctly expands ``~`` in the provided path to the user's home directory (:gh:`10265`, by `Richard Höchenberger`_)
- :func:`mne.find_events` now uses ``first_samp`` and not ``0`` for initial event when using ``initial_value`` (:gh:`10289`, by `Alex Gramfort`_)
API changes
~~~~~~~~~~~
- ``mne.Info.pick_channels`` has been deprecated. Use ``inst.pick_channels`` to pick channels from :class:`~mne.io.Raw`, :class:`~mne.Epochs`, and :class:`~mne.Evoked`. Use :func:`mne.pick_info` to pick channels from :class:`mne.Info` (:gh:`10039` by `Mathieu Scheltienne`_)
Expand Down
3 changes: 2 additions & 1 deletion mne/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ def _find_events(data, first_samp, verbose=None, output='onset',
initial_value = data[0, 0]
if initial_value != 0:
if initial_event:
events = np.insert(events, 0, [0, 0, initial_value], axis=0)
events = np.insert(
events, 0, [first_samp, 0, initial_value], axis=0)
else:
logger.info('Trigger channel has a non-zero initial value of {} '
'(consider using initial_event=True to detect this '
Expand Down
6 changes: 3 additions & 3 deletions mne/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ def test_find_events():
# test initial_event argument
info = create_info(['MYSTI'], 1000, 'stim')
data = np.zeros((1, 1000))
raw = RawArray(data, info)
raw = RawArray(data, info, first_samp=7)
data[0, :10] = 100
data[0, 30:40] = 200
assert_array_equal(find_events(raw, 'MYSTI'), [[30, 0, 200]])
assert_array_equal(find_events(raw, 'MYSTI'), [[37, 0, 200]])
assert_array_equal(find_events(raw, 'MYSTI', initial_event=True),
[[0, 0, 100], [30, 0, 200]])
[[7, 0, 100], [37, 0, 200]])

# test error message for raw without stim channels
raw = read_raw_fif(raw_fname, preload=True)
Expand Down

0 comments on commit 258b462

Please sign in to comment.