A label (when stored on disk) is a text file that contains the following info:
- one ācommentā line usually saying what software made the label
- one line stating number of vertices in the label
- one line for each vertex, with the structure:
vertex_number x y z value
Where vertex_number
s correspond to the Source Space in which the label was defined, and x
, y
, z
are in millimeters. Often the value
is zero everywhere, but itās possible for a label to contain estimated activity at each vertex (like youād find in a SourceEstimate
object); if a label did contain non-zero value
s then in principle your plotting software could take that into account (e.g., when deciding what color to make the label).
Labels are loaded into MNE-Python via mne.read_label(filename, ...)
. The resulting Label
object has attributes comment
, vertices
, pos
, and values
with the only change from the on-disk format being that pos
values are converted from millimeters to meters. You can also load several labels at once into a list, using mne.read_labels_from_annot(subject, parc=name_of_parcellation, ...)
which has a regexp
parameter for narrowing down which labels you want to load from the chosen parcellation. Iām not sure if thatās what you meant by āhow to chooseā a label?
To combine labels, you can use the +
operator: label1 + label2
will yield a new label that includes all the vertices from each of the original two. Note that they donāt have to be spatially adjacent (or even in the same hemisphere) to be combined this way. Note: you can also subtract one label from another (which only has an effect if they overlap).
To manipulate labels: you can label.split(...)
into smaller labels (along its principle axis), you can label.morph(...)
to another subject or to a template brain, you can label.compute_area(...)
, get label.center_of_mass(...)
, find out the distance from each vertex in the label to the edge of the label using label.distances_to_outside(...)
, or fill
, restrict
, or smooth
it (so that its vertices match up with the set of vertices in use in a given source space).
Copying from what I said above: You can load several labels at once into a list, using mne.read_labels_from_annot(subject, parc=name_of_parcellation, ...)
which has a regexp
parameter for narrowing down which labels you want to load from the chosen parcellation. Hereās a list of 8 tutorials/examples that use read_labels_from_annot
: mne.read_labels_from_annot ā MNE 1.6.0 documentation. Probably this one is the most relevant starting point: Plot a cortical parcellation ā MNE 1.6.0 documentation
Final comment: perhaps part of the difficulty is that the example you linked to was doing something rather round-about in this block of code:
all_labels = mne.read_labels_from_annot(subject='sample',
subjects_dir=subjects_dir)
labels = []
for select_label in ['parahippocampal-lh', 'postcentral-rh']:
labels.append([lab for lab in all_labels if lab.name in select_label][0])
hiplab, postcenlab = labels
You could have done that in one line, like this:
hiplab, postcenlab = mne.read_labels_from_annot(
subject='sample', subjects_dir=subjects_dir,
regexp="parahippocampal-lh|postcentral-rh")
ā¦although youād have to be a bit careful about the order in which they got returned; here Iām relying on the knowledge that we have one LH and one RH label, and the LH always gets read first.