Skip to content

Commit 01b76a5

Browse files
committed
Merge remote-tracking branch 'nipy/master'
2 parents e2591e9 + ccd0527 commit 01b76a5

20 files changed

+220
-105
lines changed

nipype/interfaces/afni/tests/test_auto_Autobox.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_Autobox_inputs():
2020
),
2121
out_file=dict(argstr='-prefix %s',
2222
name_source='in_file',
23+
name_template='%s_autobox',
2324
),
2425
outputtype=dict(),
2526
padding=dict(argstr='-npad %d',

nipype/interfaces/ants/tests/test_auto_Registration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def test_Registration_inputs():
104104
use_estimate_learning_rate_once=dict(),
105105
use_histogram_matching=dict(usedefault=True,
106106
),
107+
verbose=dict(argstr='-v',
108+
),
107109
winsorize_lower_quantile=dict(argstr='%s',
108110
usedefault=True,
109111
),

nipype/interfaces/freesurfer/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,19 @@ def _normalize_filenames(self):
216216
def _associated_file(in_file, out_name):
217217
"""Based on MRIsBuildFileName in freesurfer/utils/mrisurf.c
218218
219+
If no path information is provided for out_name, use path and
220+
hemisphere (if also unspecified) from in_file to determine the path
221+
of the associated file.
219222
Use in_file prefix to indicate hemisphere for out_name, rather than
220223
inspecting the surface data structure.
221-
Also, output to in_file's directory if path information not provided
222-
for out_name.
223224
"""
224225
path, base = os.path.split(out_name)
225226
if path == '':
226227
path, in_file = os.path.split(in_file)
227228
hemis = ('lh.', 'rh.')
228229
if in_file[:3] in hemis and base[:3] not in hemis:
229230
base = in_file[:3] + base
230-
return os.path.abspath(os.path.join(path, base))
231+
return os.path.join(path, base)
231232

232233

233234
class FSScriptCommand(FSCommand):

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Keeping this to avoid breaking external programs that depend on it, but
4040
# this should not be used internally
41-
FSVersion = Info.looseversion()
41+
FSVersion = Info.looseversion().vstring
4242

4343

4444
class ParseDICOMDirInputSpec(FSTraitedSpec):
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# AUTO-GENERATED by tools/checkspecs.py on 2017.04.21
2+
# Modified 2017.04.21 by Chris Markiewicz
3+
from __future__ import unicode_literals
4+
import pytest
5+
6+
from ..base import FSSurfaceCommand
7+
from ... import freesurfer as fs
8+
from ...io import FreeSurferSource
9+
10+
11+
def test_FSSurfaceCommand_inputs():
12+
input_map = dict(args=dict(argstr='%s',
13+
),
14+
environ=dict(nohash=True,
15+
usedefault=True,
16+
),
17+
ignore_exception=dict(nohash=True,
18+
usedefault=True,
19+
),
20+
subjects_dir=dict(),
21+
terminal_output=dict(nohash=True,
22+
),
23+
)
24+
inputs = FSSurfaceCommand.input_spec()
25+
26+
for key, metadata in list(input_map.items()):
27+
for metakey, value in list(metadata.items()):
28+
assert getattr(inputs.traits()[key], metakey) == value
29+
30+
31+
@pytest.mark.skipif(fs.no_freesurfer(), reason="freesurfer is not installed")
32+
def test_associated_file():
33+
fssrc = FreeSurferSource(subjects_dir=fs.Info.subjectsdir(),
34+
subject_id='fsaverage', hemi='lh')
35+
36+
fsavginfo = fssrc.run().outputs.get()
37+
38+
# Pairs of white/pial files in the same directories
39+
for white, pial in [('lh.white', 'lh.pial'),
40+
('./lh.white', './lh.pial'),
41+
(fsavginfo['white'], fsavginfo['pial'])]:
42+
43+
# Unspecified paths, possibly with missing hemisphere information,
44+
# are equivalent to using the same directory and hemisphere
45+
for name in ('pial', 'lh.pial', pial):
46+
assert FSSurfaceCommand._associated_file(white, name) == pial
47+
48+
# With path information, no changes are made
49+
for name in ('./pial', './lh.pial', fsavginfo['pial']):
50+
assert FSSurfaceCommand._associated_file(white, name) == name

nipype/interfaces/freesurfer/tests/test_auto_FSSurfaceCommand.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

nipype/interfaces/freesurfer/tests/test_auto_MRIsExpand.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def test_MRIsExpand_inputs():
2323
mandatory=True,
2424
position=-3,
2525
),
26-
navgs=dict(argstr='-navgs %d %d',
27-
),
2826
nsurfaces=dict(argstr='-N %d',
2927
),
3028
out_name=dict(argstr='%s',

nipype/interfaces/freesurfer/tests/test_auto_ReconAll.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def test_ReconAll_outputs():
151151
),
152152
filled=dict(loc='mri',
153153
),
154+
graymid=dict(altkey=['graymid', 'midthickness'],
155+
loc='surf',
156+
),
154157
inflated=dict(loc='surf',
155158
),
156159
jacobian_white=dict(loc='surf',

nipype/interfaces/freesurfer/tests/test_preprocess.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
from builtins import str
45
import os
56

67
import pytest
@@ -154,3 +155,9 @@ def test_bbregister(create_files_in_directory):
154155
'--reg {base}_bbreg_fsaverage.dat '
155156
'--mov {full} --s fsaverage'.format(
156157
full=filelist[0], base=base))
158+
159+
def test_FSVersion():
160+
"""Check that FSVersion is a string that can be compared with LooseVersion
161+
"""
162+
assert isinstance(freesurfer.preprocess.FSVersion, str)
163+
assert LooseVersion(freesurfer.preprocess.FSVersion) >= LooseVersion("0")

nipype/interfaces/freesurfer/tests/test_utils.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
from nipype.testing.fixtures import (create_files_in_directory_plus_dummy_file,
99
create_surf_file_in_directory)
1010

11+
from nipype.pipeline import engine as pe
12+
from nipype.interfaces import freesurfer as fs
1113
from nipype.interfaces.base import TraitError
12-
import nipype.interfaces.freesurfer as fs
14+
from nipype.interfaces.io import FreeSurferSource
1315

1416

1517
@pytest.mark.skipif(fs.no_freesurfer(), reason="freesurfer is not installed")
@@ -159,3 +161,52 @@ def test_surfshots(create_files_in_directory_plus_dummy_file):
159161
os.environ["DISPLAY"] = hold_display
160162
except KeyError:
161163
pass
164+
165+
166+
@pytest.mark.skipif(fs.no_freesurfer(), reason="freesurfer is not installed")
167+
def test_mrisexpand(tmpdir):
168+
fssrc = FreeSurferSource(subjects_dir=fs.Info.subjectsdir(),
169+
subject_id='fsaverage', hemi='lh')
170+
171+
fsavginfo = fssrc.run().outputs.get()
172+
173+
# dt=60 to ensure very short runtime
174+
expand_if = fs.MRIsExpand(in_file=fsavginfo['smoothwm'],
175+
out_name='expandtmp',
176+
distance=1,
177+
dt=60)
178+
179+
expand_nd = pe.Node(
180+
fs.MRIsExpand(in_file=fsavginfo['smoothwm'],
181+
out_name='expandtmp',
182+
distance=1,
183+
dt=60),
184+
name='expand_node')
185+
186+
# Interfaces should have same command line at instantiation
187+
orig_cmdline = 'mris_expand -T 60 {} 1 expandtmp'.format(fsavginfo['smoothwm'])
188+
assert expand_if.cmdline == orig_cmdline
189+
assert expand_nd.interface.cmdline == orig_cmdline
190+
191+
# Run both interfaces
192+
if_res = expand_if.run()
193+
nd_res = expand_nd.run()
194+
195+
# Commandlines differ
196+
node_cmdline = 'mris_expand -T 60 -pial {cwd}/lh.pial {cwd}/lh.smoothwm ' \
197+
'1 expandtmp'.format(cwd=nd_res.runtime.cwd)
198+
assert if_res.runtime.cmdline == orig_cmdline
199+
assert nd_res.runtime.cmdline == node_cmdline
200+
201+
# Check output
202+
if_out_file = if_res.outputs.get()['out_file']
203+
nd_out_file = nd_res.outputs.get()['out_file']
204+
# Same filename
205+
assert op.basename(if_out_file) == op.basename(nd_out_file)
206+
# Interface places output in source directory
207+
assert op.dirname(if_out_file) == op.dirname(fsavginfo['smoothwm'])
208+
# Node places output in working directory
209+
assert op.dirname(nd_out_file) == nd_res.runtime.cwd
210+
211+
# Remove test surface
212+
os.unlink(if_out_file)

0 commit comments

Comments
 (0)