Skip to content

Commit 5f040e9

Browse files
committed
Merge branch 'fix/mnibias' of github.com:mgxd/nipype into fix/mnibias
2 parents b304510 + 4318274 commit 5f040e9

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ class MNIBiasCorrectionInputSpec(FSTraitedSpec):
14761476
# mandatory
14771477
in_file = File(exists=True, mandatory=True, argstr="--i %s",
14781478
desc="input volume. Input can be any format accepted by mri_convert.")
1479-
out_file = File(argstr="--o %s", name_source=['in_file'],
1479+
out_file = File(argstr="--o %s", mandatory=True, name_source=['in_file'],
14801480
name_template='%s_output', hash_files=False, keep_extension=True,
14811481
desc="output volume. Output can be any format accepted by mri_convert. " +
14821482
"If the output format is COR, then the directory must exist.")
@@ -1519,6 +1519,7 @@ class MNIBiasCorrection(FSCommand):
15191519
>>> from nipype.interfaces.freesurfer import MNIBiasCorrection
15201520
>>> correct = MNIBiasCorrection()
15211521
>>> correct.inputs.in_file = "norm.mgz"
1522+
>>> correct.inputs.out_file = "norm_output.mgz"
15221523
>>> correct.inputs.iterations = 6
15231524
>>> correct.inputs.protocol_iterations = 1000
15241525
>>> correct.inputs.distance = 50

nipype/interfaces/freesurfer/tests/test_preprocess.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,28 @@ def test_synthesizeflash(create_files_in_directory):
8585
syn2 = freesurfer.SynthesizeFLASH(t1_image=filelist[0], pd_image=filelist[1], flip_angle=20, te=5, tr=25)
8686
assert syn2.cmdline == ('mri_synthesize 25.00 20.00 5.000 %s %s %s'
8787
% (filelist[0], filelist[1], os.path.join(outdir, 'synth-flash_20.mgz')))
88+
89+
@pytest.mark.skipif(freesurfer.no_freesurfer(), reason="freesurfer is not installed")
90+
def test_mandatory_outvol(create_files_in_directory):
91+
filelist, outdir = create_files_in_directory
92+
mni = freesurfer.MNIBiasCorrection()
93+
94+
# make sure command gets called
95+
assert mni.cmd == "mri_nu_correct.mni"
96+
97+
# test raising error with mandatory args absent
98+
with pytest.raises(ValueError): mni.run()
99+
100+
# test raising error with only partial mandatory args present
101+
mni.inputs.in_file = filelist[0] #mgz
102+
with pytest.raises(ValueError): mni.run()
103+
104+
# rest of mandatory inputs
105+
mni.inputs.out_file = 'bias_corrected_output'
106+
107+
assert mni.cmdline == ('mri_nu_correct.mni --i %s --n 4 --o bias_corrected_output.mgz'
108+
% filelist[0])
109+
# constructor based tests
110+
mni2 = freesurfer.MNIBiasCorrection(in_file=filelist[0], out_file='bias_corrected_output')
111+
assert mni2.cmdline == ('mri_nu_correct.mni --i %s --n 4 --o bias_corrected_output.mgz'
112+
% filelist[0])

nipype/interfaces/mrtrix/convert.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
"""
1212
from __future__ import print_function, division, unicode_literals, absolute_import
13-
from builtins import open
13+
from io import open
1414

1515
import os.path as op
1616
import nibabel as nb
@@ -55,10 +55,11 @@ def read_mrtrix_tracks(in_file, as_generator=True):
5555

5656

5757
def read_mrtrix_header(in_file):
58-
fileobj = open(in_file, 'r')
58+
fileobj = open(in_file, 'rb')
5959
header = {}
6060
iflogger.info('Reading header data...')
6161
for line in fileobj:
62+
line = line.decode()
6263
if line == 'END\n':
6364
iflogger.info('Reached the end of the header!')
6465
break
@@ -78,7 +79,7 @@ def read_mrtrix_header(in_file):
7879
def read_mrtrix_streamlines(in_file, header, as_generator=True):
7980
offset = header['offset']
8081
stream_count = header['count']
81-
fileobj = open(in_file, 'r')
82+
fileobj = open(in_file, 'rb')
8283
fileobj.seek(offset)
8384
endianness = native_code
8485
f4dt = np.dtype(endianness + 'f4')
@@ -90,7 +91,7 @@ def points_per_track(offset):
9091
n_points = 0
9192
track_points = []
9293
iflogger.info('Identifying the number of points per tract...')
93-
all_str = fileobj.read()
94+
all_str = fileobj.read().decode()
9495
num_triplets = int(len(all_str) / bytesize)
9596
pts = np.ndarray(shape=(num_triplets, pt_cols), dtype='f4', buffer=all_str)
9697
nonfinite_list = np.where(np.isfinite(pts[:, 2]) == False)

0 commit comments

Comments
 (0)