Skip to content

fix: MNIBiasCorrection smart out_file #1806

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 22 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bf61ba6
fix: decode instead of ignore
mgxd Feb 10, 2017
18eedf7
fix: make outvol mandatory
mgxd Feb 10, 2017
2cecd53
enh: testing
mgxd Feb 10, 2017
9990a53
Merge branch 'tst/travis' of github.com:mgxd/nipype into fix/mnibias
mgxd Feb 10, 2017
1e19bca
Merge branch 'master' of https://github.com/nipy/nipype
mgxd Feb 11, 2017
ebfbc42
Merge branch 'fix/mnibias' of https://github.com/mgxd/nipype into fix…
mgxd Feb 11, 2017
4318274
fix: doctest
mgxd Feb 11, 2017
aaecb34
Merge branch 'fix/mnibias' of github.com:mgxd/nipype into fix/mnibias
mgxd Feb 14, 2017
5f040e9
Merge branch 'fix/mnibias' of github.com:mgxd/nipype into fix/mnibias
mgxd Feb 14, 2017
5782634
enh: genfile
mgxd Feb 14, 2017
c62acee
Merge branch 'fix/mnibias' of github.com:mgxd/nipype into fix/mnibias
mgxd Feb 14, 2017
fd1dda6
fix: outputspec
mgxd Feb 14, 2017
a56bfed
Merge branch 'fix/mnibias' of github.com:mgxd/nipype into fix/mnibias
mgxd Feb 14, 2017
cb74279
fix: outputspec attribute
mgxd Feb 14, 2017
a5fc440
fix: grab out file
mgxd Feb 14, 2017
6a44c6e
fix: mnibias test
mgxd Feb 14, 2017
b97a329
fix: removed changed file
mgxd Feb 14, 2017
8231470
fix: use _outputs()
mgxd Feb 15, 2017
8d935fb
fix: removed list outputs and test changes
mgxd Feb 15, 2017
2ef535b
Merge branch 'master' of github.com:nipy/nipype into fix/mnibias
mgxd Feb 16, 2017
ba1a863
removed genfile
mgxd Feb 16, 2017
da1bd76
Merge branch 'master' of github.com:nipy/nipype into fix/mnibias
mgxd Feb 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions nipype/interfaces/freesurfer/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,11 +1503,11 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec):
# mandatory
in_file = File(exists=True, mandatory=True, argstr="--i %s",
desc="input volume. Input can be any format accepted by mri_convert.")
# optional
out_file = File(argstr="--o %s", name_source=['in_file'],
name_template='%s_output', hash_files=False, keep_extension=True,
desc="output volume. Output can be any format accepted by mri_convert. " +
"If the output format is COR, then the directory must exist.")
# optional
iterations = traits.Int(4, argstr="--n %d",
desc="Number of iterations to run nu_correct. Default is 4. This is the number of times " +
"that nu_correct is repeated (ie, using the output from the previous run as the input for " +
Expand All @@ -1528,7 +1528,7 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec):
desc="Shrink parameter for finer sampling (default is 4)")

class MNIBiasCorrectionOutputSpec(TraitedSpec):
out_file = File(desc="output volume")
out_file = File(exists=True, desc="output volume")


class MNIBiasCorrection(FSCommand):
Expand Down Expand Up @@ -1563,11 +1563,6 @@ class MNIBiasCorrection(FSCommand):
input_spec = MNIBiasCorrectionInputSpec
output_spec = MNIBiasCorrectionOutputSpec

def _list_outputs(self):
outputs = self._outputs().get()
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
return outputs


class WatershedSkullStripInputSpec(FSTraitedSpec):
# required
Expand Down
28 changes: 28 additions & 0 deletions nipype/interfaces/freesurfer/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,31 @@ def test_synthesizeflash(create_files_in_directory):
syn2 = freesurfer.SynthesizeFLASH(t1_image=filelist[0], pd_image=filelist[1], flip_angle=20, te=5, tr=25)
assert syn2.cmdline == ('mri_synthesize 25.00 20.00 5.000 %s %s %s'
% (filelist[0], filelist[1], os.path.join(outdir, 'synth-flash_20.mgz')))

@pytest.mark.skipif(freesurfer.no_freesurfer(), reason="freesurfer is not installed")
def test_mandatory_outvol(create_files_in_directory):
filelist, outdir = create_files_in_directory
mni = freesurfer.MNIBiasCorrection()

# make sure command gets called
assert mni.cmd == "mri_nu_correct.mni"

# test raising error with mandatory args absent
with pytest.raises(ValueError): mni.cmdline

# test with minimal args
mni.inputs.in_file = filelist[0]
assert mni.cmdline == ('mri_nu_correct.mni --i %s --o %s_output.mgz'
% (filelist[0], filelist[0].replace('.mgz', '')))

# test with custom outfile
mni.inputs.out_file = 'new_corrected_file.mgz'
assert mni.cmdline == ('mri_nu_correct.mni --i %s --o new_corrected_file.mgz'
% (filelist[0]))

# constructor based tests
mni2 = freesurfer.MNIBiasCorrection(in_file=filelist[0],
out_file='bias_corrected_output',
iterations=4)
assert mni2.cmdline == ('mri_nu_correct.mni --i %s --n 4 --o bias_corrected_output.mgz'
% filelist[0])