mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.73k stars 1.32k forks source link

[ENH] Add Intracranial Electrode Contact Picking GUI (PyQt) #9559

Closed alexrockhill closed 3 years ago

alexrockhill commented 3 years ago

The intracranial electrophysiology analysis pipeline could use a manual or semiautomated GUI to pick the locations of the electrode contacts based on a CT that has been aligned to the MR of that subject so that brain structures can be used to aid contact identification.

Basic Requirements:

Advanced Requirements:

cc @larsoner

alexrockhill commented 3 years ago

Ok I think a reasonable first PR would be to load in the CT and the MR, resampling the CT to MR space if needed and taking in some channel names from a raw object and then allow the user to move around and mark electrodes and return the positions.

larsoner commented 3 years ago

Ok I think a reasonable first PR would be to load in the CT and the MR, resampling the CT to MR space if needed and taking in some channel names from a raw object and then allow the user to move around and mark electrodes and return the positions.

Let's not include resampling in the GUI. This is easily scripted and done once ahead of time. The GUI I think should load a T1 and the CT-resampled-to-T1-space.

Do you have an idea of the API? I'm thinking something like:

def electrode_location_gui(info, subject=None, ct='CT_aligned.mgz', mri='T1.mgz', subjects_dir=None)

thus the common use case would be to resample your CT and save it to SUBJECTS_DIR/SUBJECT/CT_aligned.mgz and then just do:

raw = mne.io.read_raw_fif(...)
mne.gui.electrode_location_gui(raw.info, 'whoever')

and under the hood if subject is provided, we use f'{subjects_dir}/{subject}/{ct}' and f'{subjects_dir}/{subject}/{t1}'.

larsoner commented 3 years ago

... and instead of returning the localized positions, it can just set info['chs']['loc'] directly. That way at the end if you do raw.save(...) that instance will have the correct locations.

People can always use raw.get_montage if they want to see the locations they set.

agramfort commented 3 years ago

what do you think about putting such a GUI while at it's infancy in a dedicated package where contributing guidelines are less strict. Should allow you to iterate faster and accept mistakes more easily?

larsoner commented 3 years ago

what do you think about putting such a GUI while at it's infancy in a dedicated package

The current state is actually already better than this -- it already lives in a dedicated package (img_pipe) that has been pretty well manually tested. So one important gain by / motivation for moving to MNE I think is following the full contributing guidelines (TDD included)

alexrockhill commented 3 years ago

Do you have an idea of the API? I'm thinking something like:

def electrode_location_gui(info, subject=None, ct='CT_aligned.mgz', mri='T1.mgz', subjects_dir=None)

Sounds good to me except where is subject coming from if it's None?

larsoner commented 3 years ago

subject=None is just provided in case people don't want to use FreeSurfer volumes at all. In other words, if people pass full paths to ct and mri then subject won't be used at all (so no need to provide it)

larsoner commented 3 years ago

... but I'm okay with not supporting that use case right away

agramfort commented 3 years ago

let's do a video call to discuss this ok?

alexrockhill commented 3 years ago

Hmmm, yeah for the elec_img PR I had it resample but then I thought it was leading down the wrong path with lots of coordinate transforms to do it in a coordinate frame other than surface RAS

larsoner commented 3 years ago

@agramfort sure, let us know your availability in the iEEG GSoC discord channel and we'll coordinate there