Skip to content

Commit 17f5fd2

Browse files
authored
Merge pull request #495 from mgxd/enh/ref-dtype
ENH: add option to match source dtype
2 parents d109e99 + 3601046 commit 17f5fd2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

niworkflows/interfaces/bids.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def _none():
3636
DEFAULT_DTYPES = defaultdict(_none, (
3737
("mask", "uint8"),
3838
("dseg", "int16"),
39-
("probseg", "float32"))
39+
("probseg", "float32"),
40+
("boldref", "source"))
4041
)
4142

4243

@@ -252,7 +253,8 @@ class _DerivativesDataSinkInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
252253
in_file = InputMultiObject(File(exists=True), mandatory=True,
253254
desc='the object to be saved')
254255
keep_dtype = traits.Bool(False, usedefault=True, desc='keep datatype suffix')
255-
data_dtype = Str(desc='NumPy datatype to coerce NIfTI data to')
256+
data_dtype = Str(desc='NumPy datatype to coerce NIfTI data to, or `source` to'
257+
'match the input file dtype')
256258
meta_dict = traits.DictStrAny(desc='an input dictionary containing metadata')
257259
source_file = File(exists=False, mandatory=True, desc='the input func file')
258260
space = Str('', usedefault=True, desc='Label for space field')
@@ -521,6 +523,8 @@ def _run_interface(self, runtime):
521523
if self.inputs.check_hdr:
522524
# load updated NIfTI
523525
nii = nb.load(out_file, mmap=False)
526+
if data_dtype == 'source': # match source dtype
527+
data_dtype = nb.load(self.inputs.source_file).get_data_dtype()
524528
data_dtype = np.dtype(data_dtype)
525529
if nii.get_data_dtype() != data_dtype:
526530
nii.set_data_dtype(data_dtype)

0 commit comments

Comments
 (0)