From 773566a9f8784eef95f2bbb48f0b468b0659fe7a Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 11 Sep 2019 14:03:13 -0400 Subject: [PATCH] FIX: Adjust tests --- doc/changes/latest.inc | 2 ++ mne/morph.py | 39 +++++++++++++++++---------------------- mne/source_estimate.py | 2 +- mne/viz/tests/test_3d.py | 4 ++-- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index 9436f6568d1..b5a82b2b401 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -94,6 +94,8 @@ Bug - Fix bug in :meth:`mne.SourceMorph.apply` where output STCs had ``stc.vertices`` defined improperly, by `Eric Larson`_ +- Fix bug in :meth:`mne.SourceMorph.apply` where the default was errantly ``mri_space=False`` instead of ``mri_space=None`` (as documented), by `Eric Larson`_ + - Fix :meth:`mne.io.Raw.set_annotations` for ``meas_date`` previous to 1970 by `Joan Massich`_ - Fix horizontal spacing issues in :meth:`mne.io.Raw.plot_psd` by `Jeff Hanna`_ diff --git a/mne/morph.py b/mne/morph.py index 963ddc24a76..b684c78c04f 100644 --- a/mne/morph.py +++ b/mne/morph.py @@ -326,7 +326,7 @@ def __init__(self, subject_from, subject_to, kind, zooms, @verbose def apply(self, stc_from, output='stc', mri_resolution=False, - mri_space=False, verbose=None): + mri_space=None, verbose=None): """Morph source space data. Parameters @@ -341,9 +341,9 @@ def apply(self, stc_from, output='stc', mri_resolution=False, If True the image is saved in MRI resolution. Default False. WARNING: if you have many time points the file produced can be huge. The default is mri_resolution=False. - mri_space : bool + mri_space : bool | None Whether the image to world registration should be in mri space. The - default is mri_space=mri_resolution. + default (None) is mri_space=mri_resolution. %(verbose_meth)s Returns @@ -470,8 +470,7 @@ def _check_dep(nibabel='2.1.0', dipy='0.10.1'): ver)) -def _morphed_stc_as_volume(morph, stc, mri_resolution=False, mri_space=True, - output='nifti1'): +def _morphed_stc_as_volume(morph, stc, mri_resolution, mri_space, output): """Return volume source space as Nifti1Image and/or save to disk.""" if isinstance(stc, VolVectorSourceEstimate): stc = stc.magnitude() @@ -480,15 +479,7 @@ def _morphed_stc_as_volume(morph, stc, mri_resolution=False, mri_space=True, 'volumes') _check_dep(nibabel='2.1.0', dipy=False) - _check_option('output', output, ['nifti', 'nifti1', 'nifti2']) - if output in ('nifti', 'nifti1'): - from nibabel import (Nifti1Image as NiftiImage, - Nifti1Header as NiftiHeader) - else: - assert output == 'nifti2' - from nibabel import (Nifti2Image as NiftiImage, - Nifti2Header as NiftiHeader) - + NiftiImage, NiftiHeader = _triage_output(output) new_zooms = None # if full MRI resolution, compute zooms from shape and MRI zooms @@ -574,13 +565,8 @@ def _get_src_data(src): return src_data, src_kind -def _interpolate_data(stc, morph, mri_resolution=True, mri_space=True, - output='nifti1'): - """Interpolate source estimate data to MRI.""" - _check_dep(nibabel='2.1.0', dipy=False) - if output not in ('nifti', 'nifti1', 'nifti2'): - raise ValueError("invalid output specifier %s. Must be 'nifti1' or" - " 'nifti2'" % output) +def _triage_output(output): + _check_option('output', output, ['nifti', 'nifti1', 'nifti2']) if output in ('nifti', 'nifti1'): from nibabel import (Nifti1Image as NiftiImage, Nifti1Header as NiftiHeader) @@ -588,6 +574,13 @@ def _interpolate_data(stc, morph, mri_resolution=True, mri_space=True, assert output == 'nifti2' from nibabel import (Nifti2Image as NiftiImage, Nifti2Header as NiftiHeader) + return NiftiImage, NiftiHeader + + +def _interpolate_data(stc, morph, mri_resolution, mri_space, output): + """Interpolate source estimate data to MRI.""" + _check_dep(nibabel='2.1.0', dipy=False) + NiftiImage, NiftiHeader = _triage_output(output) assert morph.kind == 'volume' voxel_size_defined = False @@ -1151,9 +1144,11 @@ def _apply_morph_data(morph, stc_from): def _morph_one(stc_one): # prepare data to be morphed + # here we use mri_resolution=True, mri_space=True because + # we will slice afterward assert stc_one.data.shape[1] == 1 img_to = _interpolate_data(stc_one, morph, mri_resolution=True, - mri_space=True) + mri_space=True, output='nifti1') # reslice to match morph img_to, img_to_affine = reslice( diff --git a/mne/source_estimate.py b/mne/source_estimate.py index 5d46799c1fe..47e6e2c7c05 100644 --- a/mne/source_estimate.py +++ b/mne/source_estimate.py @@ -1780,7 +1780,7 @@ def as_volume(self, src, dest='mri', mri_resolution=False, Returns ------- - img : instance Nifti1Image + img : instance of Nifti1Image The image object. Notes diff --git a/mne/viz/tests/test_3d.py b/mne/viz/tests/test_3d.py index 239c2021af0..e62d0680bb5 100644 --- a/mne/viz/tests/test_3d.py +++ b/mne/viz/tests/test_3d.py @@ -476,9 +476,9 @@ def test_snapshot_brain_montage(renderer): @requires_nibabel() @requires_version('nilearn', '0.4') @pytest.mark.parametrize('mode, stype, init_t, want_t, init_p, want_p', [ - ('glass_brain', 's', None, 2, None, (-33.3, 16.0, 63.7)), + ('glass_brain', 's', None, 2, None, (-30.9, 18.4, 56.7)), ('stat_map', 'vec', 1, 1, None, (15.7, 16.0, -6.3)), - ('glass_brain', 'vec', None, 2, (10, -10, 20), (8.7, -12.0, 21.7)), + ('glass_brain', 'vec', None, 1, (10, -10, 20), (6.6, -9.0, 19.9)), ('stat_map', 's', 1, 1, (-10, 5, 10), (-12.3, 2.0, 7.7))]) def test_plot_volume_source_estimates(mode, stype, init_t, want_t, init_p, want_p):