WIP, ENH: Add sensors to Brain#8803
WIP, ENH: Add sensors to Brain#8803GuillaumeFavelier wants to merge 20 commits intomne-tools:mainfrom
Conversation
|
I play with it using: import os.path as op
import numpy as np
import nibabel as nib
import mne
data_path = mne.datasets.sample.data_path()
subjects_dir = op.join(data_path, 'subjects')
raw_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_raw.fif')
trans_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_raw-trans.fif')
raw = mne.io.read_raw_fif(raw_fname)
trans = mne.read_trans(trans_fname)
src = mne.read_source_spaces(op.join(subjects_dir, 'sample', 'bem',
'sample-oct-6-src.fif'))
# Load the T1 file and change the header information to the correct units
t1w = nib.load(op.join(data_path, 'subjects', 'sample', 'mri', 'T1.mgz'))
t1w = nib.Nifti1Image(t1w.dataobj, t1w.affine)
t1w.header['xyzt_units'] = np.array(10, dtype='uint8')
t1_mgh = nib.MGHImage(t1w.dataobj, t1w.affine)
Brain = mne.viz.get_brain_class()
brain = Brain(subject_id="sample", hemi="both", surf="white", alpha=0.7,
units="m")
brain.add_sensors(info=raw.info, trans=trans, coord_frame='meg')
mne.viz.plot_alignment(raw.info, trans=trans, subject='sample',
subjects_dir=subjects_dir, surfaces='head-dense',
show_axes=True, dig=True, eeg=[], meg='sensors',
coord_frame='meg', mri_fiducials='estimated',
fig=brain._renderer.scene())I had to change |
|
brain.add_sensors should not have a |
|
Working on EEG now. Where to fetch the sensors' color? |
|
Same place as https://github.com/mne-tools/mne-python/blob/main/mne/viz/_3d.py#L1063-L1065 Eventually we'll want to add a parameter to allow controlling the sensor color on a channel-name basis, but not in the first PR (need to sort out the API). But if you can at least consider this use case it might help guide the initial design. |
|
Another naive question, should I add support for projected EEG also? On what surface? Also |
Not in the first PR, we can always add it later.
You either need |
| return dict(rr=meg_rrs, tris=meg_tris) | ||
|
|
||
|
|
||
| def _get_coord_frame_trans(coord_frame, info, trans): |
There was a problem hiding this comment.
This seems confusing, could you just transform to head if in "meg", then transform to mri if in originally in "meg" (now "head" because it was just transformed) or "head"? That seems like it might be more straightforward
There was a problem hiding this comment.
Ah I guess you might need them multiple times so that might not work


This PR follows #8382 (comment) and implements
add_sensorsto plot MEG and EEG sensors.For now, I move code and experiment. Refactoring is necessary to avoid duplication between
plot_alignment()andadd_sensors.This is still work in progress.