Source localization

Estimating brain-level currents from sensor data requires a structural MRI (or a scaled template brain), a coregistration between the MRI and the sensor positions, a noise covariance estimate, and an inverse solution. This section covers all of these; source localization applies equally to Evoked analysis and TRF analysis (both are performed in source space by setting the inv state).

MRIs

The {root}/derivatives/freesurfer directory is a FreeSurfer subject directory (see The BIDS file structure). Each subject’s MRI directory either contains the files created by FreeSurfer’s recon-all command, or is created by the MNE-Python coregistration utility as a scaled copy of the template brain. An fsaverage folder is used to store the template brain; if it is missing, the MRI task of the The pipeline GUI offers to download it automatically.

See the wiki for more information on using structural MRIs or the fsaverage template brain.

Pipeline.mri_subjects: Dict[str, Dict[str, str]]

Map MEG/EEG subjects to FreeSurfer MRI subjects. Keys in mri_subjects are names for different mappings and correspond to values of the mri state parameter; the inner dictionaries map subject values to MRI subject names. MRI subjects are directories under {root}/derivatives/freesurfer; like the subject directories, they are named sub-{name}, and the sub- prefix is added automatically (unless the name is a template listed in Pipeline.mri_templates, or already starts with sub-). By default, an identity mapping is used, i.e., each subject uses their own MRI directory sub-{subject}. Custom mappings can be defined, for example to let several subjects share a template brain or to point to individually scaled MRI subjects. A plain dictionary needs an entry for every subject whose MRI is used; a mapping that follows from the subject name is more easily defined as a function with keydefaultdict, e.g.:

from eelbrain import keydefaultdict

mri_subjects = {
    'fsaverage': keydefaultdict(lambda subject: 'fsaverage'),  # all subjects use the template brain
    'scaled': keydefaultdict(lambda subject: f'{subject}-scaled'),  # sub-{subject}-scaled
    'own': {  # explicit, needs an entry for every subject whose MRI is used
        'S001': 'S001',
        'S002': 'S001',  # S002 uses the MRI of S001
    },
}

The identity mapping '' (keydefaultdict(lambda subject: subject)) is always available and is the initial mri value, unless mri_subjects overrides the '' entry. The resulting MRI subject is available as the mrisubject state. A subject that the selected mapping omits has an empty mrisubject: it can still be iterated over and analyzed in sensor space, but anything that needs its MRI raises an error.

Pipeline.mri_templates: Sequence[str]

FreeSurfer subjects that are not derived from a MEG/EEG subject, such as template brains. Their directories under {root}/derivatives/freesurfer are named without the sub- prefix. The default is ('fsaverage', 'fsaverage_sym'); fsaverage and fsaverage_sym, the FreeSurfer average brains, are always treated as templates, even when mri_templates does not list them.

Missing MRI subjects are created automatically when they are first needed, as long as they can be derived without user input:

  • fsaverage is downloaded with mne.datasets.fetch_fsaverage().

  • A subject directory that contains only an MRI scaling parameters.cfg file (as written by mne.scale_mri() and the MNE coregistration GUI) is populated by scaling the template brain accordingly. This allows distributing a BIDS dataset with the scaling parameters alone instead of the scaled surfaces.

The MRI task of the The pipeline GUI offers the same operations by double-clicking a row.

Coregistration

A trans-file records the coregistration of the MRI with the head shape in the raw data file. It is created with the MNE-Python coregistration utility, most conveniently through the Coregistration task of the The pipeline GUI: double-clicking a subject row opens the MNE coregistration GUI pre-loaded with the subject’s raw file and, if one already exists, the current transformation. For subjects without a FreeSurfer reconstruction the GUI opens against the template brain, so that MNE’s “Scale MRI” feature can be used to create a scaled copy.

Noise covariance

Pipeline.noise_covariance

Source estimation with MNE methods requires an estimate of the sensor noise covariance matrix. How it is estimated is controlled through the cov state. Two entries are always available: 'emptyroom' (the default), which estimates the covariance from an empty room recording (see Empty room noise covariance), and 'ad_hoc', a diagonal covariance with nominal sensor noise levels from mne.make_ad_hoc_cov(). Both bound the condition number of the covariance through the default max_condition (see Covariance).

Additional noise covariance estimates can be configured in Pipeline.noise_covariance as a dictionary of {name: covariance_definition} entries using:

RawCovariance([method, max_condition])

Noise covariance estimated from a continuous (empty room) recording.

EpochCovariance(epoch[, method, ...])

Covariance estimated from epochs.

Defining a noise covariance with a name from an existing definition ('emptyroom', 'ad_hoc') will override that definition.

Empty room noise covariance

To use empty room data for estimating the noise covariance, set up the empty room data according to the instruction in BIDS specification. The empty room covariance is then available through e.set(cov='emptyroom'). The built-in entry can be overridden to change how it is estimated, for example to regularize the covariance more strongly:

noise_covariance = {
    'emptyroom': RawCovariance(max_condition=1e4),
}

Noise covariance from epochs

Alternatively, the covariance can be estimated from a data epoch, most commonly the pre-stimulus baseline. The epoch is defined like any other epoch in Pipeline.epochs (see Preprocessing and epochs), and an EpochCovariance entry in Pipeline.noise_covariance refers to it by name:

epochs = {
    'picture': PrimaryEpoch('words', "stimulus == 'picture'"),
    'baseline': SecondaryEpoch('picture', tmax=0),
}

noise_covariance = {
    'baseline': EpochCovariance('baseline'),
}

This covariance is then selected with e.set(cov='baseline'). The epochs are subject to the same preprocessing as the data epochs, including the epoch_rejection state.

Inverse solution

The inverse solution is selected through the inv state, most conveniently with Pipeline.set_inv(), and the source space through src. Once these are set, source-space data is loaded by the same methods that load sensor-space data — for example, Pipeline.load_evoked() and Pipeline.load_epochs() return source estimates when inv is set (src_baseline and morph parameters), and TRFs are fit in source space (see TRF analysis).

Parcellations (Pipeline.parcs)

Pipeline.parcs

A parcellation determines how the brain surface is divided into regions. A number of standard parcellations are automatically defined (see parc (parcellations) below). Additional parcellations can be defined in the Pipeline.parcs dictionary with {name: parc_definition} entries.

SubParc(base, labels[, views])

A subset of labels in another parcellation

CombinationParc(base, labels[, views])

Recombine labels from an existing parcellation

SeededParc(seeds[, mask, surface, views])

Parcellation that is grown from seed coordinates

IndividualSeededParc(seeds[, mask, surface, ...])

Seed parcellation with individual seeds for each subject

FreeSurferParc([views])

Parcellation that is created outside Eelbrain for each subject

FSAverageParc([views])

Fsaverage parcellation that is morphed to individual subjects

Visualization defaults

Pipeline.brain_plot_defaults

The Pipeline.brain_plot_defaults dictionary can contain options that change defaults for brain plots. The following options are available:

surf‘inflated’ | ‘pial’ | ‘smoothwm’ | ‘sphere’ | ‘white’

Freesurfer surface to use as brain geometry.

viewsstr | iterator of str

View or views to show in the figure. Can also be set for each parcellation, see Pipeline.parcs.

foregroundmayavi color

Figure foreground color (i.e., the text color).

backgroundmayavi color

Figure background color.

smoothing_stepsNone | int

Number of smoothing steps to display data.

State parameters

mri

Selects a mapping from MEG/EEG subjects to MRI subjects defined in Pipeline.mri_subjects. The default ('') is the identity mapping, in which each subject uses their own MRI directory. Group-level source space results are cached separately for each mapping; subject-level results are cached per MRI subject, so mappings that select the same MRI subject share them. In the The pipeline GUI, the MRI and Coregistration tasks offer the mapping in the MRI dropdown (when the pipeline defines more than one).

mrisubject

The FreeSurfer MRI subject (directory name under {root}/derivatives/freesurfer) for the current subject under the current mri mapping. It is set automatically whenever subject or mri change, but can be overridden for a single call to load data for a specific MRI subject, e.g. e.load_src(mrisubject='fsaverage'). It is empty for a subject that the mapping omits.

cov

Selects a noise covariance estimate defined in Pipeline.noise_covariance. The following entries are always available (unless overridden):

‘emptyroom’ (default)

Empty room covariance (RawCovariance()); for required setup, see Empty room noise covariance.

‘ad_hoc’

Diagonal covariance based on mne.make_ad_hoc_cov() (RawCovariance('ad_hoc')).

src

The source space to use.

  • ico-x: Surface source space based on icosahedral subdivision of the white matter surface x steps (e.g., ico-4, the default).

  • vol-x: Volume source space based on a volume grid with x mm resolution (x is the distance between sources, e.g. vol-10 for a 10 mm grid).

inv

What inverse solution to use for source localization. inv can be set with Pipeline.set_inv(), which has a detailed description of the options. inv can also be set directly using the appropriate string, e.g., e.set(inv='fixed-6-MNE'). To determine the string corresponding to a given set of parameters, use Pipeline.inv_str(). For example:

>>> Pipeline.inv_str('fixed', snr=6, method='MNE')
'fixed-6-MNE'

Consequently, the following two are equivalent for setting inv:

>>> Pipeline.set_inv('fixed', snr=6, method='MNE')
>>> Pipeline.set(inv='fixed-6-MNE')

parc (parcellations)

The parcellation determines how the brain surface is divided into regions. Parcellations included with FreeSurfer can directly be used:

  • FreeSurfer Parcellations: aparc.a2005s, aparc.a2009s, aparc, aparc.DKTatlas, PALS_B12_Brodmann, PALS_B12_Lobes, PALS_B12_OrbitoFrontal, PALS_B12_Visuotopic.

Additional parcellation can be defined in the Pipeline.parcs attribute. Parcellations are used in different contexts:

  • When loading source space data, the current parc state determines the parcellation of the source space (change the state parameter with e.set(parc='aparc')).

  • When loading tests, the parc state masks the source space: all named labels are treated as one connected surface, and any sources labeled as "unknown" are discarded. For example, loading a test with parc='PALS_B12_Lobes' will perform a whole-brain test on the cortex, while discarding subcortical sources. Setting disconnect_labels=True instead treats each label as a separate ROI, so that for spatial cluster-based tests no clusters can cross the boundary between two labels.

Parcellations are set with their name, with the exception of SeededParc: for those, the name is followed by the radius in mm, for example, to use seeds defined in a parcellation named 'myparc' with a radius of 25 mm around the seed, use e.set(parc='myparc-25').

A few additional parcellations that provide homogeneous masks are included for backwards compatibility. For future work, it is recommended to build such masks from aparc or another parcellation with more fine-grained subdivision into labels.

  • cortex: All sources in cortex, based on the FreeSurfer “cortex” label.

  • lobes: Modified version of PALS_B12_Lobes in which the limbic lobe is merged into the other 4 lobes.

  • lobes-op: One large region encompassing occipital and parietal lobe in each hemisphere.

  • lobes-ot: One large region encompassing occipital and temporal lobe in each hemisphere.

adjacency

Possible values: '', 'link-midline'

Adjacency refers to the edges connecting data channels (sensors for sensor space data and sources for source space data). These edges are used to find clusters in cluster-based permutation tests. For source spaces, the default is to use FreeSurfer surfaces in which the two hemispheres are unconnected. By setting adjacency='link-midline', this default adjacency can be modified so that the midline gyri of the two hemispheres get linked at sources that are at most 15 mm apart. This parameter currently does not affect sensor space adjacency.