Skip to content

Commit 55faea8

Browse files
committed
FIX: accommodate Python 3 in DICOM slice sorting
1 parent ad0b13f commit 55faea8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

nibabel/nicom/dicomreaders.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def slices_to_series(wrappers):
146146
out_vol_lists = []
147147
for vol_list in volume_lists:
148148
if len(vol_list) > 1:
149-
vol_list.sort(_slice_sorter)
149+
vol_list.sort(key=_slice_sorter)
150150
zs = [s.slice_indicator for s in vol_list]
151151
if len(set(zs)) < len(zs): # not unique zs
152152
# third pass
@@ -163,12 +163,12 @@ def slices_to_series(wrappers):
163163
return out_vol_lists
164164

165165

166-
def _slice_sorter(s1, s2):
167-
return cmp(s1.slice_indicator, s2.slice_indicator)
166+
def _slice_sorter(s):
167+
return s.slice_indicator
168168

169169

170-
def _instance_sorter(s1, s2):
171-
return cmp(s1.instance_number, s2.instance_number)
170+
def _instance_sorter(s):
171+
return s.instance_number
172172

173173

174174
def _third_pass(wrappers):
@@ -182,9 +182,9 @@ def _third_pass(wrappers):
182182
'missing InstanceNumber')
183183
if len(set(inos)) < len(inos):
184184
raise DicomReadError(msg_fmt % 'some or all slices with '
185-
'the sane InstanceNumber')
185+
'the same InstanceNumber')
186186
# sort by instance number
187-
wrappers.sort(_instance_sorter)
187+
wrappers.sort(key=_instance_sorter)
188188
# start loop, in which we start a new volume, each time we see a z
189189
# we've seen already in the current volume
190190
dw = wrappers[0]

0 commit comments

Comments
 (0)