Skip to content

ENH: Convienance methods for labels #5552

Closed

Description

@bloyl

It would be good if stc.extract_label_time_course worked on stcs that are already confined to labels

Similarly it would be useful to have a method for putting derived measures back in to stc form for visualization.

Below is a use-case although more meaning full uses would come from apply_inverse_raw and apply_inverse_epochs.

I don't know my way around labels and sourcespaces, but if someone would like to give me a quick break down on how these could be resolved I'd be happy to take a shot at it.

import mne
from mne.datasets import sample
from mne.minimum_norm import read_inverse_operator, apply_inverse

data_path = sample.data_path()
label = 'Aud-lh'
label_fname = data_path + '/MEG/sample/labels/%s.label' % label
fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
fname_evoked = data_path + '/MEG/sample/sample_audvis-ave.fif'
subjects_dir = data_path + '/subjects'

snr = 3.0
lambda2 = 1.0 / snr ** 2
method = "dSPM"  # use dSPM method (could also be MNE or sLORETA)

# Load data
evoked = mne.read_evokeds(fname_evoked, condition=0, baseline=(None, 0))
inverse_operator = read_inverse_operator(fname_inv)
src = inverse_operator['src']

label = mne.read_label(label_fname)

# Compute inverse solution
pick_ori = "normal"  # Get signed values to see the effect of sign filp
stc = apply_inverse(evoked, inverse_operator, lambda2, method,
                      pick_ori=pick_ori, label=label)

stc_full = apply_inverse(evoked, inverse_operator, lambda2, method,
                         pick_ori=pick_ori)

stc_in_label = stc_full.in_label(label)

# these fails!
mean = stc.extract_label_time_course(label, src, mode='mean')
mean_2 = stc_in_label.extract_label_time_course(label, src, mode='mean')

# it would then be good to be able to put it (or some derived measure) back
stc_label = mne.label_data_to_stc(label, mean, src)

Activity

  1. agramfort commented on Sep 25, 2018

    @agramfort
    SponsorMember

    if label.hemi == 'lh' basically you need to find the intersection between label.vertices and src[0]['vertno'] then the matching vertices give you the vertices[0] to be passed to the SourceEstimate constructor.

    you do the same for right hemi 'rh' and replace 0 by 1.

    makes sense?

  2. bloyl commented on Sep 26, 2018

    @bloyl
    ContributorAuthor

    Are there any labels based on volume source spaces that I need to worry about?

  3. agramfort commented on Sep 26, 2018

    @agramfort
    SponsorMember
  4. larsoner commented on Sep 19, 2019

    @larsoner
    Member

    It would be good if stc.extract_label_time_course worked on stcs that are already confined to labels

    Agreed these should work and give the same result (I'll look into it):

    stc = apply_inverse(evoked, inverse_operator, lambda2, method,
                          pick_ori=pick_ori, label=label)
    stc_full = apply_inverse(evoked, inverse_operator, lambda2, method,
                             pick_ori=pick_ori)
    stc_in_label = stc_full.in_label(label)
    mean = stc.extract_label_time_course(label, src, mode='mean')
    mean_2 = stc_in_label.extract_label_time_course(label, src, mode='mean')
    

    Similarly it would be useful to have a method for putting derived measures back in to stc form for visualization.

    We have this now with http://mne.tools/dev/generated/mne.labels_to_stc.html

  5. added this to the 0.19 milestone on Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions