Skip to content

Commit 45b9808

Browse files
authored
Merge pull request #649 from effigies/fix/scale_factors
FIX: Set slope and intercept to 1/0 if not otherwise provided
2 parents 5d08d91 + 8c7ef8c commit 45b9808

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

niworkflows/interfaces/bids.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ def _run_interface(self, runtime):
648648
if new_data is None:
649649
set_consumables(new_header, orig_img.dataobj)
650650
new_data = orig_img.dataobj.get_unscaled()
651+
else:
652+
# Without this, we would be writing nans
653+
# This is our punishment for hacking around nibabel defaults
654+
new_header.set_slope_inter(slope=1., inter=0.)
651655
unsafe_write_nifti_header_and_data(
652656
fname=out_file,
653657
header=new_header,

niworkflows/interfaces/tests/test_bids.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@
7474
["anat.nii.gz"],
7575
{"desc": "brain", "suffix": "mask"},
7676
"sub-100185/anat/sub-100185_desc-brain_mask.nii.gz",
77-
"d425f0096b6b6d1252973e48b31d760c0b1bdc11",
77+
"7af86a1f6806a41078e4d2699d680dbe2b9f6ae2",
7878
),
7979
(
8080
T1W_PATH,
8181
["anat.nii.gz"],
8282
{"desc": "brain", "suffix": "mask", "space": "MNI"},
8383
"sub-100185/anat/sub-100185_space-MNI_desc-brain_mask.nii.gz",
84-
"a2a6efa16eb23173d0ee64779de879711bc74643",
84+
"1591f90e0da2a624c972784dda6a01b5572add15",
8585
),
8686
(
8787
T1W_PATH,
@@ -98,8 +98,8 @@
9898
f"sub-100185/anat/sub-100185_desc-{s}_dseg.nii"
9999
for s in ("aseg", "aparcaseg")
100100
],
101-
["a235cdf59f9bf077ba30bf2523a56508e3a5aabb",
102-
"a235cdf59f9bf077ba30bf2523a56508e3a5aabb"],
101+
["5543a788bf3383d7a2fc41f5cff4e0bbb8f5f282",
102+
"5543a788bf3383d7a2fc41f5cff4e0bbb8f5f282"],
103103
),
104104
(
105105
T1W_PATH,
@@ -172,14 +172,14 @@
172172
["dseg.nii"],
173173
{"space": "MNI", "suffix": "dseg", "desc": "aseg"},
174174
"sub-100185/func/sub-100185_task-machinegame_run-1_space-MNI_desc-aseg_dseg.nii",
175-
"6d2cae7f56c246d7934e2e21e7b472ecc63a4257",
175+
"ddadc9be8224eebe0177a65bf87300f275e17e96",
176176
),
177177
(
178178
BOLD_PATH,
179179
["mask.nii"],
180180
{"space": "MNI", "suffix": "mask", "desc": "brain"},
181181
"sub-100185/func/sub-100185_task-machinegame_run-1_space-MNI_desc-brain_mask.nii",
182-
"c365991854931181a1444d6803f5289448e7e266",
182+
"f97a1877508139b42ea9fc476bdba367b001ab00",
183183
),
184184
(
185185
BOLD_PATH,
@@ -308,6 +308,13 @@ def test_DerivativesDataSink_build_path(
308308

309309
for out, exp in zip(output, expectation):
310310
assert Path(out).relative_to(tmp_path) == Path(base) / exp
311+
# Regression - some images were given nan scale factors
312+
if out.endswith(".nii") or out.endswith(".nii.gz"):
313+
img = nb.load(out)
314+
with nb.openers.ImageOpener(out) as fobj:
315+
hdr = img.header.from_fileobj(fobj)
316+
assert not np.isnan(hdr["scl_slope"])
317+
assert not np.isnan(hdr["scl_inter"])
311318
for out, chksum in zip(output, checksum):
312319
assert sha1(Path(out).read_bytes()).hexdigest() == chksum
313320

0 commit comments

Comments
 (0)