Skip to content

Commit 92c49f0

Browse files
authored
Merge pull request #785 from yarikoptic/fix/xa_pulse_seq_name
Refactor create_seqinfo tiny bit to avoid duplication and add logging; and in tests to reuse list of dicom paths
2 parents 383525d + 7c24da0 commit 92c49f0

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

heudiconv/dicoms.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ def create_seqinfo(
9494
series_desc = get_typed_attr(dcminfo, "SeriesDescription", str, "")
9595
protocol_name = get_typed_attr(dcminfo, "ProtocolName", str, "")
9696

97-
if dcminfo.get([0x18, 0x24]):
98-
# GE and Philips
99-
sequence_name = dcminfo[0x18, 0x24].value
100-
elif dcminfo.get([0x19, 0x109C]):
101-
# Siemens
102-
sequence_name = dcminfo[0x19, 0x109C].value
103-
elif dcminfo.get([0x18, 0x9005]):
104-
# Siemens XA
105-
sequence_name = dcminfo[0x18, 0x9005].value
97+
for k, m in (
98+
([0x18, 0x24], "GE and Philips"),
99+
([0x19, 0x109C], "Siemens"),
100+
([0x18, 0x9005], "Siemens XA"),
101+
):
102+
if v := dcminfo.get(k):
103+
sequence_name = v.value
104+
lgr.debug(
105+
"Identified sequence name as %s coming from the %r family of MR scanners",
106+
sequence_name,
107+
m,
108+
)
109+
break
106110
else:
107111
sequence_name = ""
108112

heudiconv/tests/test_dicoms.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
parse_private_csa_header,
2222
)
2323

24-
from .utils import TESTS_DATA_PATH
24+
from .utils import TEST_DICOM_PATHS, TESTS_DATA_PATH
2525

2626
# Public: Private DICOM tags
2727
DICOM_FIELDS_TO_TEST = {"ProtocolName": "tProtocolName"}
@@ -180,26 +180,17 @@ def test_get_datetime_from_dcm_wo_dt() -> None:
180180
assert get_datetime_from_dcm(XA30_enhanced_dcm) is None
181181

182182

183-
dicom_test_data = [
184-
(dw.wrapper_from_file(d_file), [d_file], op.basename(d_file))
185-
for d_file in glob(op.join(TESTS_DATA_PATH, "*.dcm"))
186-
]
187-
188-
189-
@pytest.mark.parametrize("mw,series_files,series_id", dicom_test_data)
183+
@pytest.mark.parametrize("dcmfile", TEST_DICOM_PATHS)
190184
def test_create_seqinfo(
191-
mw: dw.Wrapper,
192-
series_files: list[str],
193-
series_id: str,
185+
dcmfile: str,
194186
) -> None:
195-
seqinfo = create_seqinfo(mw, series_files, series_id)
196-
assert seqinfo.sequence_name != ""
197-
pass
198-
187+
mw = dw.wrapper_from_file(dcmfile)
188+
seqinfo = create_seqinfo(mw, [dcmfile], op.basename(dcmfile))
189+
assert seqinfo.sequence_name
199190

200-
def test_get_reproducible_int() -> None:
201-
dcmfile = op.join(TESTS_DATA_PATH, "phantom.dcm")
202191

192+
@pytest.mark.parametrize("dcmfile", TEST_DICOM_PATHS)
193+
def test_get_reproducible_int(dcmfile: str) -> None:
203194
assert type(get_reproducible_int([dcmfile])) is int
204195

205196

heudiconv/tests/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from glob import glob
34
import logging
45
import os.path as op
56
from pathlib import Path
@@ -9,6 +10,14 @@
910

1011
HEURISTICS_PATH = op.join(heudiconv.heuristics.__path__[0])
1112
TESTS_DATA_PATH = op.join(op.dirname(__file__), "data")
13+
# Do relative to curdir to shorten in a typical application,
14+
# and side-effect test that tests do not change curdir.
15+
TEST_DICOM_PATHS = [
16+
op.relpath(x)
17+
for x in glob(op.join(TESTS_DATA_PATH, "**/*.dcm"), recursive=True)
18+
# exclude PhoenixDocuments
19+
if "PhoenixDocument" not in x
20+
]
1221

1322
lgr = logging.getLogger(__name__)
1423

0 commit comments

Comments
 (0)