trftools.roi.mask_roi

trftools.roi.mask_roi(key, src)

Create a boolean ROI based on anatomical labels

Parameters:
  • key (str) – Label definition (see Notes).

  • src (SourceSpace | Path | str) – Source space to work with, or MRI-directory from which to load fsaverage.

Return type:

[lh, rh] Boolean masks for both hemisphere (True inside the label).

Notes

Labels are defined based on a label name, and optional instructions for splitting the label.

The label name can be one of the pre-defined collections defined in ROIS at the top of this script, e.g. STG. It can also be the name of an aparc label, e.g. middletemporal.

Splitting instructions is based on number of parts, followed by the parts to use (with zero-based index, from posterior to anterior). E.g. STG301: split STG into 3 parts, and use the posterior 2/3rd (parts 0 and 1).

Multiple such definitions can be combined with +, e.g. STG+STS.

Examples

Swarmplot for an ROI, assuming e is an instance of TRFExperiment:

import seaborn
from eelbrain import *
import trftools.roi

data = e.load_trfs(-1, 'gammatone-8', **WHOLEBRAIN_PARAMETERS)
lh_roi, rh_roi = trftools.roi.mask_roi('STG301', data['det'].source)

# Extract mean for left and right hemisphere
dss = []
for hemi, roi in [['lh', lh_roi], ['rh', rh_roi]]:
    ds = data['subject',]
    ds['y'] = data['det'].mean(roi)
    ds[:, 'hemi'] = hemi
    dss.append(ds)
roi_data = combine(dss)

# Swarmplot
df = roi_data.as_dataframe()
fig = seaborn.swarmplot(df, y='y', x='hemi')