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
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])