# digitization of points for 3d brain plots - ecog data

**URL:** <https://mne.discourse.group/t/digitization-of-points-for-3d-brain-plots-ecog-data/7283>\
**Category:** Support & Discussions\
**Tags:** ieeg-and-ecog, visualization\
**Created:** [July 25, 2023, 12:51am UTC](https://mne.discourse.group/t/digitization-of-points-for-3d-brain-plots-ecog-data/7283 "2023-07-25T00:51:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [July 25, 2023, 12:51am UTC](https://mne.discourse.group/t/digitization-of-points-for-3d-brain-plots-ecog-data/7283/1 "2023-07-25T00:51:10Z")

</div>

I am working with this ecog data - [https://github.com/NeuromatchAcademy/course-content/blob/main/projects/ECoG/load\_ECoG\_fingerflex.ipynb](https://github.com/NeuromatchAcademy/course-content/blob/main/projects/ECoG/load_ECoG_fingerflex.ipynb)

I converted the data to raw object (similar to this [Load the movement imagery dataset into MNE · GitHub](https://gist.github.com/petervelosy/bdd054a5e3e15ac909eb66a8f6ef5726)) but could not plot the 3d plots like here — [Working with ECoG data — MNE 1.4.2 documentation](https://mne.tools/stable/auto_tutorials/clinical/30_ecog.html)  
This dataset doesnt have a brain template. There are just x,y,z coordinates for the electrodes. Is there a way around to plot 3d?  
@alexrockhill

---

<div class="post-metadata">

**Author:** ![alexrockhill](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexrockhill/32/31_2.png) [@alexrockhill](https://mne.discourse.group/u/alexrockhill)\
**Post date:** [July 25, 2023, 1:13am UTC](https://mne.discourse.group/t/digitization-of-points-for-3d-brain-plots-ecog-data/7283/2 "2023-07-25T01:13:26Z")

</div>

Kai organizes his data a big ideosyncratically not quite like in BIDS so what you’re talking about takes a bit of doing and undocumented know how. The refaced brain is one of the matrices in that mat file (ie replaced the patient’s face with a template) and then the x y and z coordinates are in scanner RAS (I think, unless they’re strictly positive then they’re voxel coordinates) so you need to 1) pull the data matrix out and save to a nii file, 2) run the recon on that file and then you can 3) plot on the brain or transform to MNI and plot on a template. If you want Zoom tomorrow, we can probably get something working in 20 minutes and post a minimum working example here. Or if you don’t need more help go for it but fair warning all the coordinate transforms are a bit tricky.

---

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [July 25, 2023, 2:04am UTC](https://mne.discourse.group/t/digitization-of-points-for-3d-brain-plots-ecog-data/7283/3 "2023-07-25T02:04:02Z")

</div>

Sure, it would be great to get that done tomorrow. At least if I can get MWE for this dataset!

---

<div class="post-metadata">

**Author:** ![alexrockhill](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/alexrockhill/32/31_2.png) [@alexrockhill](https://mne.discourse.group/u/alexrockhill)\
**Post date:** [July 25, 2023, 10:18pm UTC](https://mne.discourse.group/t/digitization-of-points-for-3d-brain-plots-ecog-data/7283/4 "2023-07-25T22:18:14Z")

</div>

```python
import numpy as np
import mne
import matplotlib.pyplot as plt
from scipy.io import loadmat

data = loadmat('~/Downloads/fingerflex/data/cc/cc_fingerflex.mat')
verts, tris = data['brain'].item()
tris -= 1 # matlab one-indexed -> python zero-indexed
locs = data['locs']
renderer = mne.viz.create_3d_figure((600, 600), show=True, scene=False)

renderer.mesh(*verts.T, tris, 'gray')
for loc in locs:
    renderer.sphere(loc, 'yellow', 5)
    
ch_names = [f'ch{i}' for i in range(locs.shape[0])]
proj = renderer.project(xyz=locs, ch_names=ch_names)

xy, im = np.array([proj.xy[ch] for ch in proj.xy]), renderer.screenshot()

```
