Skip to content

Commit

Permalink
Merge 28c4576 into ad0b13f
Browse files Browse the repository at this point in the history
  • Loading branch information
reddigari committed Mar 8, 2019
2 parents ad0b13f + 28c4576 commit 46fb3c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
14 changes: 7 additions & 7 deletions nibabel/nicom/dicomreaders.py
Expand Up @@ -146,7 +146,7 @@ def slices_to_series(wrappers):
out_vol_lists = []
for vol_list in volume_lists:
if len(vol_list) > 1:
vol_list.sort(_slice_sorter)
vol_list.sort(key=_slice_sorter)
zs = [s.slice_indicator for s in vol_list]
if len(set(zs)) < len(zs): # not unique zs
# third pass
Expand All @@ -163,12 +163,12 @@ def slices_to_series(wrappers):
return out_vol_lists


def _slice_sorter(s1, s2):
return cmp(s1.slice_indicator, s2.slice_indicator)
def _slice_sorter(s):
return s.slice_indicator


def _instance_sorter(s1, s2):
return cmp(s1.instance_number, s2.instance_number)
def _instance_sorter(s):
return s.instance_number


def _third_pass(wrappers):
Expand All @@ -182,9 +182,9 @@ def _third_pass(wrappers):
'missing InstanceNumber')
if len(set(inos)) < len(inos):
raise DicomReadError(msg_fmt % 'some or all slices with '
'the sane InstanceNumber')
'the same InstanceNumber')
# sort by instance number
wrappers.sort(_instance_sorter)
wrappers.sort(key=_instance_sorter)
# start loop, in which we start a new volume, each time we see a z
# we've seen already in the current volume
dw = wrappers[0]
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions nibabel/nicom/tests/test_dicomreaders.py
Expand Up @@ -2,6 +2,8 @@
"""

from os.path import join as pjoin, abspath

import numpy as np

from .. import dicomreaders as didr
Expand Down Expand Up @@ -68,3 +70,12 @@ def test_passing_kwds():
IO_DATA_PATH,
csa_glob,
dicom_kwargs=dict(force=True))

@dicom_test
def test_slices_to_series():
dicom_files = (pjoin(IO_DATA_PATH, "%d.dcm" % i) for i in range(2))
wrappers = [didr.wrapper_from_file(f) for f in dicom_files]
series = didr.slices_to_series(wrappers)
assert_equal(len(series), 1)
assert_equal(len(series[0]), 2)

0 comments on commit 46fb3c9

Please sign in to comment.