digitization of points for 3d brain plots - ecog data

I am working with this ecog data - 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) but could not plot the 3d plots like here — Working with ECoG data — MNE 1.4.2 documentation
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

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.

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

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