Skip to content

fix decimal rescale values causing Decimal data frame #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions nibabel/nicom/dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ def is_same_series(self, other):
return True

def _scale_data(self, data):
scale = self.get('RescaleSlope', 1)
offset = self.get('RescaleIntercept', 0)
# depending on pydicom and dicom files, values might need casting from Decimal to float
scale = float(self.get('RescaleSlope', 1))
offset = float(self.get('RescaleIntercept', 0))
# a little optimization. If we are applying either the scale or
# the offset, we need to allow upcasting to float.
if scale != 1:
Expand Down
Binary file added nibabel/nicom/tests/data/decimal_rescale.dcm
Binary file not shown.
8 changes: 8 additions & 0 deletions nibabel/nicom/tests/test_dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DATA = None
DATA_FILE_B0 = pjoin(IO_DATA_PATH, 'siemens_dwi_0.dcm.gz')
DATA_FILE_SLC_NORM = pjoin(IO_DATA_PATH, 'csa_slice_norm.dcm')
DATA_FILE_DEC_RSCL = pjoin(IO_DATA_PATH, 'decimal_rescale.dcm')

# This affine from our converted image was shown to match our image
# spatially with an image from SPM DICOM conversion. We checked the
Expand Down Expand Up @@ -171,3 +172,10 @@ def test_assert_parallel():
dw = didw.wrapper_from_file(DATA_FILE_SLC_NORM)
dw.image_orient_patient = np.c_[[1., 0., 0.], [0., 1., 0.]]
assert_raises(AssertionError, dw.__getattribute__, 'slice_normal')

@dicom_test
def test_decimal_rescale():
#Test that we don't get back a data array with dtpye np.object when our
#rescale slope is a decimal
dw = didw.wrapper_from_file(DATA_FILE_DEC_RSCL)
assert dw.get_data().dtype != np.object