Skip to content

Commit 15ab87a

Browse files
committed
Merge pull request #125 from matthew-brett/pydicom-0p7-fixes
BF: make compatible with pydicom 0.9.7 Pydicom 0.9.7 returns some fields as Python Decimals, when previously they were floats. This causes a mess when using values in an array, because the array becomes objects rather than floats, and, well, it doesn't go well. Tests pass for me with pydicom 0.9.5 through 0.9.7 with these changes.
2 parents 7460fd7 + 112b90c commit 15ab87a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

nibabel/nicom/dicomwrappers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def image_orient_patient(self):
130130
iop = self.get('ImageOrientationPatient')
131131
if iop is None:
132132
return None
133+
# Values are python Decimals in pydicom 0.9.7
134+
iop = np.array((map(float, iop)))
133135
return np.array(iop).reshape(2,3).T
134136

135137
@one_time
@@ -180,6 +182,9 @@ def voxel_sizes(self):
180182
zs = self.get('SliceThickness')
181183
if zs is None:
182184
zs = 1
185+
# Protect from python decimals in pydicom 0.9.7
186+
zs = float(zs)
187+
pix_space = map(float, pix_space)
183188
return tuple(pix_space + [zs])
184189

185190
@one_time
@@ -198,7 +203,8 @@ def image_position(self):
198203
ipp = self.get('ImagePositionPatient')
199204
if ipp is None:
200205
return None
201-
return np.array(ipp)
206+
# Values are python Decimals in pydicom 0.9.7
207+
return np.array(map(float, ipp))
202208

203209
@one_time
204210
def slice_indicator(self):
@@ -558,13 +564,15 @@ def image_position(self):
558564
img_pos : (3,) array
559565
position in mm of voxel (0,0,0) in Mosaic array
560566
'''
561-
ipp = self.get('ImagePositionPatient')
567+
ipp = super(MosaicWrapper, self).image_position
562568
# mosaic image size
563569
md_rows, md_cols = (self.get('Rows'), self.get('Columns'))
564570
iop = self.image_orient_patient
565571
pix_spacing = self.get('PixelSpacing')
566572
if None in (ipp, md_rows, md_cols, iop, pix_spacing):
567573
return None
574+
# PixelSpacing values are python Decimal in pydicom 0.9.7
575+
pix_spacing = np.array(map(float, pix_spacing))
568576
# size of mosaic array before rearranging to 3D.
569577
md_rc = np.array([md_rows, md_cols])
570578
# size of slice array after reshaping to 3D

0 commit comments

Comments
 (0)