How to set atlas for
" mne.bem.make_watershed_bem(*subject*, *subjects_dir=None*,
*overwrite=False*, *volume='T1'*, *atlas=False, gcaatlas=False*,
*preflood=None*, *show=False*, *verbose=None*) "
How can I define Desikan-Killiany Atlas in the following command:
" mne.bem.make_watershed_bem(s*ubject*, *subjects_dir=None*,
*overwrite=False*, *volume='T1'*, *atlas=False, gcaatlas=False*,
*preflood=None*, *show=False*, *verbose=None*) "
Okay.
The source estimate file I'm getting consists of 8175 vertices
(SourceEstimate | 8175 vertices) , I wanted to reduce the number of
vertices to the ROIs, in my case I wanted to use Desikan atlas.
How can I reduce the number of vertices, specific to certain atlases?
You do cortical parcellation by using some atlas. I think what you meant is
to restrict the dipoles activity to some particular brain regions. For
that, you need to pass the 'label' during source estimation or you can do
something like this after the source estimate:
code:
regexp = 'bankssts' # name the brain region that you are interested in
hemi = 'both' # taking both hemisphere
label = mne.read_labels_from_annot(subject, hemi=hemi, parc='aparc',
subjects_dir=subjects_dir, regexp=regexp)[0] # read the label of the
particular region based on Desikan atlas (i.e., defined by 'aparc')
stc = stc.in_label(label) # restrict the dipoles to that particular label
When I run this command, label = mne.read_labels_from_annot(subject,
hemi=hemi, parc='aparc', subjects_dir=subjects_dir, regexp=regexp)[0], with
[0] at the end I could run the next command stc = stc.in_label(label),
successfully but it reduces the number of vertices to 35, whereas when I do
not use '[0]' at the end of command, I could not run the next command, it
gives the following error:
parc='aparc', subjects_dir=subjects_dir, regexp=None)
Reading labels from parcellation...
read 34 labels from
/home/vivek/Downloads/freesurfer/subjects/sub-CC721377_T1w/label/lh.aparc.annot
read 34 labels from
/home/vivek/Downloads/freesurfer/subjects/sub-CC721377_T1w/label/rh.aparc.annot
stc_label.in_label(label)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/vivek/anaconda3/lib/python3.7/site-packages/mne/source_estimate.py",
line 1197, in in_label
if label.subject is not None and self.subject is not None \
AttributeError: 'list' object has no attribute 'subject'
I'm still not able to reduce the number of vertices to 68.
let me again explain my problem with more detail:
I'm using the following command to generate source estimates...
The output of above command contains 8175 vertices and I want to reduce the
number of vertices to 68 which is according to Desikan atlas.
To reduce the vertices I use the following code:
This line:
*label = mne.read_labels_from_annot('subject', hemi='both', parc='aparc',
subjects_dir=subjects_dir, regexp=None)[0]*
selects the alphabetically first label from the parcellation*.* Is that
really what you want? More clearly: mne.read_labels_from_annot returns a
list of labels **sorted by label name (ascending)**. Perhaps you're
getting the wrong number of vertices because you're selecting the wrong
label?
This line:
*label = mne.read_labels_from_annot('subject', hemi='both', parc='aparc',
subjects_dir=subjects_dir, regexp=None)[0]*
selects the alphabetically first label from the parcellation*.* Is that
really what you want? "I want all the 68 labels not only the first
one...... when I execute this code:
*label = mne.read_labels_from_annot('subject', hemi='both', parc='aparc',
subjects_dir=subjects_dir, regexp=None)[0]*
it gives the following output
Reading labels from parcellation...
read 34 labels from
/home/vivek/Downloads/freesurfer/subjects/sub-CC721377_T1w/label/lh.aparc.annot
read 34 labels from
/home/vivek/Downloads/freesurfer/subjects/sub-CC721377_T1w/label/rh.aparc.annot
and the variable label contains: <Label | sub-CC721377_T1w,
'bankssts-lh', lh : 1265 vertices>
if I remove [0] from end in the code, the output changes to lengthy list of
labels. but this output I cannot include using code: *stc1 =
stc.in_label(label). *It gives following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/home/vivek/anaconda3/lib/python3.7/site-packages/mne/source_estimate.py",
line 1197, in in_label
if label.subject is not None and self.subject is not None \
AttributeError: 'list' object has no attribute 'subject'
Perhaps you are confusing labels and vertices? The desikan atlas contains
68 *labels*, and what the output is telling you is that it loads 34 labels
for the left hemisphere, and 34 labels for the right hemisphere, for a
total of 68 labels. So that is working as expected. But each individual
*label* has different numbers of vertices (depending on the size of the
label). Again, your output is telling you this: the variable `label` is
for the banks of the superior temporal sulcus - left hemisphere
(bankssts-lh), and contains 1265 vertices.
I'm still not 100% clear on what you're trying to do, but one of these
might be the right direction:
1. Use the regexp argument of mne.read_labels_from_annot() to get the
label(s) you want (instead of indexing with [0]). If you want, you can run
it multiple times with different regexp arguments, and combine several
labels with the + operator. From there you can use
mne.SourceEstimate.in_label().
2. mne.SourceEstimate.extract_label_time_course() # takes a label or list
of labels
3. mne.Label.center_of_mass() # reduces a label to a single vertex; if
what you really want is just 68 vertices, one for each label
Thank you so much. Your answer clears the confusion.
If I define the regexp, the output I get consists of single label but I
want 68 labels.
If I do not define regexp, and also not the indexing, I could not run the
code: stc = stc.in_label(label)
Is there a way I can get all the 68 label in a single variable and run this
line: stc = stc.in_label(label) and further reduce the vertices to a single
label.
This is what exactly I want: # reduces a label to a single vertex; if what
you really want is just 68 vertices, one for each label.
Is there a way I can get all the 68 label in a single variable and run
this line: stc = stc.in_label(label) and further reduce the vertices to a
single label.
I'm still not 100% clear what you want to do. I'm stuck on "reduce the
vertices to a single label" --- if you mean "restrict the all the vertices
on the cortical surface to only the vertices defined by that label", well,
that's exactly what mne.SourceEstimate.in_label() does. If you need to do
it for all 68 labels, you can do it in a for loop. But that will not
reduce to just one data point (or time course) per label... it will still
have separate data for each vertex within each label.
If you want to start with a SourceEstimate and end up with 68 data points
(or 68 time series) --- one for each of the 68 labels --- look closer at
mne.SourceEstimate.extract_label_time_course().
Thanks.
I could generate the 68 time series with this --
mne.SourceEstimate.extract_label_time_course().
In a variable x I have 68 time series....
x = stc.extract_label_time_course(label, src, mode='mean_flip',
allow_empty=False, verbose=None)
but I'm unable to plot this as I use to plot stc.
I use the following line to plot stc file:
"*brain = mne.viz.plot_source_estimates(stc, subject='sub-CC721377_T1w',
surface='inflated', hemi='both', colormap='auto', time_label='auto',
smoothing_steps=10, transparent=True, alpha=1.0, time_viewer=True,
subjects_dir=subjects_dir, figure=None, views='lat', colorbar=True,
clim='auto', cortex='high_contrast', size=800, background='black',
foreground='white', initial_time=peak_time, time_unit='s', backend='auto',
spacing='oct6', title='eLORETA1', verbose=None)*"
I could have 68 labels in variable name label with this line of code:
label = mne.read_labels_from_annot('sub-CC721377_T1w', hemi='both',
parc='aparc', subjects_dir=subjects_dir, regexp=None)
and (68, time ) matrix using this line:
x = stc.extract_label_time_course(label, src, mode='mean_flip',
allow_empty=False, verbose=None)
gives the following output:
Extracting time courses for 68 labels (mode: mean_flip)
as suggested by Eric Lanson I'm using following line of code to generate
stc file with the above output files:
stc1 = mne.labels_to_stc(label, x, tmin=0, tstep=1, subject=None,
verbose=None)
The output I get in stc1 is:
<SourceEstimate | 296592 vertices, subject : sub-CC721377_T1w, tmin : 0.0
(ms), tmax : 179000.0 (ms), tstep : 1000.0 (ms), data shape : (296592, 180)>
where as I was expecting the number of vertices to be 68.