# How to set atlas

**URL:** <https://mne.discourse.group/t/how-to-set-atlas/1714>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [January 16, 2019, 7:24am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714 "2019-01-16T07:24:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 16, 2019, 7:24am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/1 "2019-01-16T07:24:51Z")

</div>

External Email - Use Caution

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\*) "

[https://martinos.org/mne/stable/generated/mne.bem.make\_watershed\_bem.html#mne.bem.make\_watershed\_bem](https://martinos.org/mne/stable/generated/mne.bem.make_watershed_bem.html#mne.bem.make_watershed_bem)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 17, 2019, 5:44am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/2 "2019-01-17T05:44:00Z")

</div>

External Email - Use Caution

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\*) "

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 17, 2019, 8:39am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/3 "2019-01-17T08:39:32Z")

</div>

External Email - Use Caution

make\_watershed\_bem uses an atlas to get a good skull segmentation

it's not an atlas of the cortical surface as you suggest

HTH  
A

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 17, 2019, 11:04am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/4 "2019-01-17T11:04:43Z")

</div>

External Email - Use Caution

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?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 17, 2019, 11:41am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/5 "2019-01-17T11:41:52Z")

</div>

External Email - Use Caution

Hi,

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

best,

Dip

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 22, 2019, 10:18am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/6 "2019-01-22T10:18:03Z")

</div>

External Email - Use Caution

Hi,  
Thanks for the code.  
I tried with this method but it reduces the number of vertices to 35, I  
want it to be 68 according to Desikan atlas.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 23, 2019, 1:21pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/7 "2019-01-23T13:21:05Z")

</div>

External Email - Use Caution

Follow this:  
[https://github.com/mne-tools/mne-python/issues/5850](https://github.com/mne-tools/mne-python/issues/5850)

best,

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 23, 2019, 3:58pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/8 "2019-01-23T15:58:50Z")

</div>

External Email - Use Caution

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:

> > > label = mne.read\_labels\_from\_annot('sub-CC721377\_T1w', hemi='both',

parc='aparc', subjects\_dir=subjects\_dir, regexp=None)  
Reading labels from parcellation...  
&nbsp;&nbsp;&nbsp;read 34 labels from  
/home/vivek/Downloads/freesurfer/subjects/sub-CC721377\_T1w/label/lh.aparc.annot  
&nbsp;&nbsp;&nbsp;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):  
&nbsp;&nbsp;File "\<stdin\>", line 1, in \<module\>  
&nbsp;&nbsp;File  
"/home/vivek/anaconda3/lib/python3.7/site-packages/mne/source\_estimate.py",  
line 1197, in in\_label  
&nbsp;&nbsp;&nbsp;&nbsp;if label.subject is not None and self.subject is not None \  
AttributeError: 'list' object has no attribute 'subject'

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [January 23, 2019, 4:09pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/9 "2019-01-23T16:09:36Z")

</div>

External Email - Use Caution

.in\_label(label) takes a single argument i.e., single label. Just combine  
the both labels and continue. For details, see this:  
[https://martinos.org/mne/stable/generated/mne.SourceEstimate.html?highlight=in\_label#mne.SourceEstimate.in\_label](https://martinos.org/mne/stable/generated/mne.SourceEstimate.html?highlight=in_label#mne.SourceEstimate.in_label)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 4, 2019, 10:09am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/10 "2019-02-04T10:09:04Z")

</div>

External Email - Use Caution

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...

\*stc = mne.minimum\_norm.apply\_inverse\_raw(raw, inverse\_operator, lambda2,  
method='eLORETA', label=None, start=60, stop=240, nave=1, time\_func=None,  
pick\_ori=None, buffer\_size=None, prepared=False, method\_params=None,  
verbose=None)\*

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:

\*label = mne.read\_labels\_from\_annot('subject', hemi='both', parc='aparc',  
subjects\_dir=subjects\_dir, regexp=None)[0]\*  
\*stc1 = stc.in\_label(label)\*

Now the stc1 contain 35 vertices but I want 68 (Desikan)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 4, 2019, 6:25pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/11 "2019-02-04T18:25:47Z")

</div>

External Email - Use Caution

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?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 5, 2019, 7:11am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/12 "2019-02-05T07:11:25Z")

</div>

External Email - Use Caution

please find my comments marked in red.

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;External Email - Use Caution
> 
> 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...  
&nbsp;&nbsp;&nbsp;read 34 labels from  
/home/vivek/Downloads/freesurfer/subjects/sub-CC721377\_T1w/label/lh.aparc.annot  
&nbsp;&nbsp;&nbsp;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):  
&nbsp;&nbsp;File "\<stdin\>", line 1, in \<module\>  
&nbsp;&nbsp;File  
"/home/vivek/anaconda3/lib/python3.7/site-packages/mne/source\_estimate.py",  
line 1197, in in\_label  
&nbsp;&nbsp;&nbsp;&nbsp;if label.subject is not None and self.subject is not None \  
AttributeError: 'list' object has no attribute 'subject'

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 5, 2019, 7:05pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/13 "2019-02-05T19:05:10Z")

</div>

External Email - Use Caution

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 7, 2019, 4:00pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/14 "2019-02-07T16:00:24Z")

</div>

External Email - Use Caution

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 7, 2019, 7:54pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/15 "2019-02-07T19:54:26Z")

</div>

External Email - Use Caution

> 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().

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 8, 2019, 11:36am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/16 "2019-02-08T11:36:20Z")

</div>

External Email - Use Caution

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)\*"

How can I plot this extracted time series?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 8, 2019, 4:14pm UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/17 "2019-02-08T16:14:23Z")

</div>

External Email - Use Caution

This is probably what you want (only available in `master` currently,  
hasn't been released yet):

[http://mne-tools.github.io/dev/generated/mne.labels\_to\_stc.html](http://mne-tools.github.io/dev/generated/mne.labels_to_stc.html)

It takes a set of labels and matching set of time series, and constructs a  
stc from them.

Eric

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 11, 2019, 7:15am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/18 "2019-02-11T07:15:03Z")

</div>

External Email - Use Caution

Thanks.  
How can I work with mne-0.18.dev0. I tried downloading but it downloads  
0.17.0.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 11, 2019, 8:18am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/19 "2019-02-11T08:18:02Z")

</div>

External Email - Use Caution

see:

[http://martinos.org/mne/stable/advanced\_setup.html#using-the-development-version-of-mne-latest-master](http://martinos.org/mne/stable/advanced_setup.html#using-the-development-version-of-mne-latest-master)

HTH  
Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 11, 2019, 9:50am UTC](https://mne.discourse.group/t/how-to-set-atlas/1714/20 "2019-02-11T09:50:19Z")

</div>

External Email - Use Caution

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.
