From c71522509bb26ba4ea28fdb3dbad44f2059e989e Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 16 Jan 2024 09:16:11 -0500 Subject: [PATCH] change tostr -> tobytes for deprecation, add basic test --- heudiconv/heuristics/convertall.py | 2 +- heudiconv/tests/test_dicoms.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/heudiconv/heuristics/convertall.py b/heudiconv/heuristics/convertall.py index 9afede7d..d9ada9f7 100644 --- a/heudiconv/heuristics/convertall.py +++ b/heudiconv/heuristics/convertall.py @@ -26,7 +26,7 @@ def custom_seqinfo(wrapper: dw.Wrapper, series_files: list[str], **kw: Any) -> t # in https://github.com/nipy/heudiconv/pull/333 from nibabel.nicom.dicomwrappers import WrapperError try: - affine = wrapper.affine.tostring() + affine = wrapper.affine.tobytes() except WrapperError: lgr.exception("Errored out while obtaining/converting affine") affine = None diff --git a/heudiconv/tests/test_dicoms.py b/heudiconv/tests/test_dicoms.py index dc03790a..678ff2e2 100644 --- a/heudiconv/tests/test_dicoms.py +++ b/heudiconv/tests/test_dicoms.py @@ -99,6 +99,26 @@ def test_group_dicoms_into_seqinfos() -> None: ] +def test_custom_seqinfo() -> None: + """Tests for custom seqinfo extraction""" + + from heudiconv.heuristics.convertall import custom_seqinfo + + dcmfiles = glob(op.join(TESTS_DATA_PATH, "phantom.dcm")) + + seqinfos = group_dicoms_into_seqinfos( + dcmfiles, + "studyUID", + flatten=True, + custom_seqinfo=custom_seqinfo) + + seqinfo = list(seqinfos.keys())[0] + + assert hasattr(seqinfo, 'custom') + assert isinstance(seqinfo.custom, tuple) + assert len(seqinfo.custom) == 2 + assert seqinfo.custom[1] == dcmfiles[0] + def test_get_datetime_from_dcm_from_acq_date_time() -> None: typical_dcm = dcm.dcmread( op.join(TESTS_DATA_PATH, "phantom.dcm"), stop_before_pixels=True