Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG; ENH] Add "add_estimated_fiducials" to DigMontage #9118

Merged
merged 20 commits into from Mar 18, 2021

Conversation

adam2392
Copy link
Member

@adam2392 adam2392 commented Mar 16, 2021

Reference issue

Closes: #9111

Will enhance: #9087 and plot_seeg related tutorials in the future. Necessary ingredients for dataset though:

  • FreeSurfer subject-specific files
  • electrode coordinates in FS subject-specific T1w

What does this implement/fix?

Add add_estimated_fiducials function to DigMontage.

Implements unit test... todo

Additional information

From BIDS convos of mne sprint chat.

@adam2392
Copy link
Member Author

@larsoner I am not sure how to best follow the unit tests you specified in #9111 (comment)

I kind of... pseudocoded it out here, but not familiar w/ all the testing datasets in MNE. Would you be able to provide some more explicit guidance here on what exactly do I load and compare?

@larsoner
Copy link
Member

Probably something close to this:

https://github.com/mne-tools/mne-python/blob/main/mne/tests/test_coreg.py#L267-L281

You want to load the actual manually-created sample -trans.fif, and compare it to the one you get if you use your new function. You can do this second part for example by creating an arbitrary 1-channel montage for sample (the channel position does not matter) with the MRI coordinate frame, then use your estimation function, and montage.get_native_head_t() and see if the rotation angle (quat_to_rot) is small and the translation is small.

mne/channels/montage.py Outdated Show resolved Hide resolved
mne/channels/montage.py Outdated Show resolved Hide resolved
@rob-luke
Copy link
Member

The failing ci is due to the doc strings. I made some suggestions about how this could be fixed, there may well be a better fix.

mne/channels/montage.py Outdated Show resolved Hide resolved
mne/channels/montage.py Show resolved Hide resolved
_validate_type(item=fids_mri, types=list, item_name='dig')

# add those digpoints to montage
self.dig.extend(fids_mri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to insert these at the beginning, I think that's usually where we put fiducials in the dig list.

mne/channels/tests/test_montage.py Outdated Show resolved Hide resolved
mne/channels/montage.py Outdated Show resolved Hide resolved
adam2392 and others added 7 commits March 17, 2021 09:30
Co-authored-by: Robert Luke <748691+rob-luke@users.noreply.github.com>
Co-authored-by: Robert Luke <748691+rob-luke@users.noreply.github.com>
Co-authored-by: Robert Luke <748691+rob-luke@users.noreply.github.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@adam2392
Copy link
Member Author

Is there a way to link the docstring to an existing tutorial?

E.g.

https://mne.tools/stable/auto_tutorials/source-modeling/plot_source_alignment.html?highlight=freesurfer%20coordinates#coordinate-frame-definitions

If a user isn't understanding why one needs the mri coord_frame. I know I asked that question until I read Eric's comment.

@drammock
Copy link
Member

Is there a way to link the docstring to an existing tutorial?

Crossrefs to tutorials are probably most appropriate in a See also section, but could also be added inline to the docstring intro paragraph. To link to that tutorial you can use its target name:

@adam2392
Copy link
Member Author

If this CI works, will add the changelog. don't wanna hit the CIs again :p

@larsoner
Copy link
Member

Feel free to push, I'll probably go through and clear out the GitHub Actions log soon anyway...

@adam2392 adam2392 changed the title [WIP] Add "add_estimated_fiducials" to DigMontage [MRG; ENH] Add "add_estimated_fiducials" to DigMontage Mar 17, 2021
Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1 for merge once CIs come back happy (someday)

mne/channels/montage.py Outdated Show resolved Hide resolved
adam2392 and others added 2 commits March 17, 2021 16:08
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@larsoner larsoner merged commit ee18776 into mne-tools:main Mar 18, 2021
@larsoner
Copy link
Member

Thanks @adam2392 !

Copy link
Member

@agramfort agramfort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for coming late to the party :(

- :func:`mne.io.anonymize_info` now anonymizes also sex and hand fields when ``keep_his`` is ``False`` (:gh:`9103` by |Rotem Falach|_)`
- Add :func:`mne.channels.DigMontage.add_estimated_fiducials` which will add LPA, RPA and Nasion fiducial points to the ``DigMontage`` object in ``mri`` coordinate frame (:gh:`9118` by `Adam Li`_)

- :func:`mne.io.anonymize_info` now anonymizes also sex and hand fields when ``keep_his`` is ``False`` (:gh:`9103` by |Rotem Falach|_)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent pb

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this in main, it was my error during the mege...

This takes a montage with the ``mri`` coordinate frame,
corresponding to the FreeSurfer RAS (xyz in the volume) T1w
image of the specific subject. It will call
:func:`mne.coreg.get_mni_fiducials` to estimate LPA, RPA and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like to have stuff from coreg module to be imported outside. coreg should be GUI code only I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed we could move it to source_space.py, it's where we deal with coordinate frames most of the time anyway

and then use ``montage.get_native_head_t()`` to get the
head <-> MRI transform.
"""
from ..coreg import get_mni_fiducials
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes nested import is required exactly for this I think.

@agramfort
Copy link
Member

agramfort commented Mar 19, 2021 via email

@larsoner larsoner mentioned this pull request Mar 19, 2021
@adam2392 adam2392 deleted the estfids branch August 25, 2021 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add montage.add_estimated_fiducials
5 participants