Skip to content

Commit 8efb8fd

Browse files
committed
BF: fix parrec2nii scaling=off, test scaling
Scaling=off was broken; test all scalings, fix scaling=off.
1 parent 7a857ce commit 8efb8fd

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

bin/parrec2nii

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def proc_file(infile, opts):
136136
'overwrite it' % outfilename)
137137

138138
# load the PAR header and data
139-
scaling = None if opts.scaling == 'off' else opts.scaling
139+
scaling = 'dv' if opts.scaling == 'off' else opts.scaling
140140
infile = fname_ext_ul_case(infile)
141141
pr_img = pr.load(infile,
142142
permit_truncated=opts.permit_truncated,

nibabel/parrec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def get_data_scaling(self, method="dv"):
929929
slope = 1.0 / scale_slope
930930
intercept = rescale_intercept / (rescale_slope * scale_slope)
931931
else:
932-
raise ValueError("Unknown scling method '%s'." % method)
932+
raise ValueError("Unknown scaling method '%s'." % method)
933933
reorder = self.get_sorted_slice_indices()
934934
slope = slope[reorder]
935935
intercept = intercept[reorder]

nibabel/tests/test_scripts.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from nose.tools import (assert_true, assert_false, assert_not_equal,
2121
assert_equal)
2222

23-
from numpy.testing import assert_almost_equal
23+
from numpy.testing import assert_almost_equal, assert_array_equal
2424

2525
from .scriptrunner import ScriptRunner
2626
from .nibabel_data import needs_nibabel_data
@@ -104,6 +104,24 @@ def test_parrec2nii():
104104
data = img.get_data()
105105
assert_data_similar(data, eg_dict)
106106
assert_almost_equal(img.header.get_zooms(), eg_dict['zooms'])
107+
# Check scaling options
108+
cmd = ['parrec2nii', '--scaling=dv', fname]
109+
# Does not overwrite unless option given
110+
code, stdout, stderr = run_command(cmd, check_code=False)
111+
assert_equal(code, 1)
112+
cmd.append('--overwrite')
113+
run_command(cmd)
114+
img = load(out_froot)
115+
assert_data_similar(img.get_data(), eg_dict)
116+
# fp scaling
117+
run_command(['parrec2nii', '--scaling=fp', '--overwrite', fname])
118+
pr_img = load(fname, scaling='fp')
119+
img = load(out_froot)
120+
assert_true(np.allclose(img.get_data(), pr_img.get_data()))
121+
# no scaling
122+
run_command(['parrec2nii', '--scaling=off', '--overwrite', fname])
123+
img = load(out_froot)
124+
assert_almost_equal(img.get_data(), pr_img.dataobj.get_unscaled())
107125

108126

109127
@script_test

0 commit comments

Comments
 (0)