Skip to content

Commit e6832af

Browse files
committed
Merge pull request #145 from bpinsard/bug/decimalrescale
fix decimal rescale values causing Decimal data frame Error when some versions of pydicom have Decimal instead of float returned from dicom floating point string.
2 parents fe05d0a + b1086b8 commit e6832af

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

nibabel/nicom/dicomwrappers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ def is_same_series(self, other):
353353
return True
354354

355355
def _scale_data(self, data):
356-
scale = self.get('RescaleSlope', 1)
357-
offset = self.get('RescaleIntercept', 0)
356+
# depending on pydicom and dicom files, values might need casting from Decimal to float
357+
scale = float(self.get('RescaleSlope', 1))
358+
offset = float(self.get('RescaleIntercept', 0))
358359
# a little optimization. If we are applying either the scale or
359360
# the offset, we need to allow upcasting to float.
360361
if scale != 1:
26 KB
Binary file not shown.

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
DATA = None
3232
DATA_FILE_B0 = pjoin(IO_DATA_PATH, 'siemens_dwi_0.dcm.gz')
3333
DATA_FILE_SLC_NORM = pjoin(IO_DATA_PATH, 'csa_slice_norm.dcm')
34+
DATA_FILE_DEC_RSCL = pjoin(IO_DATA_PATH, 'decimal_rescale.dcm')
3435

3536
# This affine from our converted image was shown to match our image
3637
# spatially with an image from SPM DICOM conversion. We checked the
@@ -171,3 +172,10 @@ def test_assert_parallel():
171172
dw = didw.wrapper_from_file(DATA_FILE_SLC_NORM)
172173
dw.image_orient_patient = np.c_[[1., 0., 0.], [0., 1., 0.]]
173174
assert_raises(AssertionError, dw.__getattribute__, 'slice_normal')
175+
176+
@dicom_test
177+
def test_decimal_rescale():
178+
#Test that we don't get back a data array with dtpye np.object when our
179+
#rescale slope is a decimal
180+
dw = didw.wrapper_from_file(DATA_FILE_DEC_RSCL)
181+
assert dw.get_data().dtype != np.object

0 commit comments

Comments
 (0)