Skip to content

Commit

Permalink
FIX: Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Sep 11, 2019
1 parent bfef83a commit 773566a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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`_
Expand Down
39 changes: 17 additions & 22 deletions mne/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -574,20 +565,22 @@ 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)
else:
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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion mne/source_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mne/viz/tests/test_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 773566a

Please sign in to comment.