mne-tools / mne-bids-pipeline

Automatically process entire electrophysiological datasets using MNE-Python.
https://mne.tools/mne-bids-pipeline/
BSD 3-Clause "New" or "Revised" License
138 stars 65 forks source link

Parsing annotations when making resting state epochs #474

Open dengemann opened 2 years ago

dengemann commented 2 years ago

I think it would be useful to have a mechanism for inserting the info from annotations present for a given raw segment into the metadata of the resulting epoch. Say you have long resting state runs with eyes closed/open and you don't want to handle those as events but annotate the entire run instead as eyes closed/open. When epoching, it would be nice consider the current annotation. Do we already have anything in that space? Would anything object against a PR?

cc @hoechenberger @agramfort

drammock commented 2 years ago

see https://github.com/mne-tools/mne-python/pull/9969 and https://github.com/mne-tools/mne-python/pull/10019

dengemann commented 2 years ago

Ah, this looks very good! I will see if I can help merging it.

On Mon, Nov 22, 2021 at 4:33 PM Daniel McCloy @.***> wrote:

see mne-tools/mne-python#9969 https://github.com/mne-tools/mne-python/pull/9969 and mne-tools/mne-python#10019 https://github.com/mne-tools/mne-python/pull/10019

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mne-tools/mne-bids-pipeline/issues/474#issuecomment-975646830, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOR7CS7WW5C6VYXIIJNB4LUNJPFFANCNFSM5IRJKBWA .

hoechenberger commented 2 years ago

@dengemann We already do that automatically

The ERP CORE example configuration does stuff like:

    conditions = {
        'related': '`first_stimulus/target` == "related" and '
                   'first_response == "correct"',
        'unrelated': '`first_stimulus/target` == "unrelated" and '
                     'first_response == "correct"'
    }

These are operations on auto-generated metadata.

It is achieved via the mechanism described here: https://mne.tools/stable/auto_tutorials/epochs/40_autogenerate_metadata.html

And that's how we use it in the Pipeline: https://github.com/mne-tools/mne-bids-pipeline/blob/0ce17c8f5f58a2332191d0a3e1d79c21aa0d7885/config.py#L2484-L2496

No need to wait for Epochs metadata to arrive upstream.

Let me know if you need advice on how to make use of it!

dengemann commented 2 years ago

I think my point did not fully come across @hoechenberger –– in my case there are no events - no conditions! It's resting state data where every 5 minutes the context changes (eyes closed/open). No events. task = 'rest'. I want the subsequent resting state epochs to convert the annotations into some event ID. Getting clearer?

drammock commented 2 years ago

not clearer yet :) do you want the info from the annotation as a column in the epoch metadata dataframe, or do you want those epochs to have "rest" as their name in the event_id dict?

dengemann commented 2 years ago

If an epoch was cut from a segment of raw in which there was annotation "eyes closed", I want that label of the annotation to be present in any epoch cut out from that part of the raw recording. Clearer now?

drammock commented 2 years ago

it's still not clear to me how/where you want that information stored. Do you want it in the epochs.metadata dataframe? Do you instead want it as a value in epochs.event_id? Do you want it as an annotation attached to the epoch (not yet possible, but will be with https://github.com/mne-tools/mne-python/pull/9969)?

dengemann commented 2 years ago

I actually do not care :) I just want to know for a downstream epoch the annotation that was present for the original raw signal seen in that epoch. Metadata could be cool though, that was my initial intuition. I would intuitively propagate the Anntoations.descriptions to the metadata. If you have multiple annotaions in one epoch, you could have multiple columns in the metadata.

drammock commented 2 years ago

ah, gotcha. thanks for clarifying. I think the epochs.metadata approach will be most robust, and Adam is working on that as the next step after the epochs.annotations stuff (it's needed for mne_connectivity)