Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX merge_events when replace_events=False #3015

Closed
wants to merge 1 commit into from

Conversation

teonbrooks
Copy link
Member

this was brought on the listserv by Lucy MacGregor.
When we create the merged events, we don't get rid of the redundant copy when replace_events=False.

Below you can replicate the error.

"""
========================================================
Sample script to merge events
========================================================

Reads sample data, finds events from event file, merges events to create new events whilst retaining the originals.

Desired behaviour: create *multiple* new event codes whilst retaining originals.

Current behaviour:  If 1 new event is created, for every sample point there are now 2 events: in
cases where original event is merged this results in 1 original and 1 new event as expected. However, in cases
where the original event code isn't merged there is a repetition of the original event code. If
n new events are created, for every sample point there are now n^2 events (presumably because
replace_events=False). 

8.3.2016
Lucy.MacGregor@mrc-cbu.cam.ac.uk

"""

import mne
from mne import io
from mne.datasets import sample

print(__doc__)

data_path = sample.data_path()

###############################################################################
# Set parameters
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'


#   Setup for reading the raw data
raw = io.Raw(raw_fname)
events = mne.read_events(event_fname)

# merge events
events=mne.event.merge_events(events, [1,2], 12, replace_events=False)
events=mne.event.merge_events(events, [3,4], 34, replace_events=False)
events=mne.event.merge_events(events, [1,2,3,4], 1234, replace_events=False)


event_id = dict(A= 1, B= 2, C=3, D=4, E=5, F=12, G=34, H=1234)

@teonbrooks teonbrooks added the FIX label Mar 15, 2016
@agramfort
Copy link
Member

can you add a test?

now we should recommend using dict hierarchical event ids.

travis is not happy

@teonbrooks
Copy link
Member Author

test to come. wanted to make sure that this is right corrected behavior. travis breaks because the current test for this fails.

now we should recommend using dict hierarchical event ids.

agreed.

@agramfort
Copy link
Member

@teonbrooks closing in favor of #3076

it was indeed pretty buggy...

@agramfort agramfort closed this Mar 26, 2016
@jona-sassenhagen
Copy link
Contributor

We probably need to feature hierarchical event_ids better. Put it more prominently in some of the examples.

@teonbrooks teonbrooks deleted the merge_events_FIX branch February 4, 2022 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants