Skip to content

Commit fb5d070

Browse files
josephmjeoesteban
andcommitted
Apply @oesteban's suggestions
Co-Authored-By: Oscar Esteban <[email protected]>
1 parent 098004e commit fb5d070

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

dmriprep/utils/images.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def extract_b0(in_file, b0_ixs, out_path=None):
1717
hdr = img.header.copy()
1818
hdr.set_data_shape(b0.shape)
1919
hdr.set_xyzt_units('mm')
20-
hdr.set_data_dtype(np.float32)
21-
nb.Nifti1Image(b0, img.affine, hdr).to_filename(out_path)
20+
nb.Nifti1Image(b0.astype(hdr.get_data_dtype()), img.affine, hdr).to_filename(out_path)
2221
return out_path
2322

2423

@@ -32,14 +31,14 @@ def rescale_b0(in_file, mask_file, out_path=None):
3231
if img.dataobj.ndim == 3:
3332
return in_file
3433

35-
data = img.get_fdata(dtype='float32')
34+
data = img.get_fdata()
3635
mask_img = nb.load(mask_file)
37-
mask_data = mask_img.get_fdata(dtype='float32')
36+
mask_data = mask_img.get_fdata()
3837

3938
median_signal = np.median(data[mask_data > 0, ...], axis=0)
4039
rescaled_data = 1000 * data / median_signal
4140
hdr = img.header.copy()
42-
nb.Nifti1Image(rescaled_data, img.affine, hdr).to_filename(out_path)
41+
nb.Nifti1Image(rescaled_data.astype(hdr.get_data_dtype()), img.affine, hdr).to_filename(out_path)
4342
return out_path
4443

4544

@@ -63,5 +62,7 @@ def median(in_file, dtype=None, out_path=None):
6362
hdr.set_xyzt_units('mm')
6463
if dtype is not None:
6564
hdr.set_data_dtype(dtype)
66-
nb.Nifti1Image(median_data, img.affine, hdr).to_filename(out_path)
65+
else:
66+
dtype = hdr.get_data_dtype()
67+
nb.Nifti1Image(median_data.astype(dtype), img.affine, hdr).to_filename(out_path)
6768
return out_path

0 commit comments

Comments
 (0)