-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ENH, MRG] Add mne.viz.Brain.plot_sensors and refactor mne.viz.plot_alignment
#9585
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6466e47
working version of plot sensors
alexrockhill c67f8a4
Update 70_fnirs_processing.py
rob-luke e940aa3
fix test
alexrockhill fe8309c
alex review
alexrockhill e58b370
Dan review
alexrockhill a7ec6b8
fix test
alexrockhill 2804d8a
alex review
alexrockhill 8d0ee14
Eric review
alexrockhill 15f8df6
tried to refactor add sensors
alexrockhill cd1434f
put back
alexrockhill a7c80d5
fix tests
alexrockhill 0442e50
Eric comment
alexrockhill 2f151d3
fix tests
alexrockhill 390af4f
fix transposed arguments
alexrockhill 921cb32
fix tests
alexrockhill 79c2cc5
fix test
alexrockhill 6b6a672
Update doc/changes/latest.inc
alexrockhill 5ab4243
Eric review
alexrockhill b1a4b15
fix style
alexrockhill f4165e9
remove back exclude
alexrockhill d3abbcf
fix bem exception
alexrockhill dbc2205
review
alexrockhill 2f9b8b9
fix flake
alexrockhill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ def _check_subject_dir(subject, subjects_dir): | |
| raise ValueError('Freesurfer recon-all subject folder ' | ||
| 'is incorrect or improperly formatted, ' | ||
| f'got {op.join(subjects_dir, subject)}') | ||
| return subjects_dir | ||
| return op.join(subjects_dir, subject) | ||
|
|
||
|
|
||
| def _get_aseg(aseg, subject, subjects_dir): | ||
|
|
@@ -402,7 +402,7 @@ def get_mni_fiducials(subject, subjects_dir=None, verbose=None): | |
|
|
||
| For more details about the coordinate systems and transformations involved, | ||
| see https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems and | ||
| :ref:`plot_source_alignment`. | ||
| :ref:`tut-source-alignment`. | ||
| """ | ||
| # Eventually we might want to allow using the MNI Talairach with-skull | ||
| # transformation rather than the standard brain-based MNI Talaranch | ||
|
|
@@ -422,6 +422,47 @@ def get_mni_fiducials(subject, subjects_dir=None, verbose=None): | |
| return fids | ||
|
|
||
|
|
||
| @verbose | ||
| def estimate_head_mri_t(subject, subjects_dir=None, verbose=None): | ||
| """Estimate the head->mri transform from fsaverage fiducials. | ||
|
|
||
| A subject's fiducials can be estimated given a Freesurfer ``recon-all`` | ||
| by transforming ``fsaverage`` fiducials using the inverse Talairach | ||
| transform, see :func:`mne.coreg.get_mni_fiducials`. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| %(subject)s | ||
| %(subjects_dir)s | ||
| %(verbose)s | ||
|
|
||
| Returns | ||
| ------- | ||
| %(trans_not_none)s | ||
| """ | ||
| from .channels.montage import make_dig_montage, compute_native_head_t | ||
| subjects_dir = get_subjects_dir(subjects_dir, raise_error=True) | ||
| lpa, nasion, rpa = get_mni_fiducials(subject, subjects_dir) | ||
| montage = make_dig_montage(lpa=lpa['r'], nasion=nasion['r'], rpa=rpa['r'], | ||
| coord_frame='mri') | ||
| return invert_transform(compute_native_head_t(montage)) | ||
|
|
||
|
|
||
| def _ensure_image_in_surface_RAS(image, subject, subjects_dir): | ||
| """Check if the image is in Freesurfer surface RAS space.""" | ||
| import nibabel as nib | ||
| if not isinstance(image, nib.spatialimages.SpatialImage): | ||
| image = nib.load(image) | ||
| image = nib.MGHImage(image.dataobj.astype(np.float32), image.affine) | ||
| fs_img = nib.load(op.join(subjects_dir, subject, 'mri', 'brain.mgz')) | ||
| if not np.allclose(image.affine, fs_img.affine, atol=1e-6): | ||
| raise RuntimeError('The `image` is not aligned to Freesurfer ' | ||
| 'surface RAS space. This space is required as ' | ||
| 'it is the space where the anatomical ' | ||
| 'segmentation and reconstructed surfaces are') | ||
| return image # returns MGH image for header | ||
|
|
||
|
|
||
| @verbose | ||
| def read_talxfm(subject, subjects_dir=None, verbose=None): | ||
| """Compute MRI-to-MNI transform from FreeSurfer talairach.xfm file. | ||
|
|
@@ -632,3 +673,43 @@ def _get_head_surface(surf, subject, subjects_dir, bem=None, verbose=None): | |
| return _read_mri_surface(fname) | ||
| raise IOError('No head surface found for subject ' | ||
| f'{subject} after trying:\n' + '\n'.join(try_fnames)) | ||
|
|
||
|
|
||
| @verbose | ||
| def _get_skull_surface(surf, subject, subjects_dir, bem=None, verbose=None): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this is redundant with some BEM functions that will read all surfaces. You can just pick the skull from it. |
||
| """Get a skull surface from the Freesurfer subject directory. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| surf : str | ||
| The name of the surface 'outer' or 'inner'. | ||
| %(subject)s | ||
| %(subjects_dir)s | ||
| bem : mne.bem.ConductorModel | None | ||
| The conductor model that stores information about the skull surface. | ||
| %(verbose)s | ||
|
|
||
| Returns | ||
| ------- | ||
| skull_surf : dict | None | ||
| A dictionary with keys 'rr', 'tris', 'ntri', 'use_tris', 'np' | ||
| and 'coord_frame' that store information for mesh plotting and other | ||
| useful information about the head surface. | ||
|
|
||
| Notes | ||
| ----- | ||
| .. versionadded: 0.24 | ||
| """ | ||
| if bem is not None: | ||
| try: | ||
| return _bem_find_surface(bem, surf + '_skull') | ||
| except RuntimeError: | ||
| logger.info('Could not find the surface for ' | ||
| 'skull in the provided BEM model, ' | ||
| 'looking in the subject directory.') | ||
| subjects_dir = get_subjects_dir(subjects_dir, raise_error=True) | ||
| fname = _check_fname(op.join(subjects_dir, subject, 'bem', | ||
| surf + '_skull.surf'), | ||
| overwrite='read', must_exist=True, | ||
| name=f'{surf} skull surface') | ||
| return _read_mri_surface(fname) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.