Skip to content

Commit

Permalink
sequence_name from PulseSequenceName on Siemens XA series, need tests…
Browse files Browse the repository at this point in the history
… data to write tests
  • Loading branch information
bpinsard committed Sep 16, 2024
1 parent 3eb5efa commit 9afeae9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion heudiconv/dicoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ def create_seqinfo(
image_type = get_typed_attr(dcminfo, "ImageType", tuple, ())
is_moco = "MOCO" in image_type
series_desc = get_typed_attr(dcminfo, "SeriesDescription", str, "")
protocol_name = get_typed_attr(dcminfo, "ProtocolName", str, "")

if dcminfo.get([0x18, 0x24]):
# GE and Philips
sequence_name = dcminfo[0x18, 0x24].value
elif dcminfo.get([0x19, 0x109C]):
# Siemens
sequence_name = dcminfo[0x19, 0x109C].value
elif dcminfo.get([0x18, 0x9005]):
# Siemens XA
sequence_name = dcminfo[0x18, 0x9005].value
else:
sequence_name = ""

Expand Down Expand Up @@ -133,7 +137,7 @@ def create_seqinfo(
dim4=size[3],
TR=TR,
TE=TE,
protocol_name=dcminfo.ProtocolName,
protocol_name=protocol_name,
is_motion_corrected=is_moco,
is_derived="derived" in [x.lower() for x in image_type],
patient_id=dcminfo.get("PatientID"),
Expand Down
19 changes: 19 additions & 0 deletions heudiconv/tests/test_dicoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from heudiconv.cli.run import main as runner
from heudiconv.convert import nipype_convert
from heudiconv.dicoms import (
create_seqinfo,
dw,
embed_dicom_and_nifti_metadata,
get_datetime_from_dcm,
get_reproducible_int,
Expand Down Expand Up @@ -178,6 +180,23 @@ def test_get_datetime_from_dcm_wo_dt() -> None:
assert get_datetime_from_dcm(XA30_enhanced_dcm) is None


dicom_test_data = [
(dw.wrapper_from_file(d_file), [d_file], op.basename(d_file))
for d_file in glob(op.join(TESTS_DATA_PATH, "*.dcm"))
]


@pytest.mark.parametrize("mw,series_files,series_id", dicom_test_data)
def test_create_seqinfo(
mw: dw.Wrapper,
series_files: list[str],
series_id: str,
) -> None:
seqinfo = create_seqinfo(mw, series_files, series_id)
assert seqinfo.sequence_name != ""
pass


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

Expand Down

0 comments on commit 9afeae9

Please sign in to comment.