mne-tools / mne-python

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

Add montage.add_estimated_fiducials #9111

Closed larsoner closed 3 years ago

larsoner commented 3 years ago

New method of montage that, if the montage is in MRI / FreeSurfer surface RAS coordinates, will estimate the fiducials (using mne.coreg.get_mni_fiducials) and add them to the montage. For example this docstring:

"""Estimate fiducials based on FreeSurfer parameters

Parameters
---------
subject : ...
subjects_dir ...

It should help iEEG folks get their montages to be MNE/FIF compatible without requiring a bunch of changes in MNE. For example they would have:

montage = ...  # wherever they get their electrodes in MRI (FS Surface RAS) coords
montage.add_estimated_fiducials(subject, subjects_dir)  # adds LPA/Nasion/RPA based on FS files
trans = montage.get_native_head_t()  # head<->MRI trans can now be computed properly

Then when they set_montage, MNE internally converts to all electrode locations to head coords as usual (for now at least), and iEEG folks pass trans to functions that need them (like plot_alignment) and now all coordinate frames are properly defined. Still future compatible with the dream of MNE supporting coordinate frames other than head for EEG electrodes (since it just allows us to properly define the Neuromag coordinate frame), but gives us a bit more leeway to punt on that for now.

Discussed with @libertyh as a possible partial solution for iEEG folks.

adam2392 commented 3 years ago

I can do this really quickly. This can then augment #9087

Does this function just call: mne.coreg.get_mni_fiducials? Is there a unit-test in mind we can apply here?

larsoner commented 3 years ago

Excellent!

Does this function just call: mne.coreg.get_mni_fiducials?

Yes, and adds it to the montage in the right way (whatever that is).

Is there a unit-test in mind we can apply here?

You can test it on fsaverage, it should match (to numerical precision) the built-in fsaverage trans .fif file we have. You can test it on sample, and it should match to some correlation limit (0.98+ I'm guesssing) the manually-created trans for sample.