Skip to content

Commit edff8db

Browse files
committed
Merge pull request #1411 from effigies/mri_concat_fix
FIX: Permit relative path for concatenated_file input to Concatenate()
2 parents bb86f47 + cd985f1 commit edff8db

File tree

7 files changed

+88
-33
lines changed

7 files changed

+88
-33
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Next release
22
============
3+
34
* ENH: Created interface for BrainSuite Cortical Surface Extraction command line tools (https://github.com/nipy/nipype/pull/1305)
45
* FIX: job execution on systems/approaches where locale is undefined (https://github.com/nipy/nipype/pull/1401)
56
* FIX: Clean up byte/unicode issues using subprocess (https://github.com/nipy/nipype/pull/1394)
@@ -26,6 +27,7 @@ Next release
2627
* FIX: Use realpath to determine hard link source (https://github.com/nipy/nipype/pull/1388)
2728
* FIX: Correct linking/copying fallback behavior (https://github.com/nipy/nipype/pull/1391)
2829
* ENH: Nipype workflow and interfaces for FreeSurfer's recon-all (https://github.com/nipy/nipype/pull/1326)
30+
* FIX: Permit relative path for concatenated_file input to Concatenate() (https://github.com/nipy/nipype/pull/1411)
2931

3032
Release 0.11.0 (September 15, 2015)
3133
============

nipype/interfaces/freesurfer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Top-level namespace for freesurfer."""
44

5-
from .base import Info, FSCommand
5+
from .base import Info, FSCommand, no_freesurfer
66
from .preprocess import (ParseDICOMDir, UnpackSDICOMDir, MRIConvert, Resample,
77
ReconAll, BBRegister, ApplyVolTransform, Smooth,
88
DICOMConvert, RobustRegister, FitMSParams,

nipype/interfaces/freesurfer/base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ def _subjects_dir_update(self):
117117
def set_default_subjects_dir(cls, subjects_dir):
118118
cls._subjects_dir = subjects_dir
119119

120-
@property
121-
def version(self):
122-
return Info.version()
123-
124120
def run(self, **inputs):
125121
if 'subjects_dir' in inputs:
126122
self.inputs.subjects_dir = inputs['subjects_dir']
@@ -220,3 +216,14 @@ def run(self, **inputs):
220216
self.inputs.num_threads = inputs['num_threads']
221217
self._num_threads_update()
222218
return super(FSCommandOpenMP, self).run(**inputs)
219+
220+
221+
def no_freesurfer():
222+
"""Checks if FreeSurfer is NOT installed
223+
used with skipif to skip tests that will
224+
fail if FreeSurfer is not installed"""
225+
226+
if Info.version() is None:
227+
return True
228+
else:
229+
return False

nipype/interfaces/freesurfer/model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,11 @@ class Concatenate(FSCommand):
603603

604604
def _list_outputs(self):
605605
outputs = self.output_spec().get()
606-
if not isdefined(self.inputs.concatenated_file):
607-
outputs['concatenated_file'] = os.path.join(os.getcwd(),
608-
'concat_output.nii.gz')
609-
else:
610-
outputs['concatenated_file'] = self.inputs.concatenated_file
606+
607+
fname = self.inputs.concatenated_file
608+
if not isdefined(fname):
609+
fname = 'concat_output.nii.gz'
610+
outputs['concatenated_file'] = os.path.join(os.getcwd(), fname)
611611
return outputs
612612

613613
def _gen_filename(self, name):
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
4+
import os
5+
import tempfile
6+
import shutil
7+
import numpy as np
8+
import nibabel as nib
9+
10+
from nipype.testing import assert_equal, skipif
11+
from nipype.interfaces.freesurfer import model, no_freesurfer
12+
import nipype.pipeline.engine as pe
13+
14+
15+
@skipif(no_freesurfer)
16+
def test_concatenate():
17+
tmp_dir = tempfile.mkdtemp()
18+
cwd = os.getcwd()
19+
os.chdir(tmp_dir)
20+
in1 = os.path.join(tmp_dir, 'cont1.nii')
21+
in2 = os.path.join(tmp_dir, 'cont2.nii')
22+
out = 'bar.nii'
23+
24+
data1 = np.zeros((3, 3, 3, 1), dtype=np.float32)
25+
data2 = np.ones((3, 3, 3, 5), dtype=np.float32)
26+
out_data = np.concatenate((data1, data2), axis=3)
27+
mean_data = np.mean(out_data, axis=3)
28+
29+
nib.Nifti1Image(data1, affine=np.eye(4)).to_filename(in1)
30+
nib.Nifti1Image(data2, affine=np.eye(4)).to_filename(in2)
31+
32+
# Test default behavior
33+
res = model.Concatenate(in_files=[in1, in2]).run()
34+
yield (assert_equal, res.outputs.concatenated_file,
35+
os.path.join(tmp_dir, 'concat_output.nii.gz'))
36+
yield (assert_equal, nib.load('concat_output.nii.gz').get_data(), out_data)
37+
38+
# Test specified concatenated_file
39+
res = model.Concatenate(in_files=[in1, in2], concatenated_file=out).run()
40+
yield (assert_equal, res.outputs.concatenated_file,
41+
os.path.join(tmp_dir, out))
42+
yield (assert_equal, nib.load(out).get_data(), out_data)
43+
44+
# Test in workflow
45+
wf = pe.Workflow('test_concatenate', base_dir=tmp_dir)
46+
concat = pe.Node(model.Concatenate(in_files=[in1, in2],
47+
concatenated_file=out),
48+
name='concat')
49+
wf.add_nodes([concat])
50+
wf.run()
51+
yield (assert_equal, nib.load(os.path.join(tmp_dir, 'test_concatenate',
52+
'concat', out)).get_data(),
53+
out_data)
54+
55+
# Test a simple statistic
56+
res = model.Concatenate(in_files=[in1, in2], concatenated_file=out,
57+
stats='mean').run()
58+
yield (assert_equal, nib.load(out).get_data(), mean_data)
59+
60+
os.chdir(cwd)
61+
shutil.rmtree(tmp_dir)

nipype/interfaces/freesurfer/tests/test_preprocess.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@
55
import nibabel as nif
66
import numpy as np
77
from tempfile import mkdtemp
8-
from nipype.testing import (assert_equal, assert_false, assert_true,
9-
assert_raises, skipif)
8+
from nipype.testing import assert_equal, assert_raises, skipif
109
import nipype.interfaces.freesurfer as freesurfer
1110

1211

13-
def no_freesurfer():
14-
if freesurfer.Info().version is None:
15-
return True
16-
else:
17-
return False
18-
19-
2012
def create_files_in_directory():
2113
outdir = os.path.realpath(mkdtemp())
2214
cwd = os.getcwd()
@@ -38,7 +30,7 @@ def clean_directory(outdir, old_wd):
3830
os.chdir(old_wd)
3931

4032

41-
@skipif(no_freesurfer)
33+
@skipif(freesurfer.no_freesurfer)
4234
def test_robustregister():
4335
filelist, outdir, cwd = create_files_in_directory()
4436

@@ -66,7 +58,7 @@ def test_robustregister():
6658
clean_directory(outdir, cwd)
6759

6860

69-
@skipif(no_freesurfer)
61+
@skipif(freesurfer.no_freesurfer)
7062
def test_fitmsparams():
7163
filelist, outdir, cwd = create_files_in_directory()
7264

@@ -91,7 +83,7 @@ def test_fitmsparams():
9183
clean_directory(outdir, cwd)
9284

9385

94-
@skipif(no_freesurfer)
86+
@skipif(freesurfer.no_freesurfer)
9587
def test_synthesizeflash():
9688
filelist, outdir, cwd = create_files_in_directory()
9789

nipype/interfaces/freesurfer/tests/test_utils.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
import nipype.interfaces.freesurfer as fs
1616

1717

18-
def no_freesurfer():
19-
if fs.Info().version is None:
20-
return True
21-
else:
22-
return False
23-
24-
2518
def create_files_in_directory():
2619
outdir = os.path.realpath(mkdtemp())
2720
cwd = os.getcwd()
@@ -60,7 +53,7 @@ def clean_directory(outdir, old_wd):
6053
os.chdir(old_wd)
6154

6255

63-
@skipif(no_freesurfer)
56+
@skipif(fs.no_freesurfer)
6457
def test_sample2surf():
6558

6659
s2s = fs.SampleToSurface()
@@ -104,7 +97,7 @@ def set_illegal_range():
10497
clean_directory(cwd, oldwd)
10598

10699

107-
@skipif(no_freesurfer)
100+
@skipif(fs.no_freesurfer)
108101
def test_surfsmooth():
109102

110103
smooth = fs.SurfaceSmooth()
@@ -139,7 +132,7 @@ def test_surfsmooth():
139132
clean_directory(cwd, oldwd)
140133

141134

142-
@skipif(no_freesurfer)
135+
@skipif(fs.no_freesurfer)
143136
def test_surfxfm():
144137

145138
xfm = fs.SurfaceTransform()
@@ -173,7 +166,7 @@ def test_surfxfm():
173166
clean_directory(cwd, oldwd)
174167

175168

176-
@skipif(no_freesurfer)
169+
@skipif(fs.no_freesurfer)
177170
def test_surfshots():
178171

179172
fotos = fs.SurfaceSnapshots()

0 commit comments

Comments
 (0)