# Plot external source analysis

**URL:** <https://mne.discourse.group/t/plot-external-source-analysis/3685>\
**Category:** Support & Discussions\
**Tags:** ﻿source-localization, visualization\
**Created:** [September 12, 2021, 9:49am UTC](https://mne.discourse.group/t/plot-external-source-analysis/3685 "2021-09-12T09:49:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![noreun](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/noreun/32/782_2.png) [@noreun](https://mne.discourse.group/u/noreun)\
**Post date:** [September 12, 2021, 9:49am UTC](https://mne.discourse.group/t/plot-external-source-analysis/3685/1 "2021-09-12T09:49:59Z")

</div>

- MNE-Python version: 0.23.1
- operating system: Ubuntu 18.04.5 LTS as server running Jupyter and macbook BigSur 11.5 as client (with firefox 91.0.2).

Dear MNE community,

After performing source localization in my data, I extracted the time series per label using _stc.in\_label()_ and performed some analysis outside MNE, ending up with 68 values (one per region), stored in the some array _external\_computations_. Now I would like to plot these values in source space. What would be the easiest way to do that in MNE? I couldn’t find anything similar in the tutorials or in the discussions here.

I did hack something up after inspecting the mne.SourceEstimate class, which seems to be working, but it just looks… wrong 🙂

Here is the snippet that seems to do what I want, but I hope there is a better way of doing that:

```python
# Load original source estimates
labels = mne.read_labels_from_annot(subject, parc='aparc', hemi='both', subjects_dir=freesurfer_path)
stclh = read_source_estimate('./sources_sLORETA-lh.stc')
stcrh = read_source_estimate('./sources_sLORETA-rh.stc')

# Crop to get only one sample
stclh = stclh.crop(0, .0001)
stcrh = stcrh.crop(0, .0001)

# Set original source estimate values to zero
stclh.data[:] = 0
stcrh.data[:] = 0

# Update the values in each dipole of each region with the external computations in "external_computations", which is an array with 68 values, one per region
 
for (il, l) in enumerate(labels):
    if (l.name[-2:] == 'lh'):
        lvert = stclh.in_label(l).vertices[0]
        inter = np.intersect1d(lvert, stclh.vertices[0], return_indices=True)
        stclh.data[inter[2], 0] = external_computations[il]
        
    if (l.name[-2:] == 'rh'):
        lvert = stcrh.in_label(l).vertices[1]
        inter = np.intersect1d(lvert, stcrh.vertices[1], return_indices=True)
        stcrh.data[inter[2]+len(stclh.vertices[0]), 0] = external_computations[il]

```

Now in theory I can do the plots with _stclh.plot()_ and _stcrh.plot()_. But I’m not sure this is correct, and it looks overly complicated. For instance I have to sum the number of vertices in left hemisphere (_len(stclh.vertices[0])_) to the positions identified in the right hemisphere (_stcrh.in\_label(l).vertices[1]_) before indexing the actual data (_stcrh.data[]_). Is this the correct way to access the data of a particular region in the right hemisphere?

Best regards,  
Leonardo

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [September 13, 2021, 7:44am UTC](https://mne.discourse.group/t/plot-external-source-analysis/3685/2 "2021-09-13T07:44:08Z")

</div>

I don’t think there is a much simpler solution.

Alex

---

<div class="post-metadata">

**Author:** ![noreun](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/noreun/32/782_2.png) [@noreun](https://mne.discourse.group/u/noreun)\
**Post date:** [September 13, 2021, 8:42am UTC](https://mne.discourse.group/t/plot-external-source-analysis/3685/3 "2021-09-13T08:42:32Z")

</div>

Ok, I was just not sure if this was right, for instance I got the fact that the vertices in the right hemisphere were offset simply by trial and error (just indexing without the shift gave me “christmas tree” activity). I guess I’ll stick to this solution then. Tks!
