Skip to content

Commit 12abb6a

Browse files
committed
Merge pull request #463 from bpinsard/bug/tsnr
fixing TSNR integer data bug
2 parents df7c093 + 39f1014 commit 12abb6a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

nipype/algorithms/misc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,12 @@ def _gen_output_file_name(self, suffix=None):
484484

485485
def _run_interface(self, runtime):
486486
img = nb.load(self.inputs.in_file[0])
487+
header = img.get_header().copy()
487488
vollist = [nb.load(filename) for filename in self.inputs.in_file]
488489
data = np.concatenate([vol.get_data().reshape(vol.get_shape()[:3] + (-1,)) for vol in vollist], axis=3)
490+
if data.dtype.kind == 'i':
491+
header.set_data_dtype(np.float32)
492+
data = data.astype(np.float32)
489493
if isdefined(self.inputs.regress_poly):
490494
timepoints = img.get_shape()[-1]
491495
X = np.ones((timepoints, 1))
@@ -496,16 +500,16 @@ def _run_interface(self, runtime):
496500
np.rollaxis(betas[1:, :, :, :], 0, 3)),
497501
0, 4)
498502
data = data - datahat
499-
img = nb.Nifti1Image(data, img.get_affine(), img.get_header())
503+
img = nb.Nifti1Image(data, img.get_affine(), header)
500504
nb.save(img, self._gen_output_file_name('detrended'))
501505
meanimg = np.mean(data, axis=3)
502506
stddevimg = np.std(data, axis=3)
503507
tsnr = meanimg / stddevimg
504-
img = nb.Nifti1Image(tsnr, img.get_affine(), img.get_header())
508+
img = nb.Nifti1Image(tsnr, img.get_affine(), header)
505509
nb.save(img, self._gen_output_file_name())
506-
img = nb.Nifti1Image(meanimg, img.get_affine(), img.get_header())
510+
img = nb.Nifti1Image(meanimg, img.get_affine(), header)
507511
nb.save(img, self._gen_output_file_name('mean'))
508-
img = nb.Nifti1Image(stddevimg, img.get_affine(), img.get_header())
512+
img = nb.Nifti1Image(stddevimg, img.get_affine(), header)
509513
nb.save(img, self._gen_output_file_name('stddev'))
510514
return runtime
511515

0 commit comments

Comments
 (0)