diff --git a/nibabel/nicom/dicomreaders.py b/nibabel/nicom/dicomreaders.py index 4c06d10db8..d18a43af96 100644 --- a/nibabel/nicom/dicomreaders.py +++ b/nibabel/nicom/dicomreaders.py @@ -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 @@ -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): @@ -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] diff --git a/nibabel/tests/data/0.dcm b/nibabel/nicom/tests/data/0.dcm similarity index 100% rename from nibabel/tests/data/0.dcm rename to nibabel/nicom/tests/data/0.dcm diff --git a/nibabel/tests/data/1.dcm b/nibabel/nicom/tests/data/1.dcm similarity index 100% rename from nibabel/tests/data/1.dcm rename to nibabel/nicom/tests/data/1.dcm diff --git a/nibabel/nicom/tests/test_dicomreaders.py b/nibabel/nicom/tests/test_dicomreaders.py index 8e09c07b47..cb03aae74b 100644 --- a/nibabel/nicom/tests/test_dicomreaders.py +++ b/nibabel/nicom/tests/test_dicomreaders.py @@ -2,6 +2,8 @@ """ +from os.path import join as pjoin, abspath + import numpy as np from .. import dicomreaders as didr @@ -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) +