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

Add epochs_metadata_excludes #495

Closed
wants to merge 4 commits into from

Conversation

hoechenberger
Copy link
Member

@hoechenberger hoechenberger commented Dec 31, 2021

This new setting allows for the exclusion of epochs based on metadata.

In theory this is already possible via conditions, but especially with lots of nested event names, this becomes very cumbersome very quickly, because the auto-generated metadata dataframe currently does not create columns for such event groupings. That is, if you have e.g. the following events:

stim/1
stim/2
stim/3
stim/4
stim/5
bad_response

and you want to analyze all stim trials but exclude all epochs that have a bad_response event in the metadata. You cannot simply specify:

conditions = {'stim': 'stim.notna() and bad_response.isna()'}

because there won't be a column 'stim' in the auto-generated metadata. Instead, you'd have to add each event name explicitly, and use backticks to make the forward slashes work:

conditions = {
    'stim':
        '(`stim/1`.notna() or '
        ' `stim/2`.notna() or '
        ' `stim/3`.notna() or '
        ' `stim/4`.notna() or '
        ' `stim/5`.notna()) and'
        'bad_response.isna()'
}

Now imagine doing this with even more conditions … This is not very user friendly.

Also there might be experiments where all participants get to be presented with a stim, but you might have groups that only get to see stim/1 and stim/2, while others only get to see stim/3 and stim/4. You'd have to produce different conditions for each group, as the columns corresponding to the not-presented stimuli would simply be missing, and the query would fail, complaining about missing columns.

With this PR, the above situation can be addressed by simply specifying:

epochs_metadata_excludes = ['bad_response.notna()']
conditions = ['stim']

Before merging …

  • Changelog has been updated (docs/source/changes.md)

@hoechenberger hoechenberger marked this pull request as ready for review December 31, 2021 10:27
config.py Outdated Show resolved Hide resolved
config.py Outdated Show resolved Hide resolved
config.py Outdated Show resolved Hide resolved
@agramfort
Copy link
Member

couldn't you rather do:

event_name.str.contains('stim/') and bad_response.isna()

or something like this?

@hoechenberger
Copy link
Member Author

couldn't you rather do:

event_name.str.contains('stim/') and bad_response.isna()

or something like this?

This might work, will give it a shot

@hoechenberger
Copy link
Member Author

@agramfort Your proposal works, closing this PR! Thanks!

@hoechenberger hoechenberger deleted the metadata-excludes branch January 3, 2022 11:06
@hoechenberger hoechenberger restored the metadata-excludes branch January 3, 2022 13:19
hoechenberger added a commit to hoechenberger/mne-bids-pipeline that referenced this pull request Jan 3, 2022
hoechenberger added a commit to hoechenberger/mne-bids-pipeline that referenced this pull request Jan 3, 2022
hoechenberger added a commit that referenced this pull request Jan 3, 2022
* Allow epochs selection based on a metadata query

This is a rework of #495

* Update docs/source/changes.md

* Style
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

2 participants