Skip to content

Commit 5e6e42e

Browse files
committed
changes to use chunk- entity when multiple FoV are converted in separate niftis for the same series
1 parent 1a560ff commit 5e6e42e

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

heudiconv/bids.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,12 @@ class BIDSFile:
10881088
"mt",
10891089
"part",
10901090
"recording",
1091+
"chunk",
1092+
"nuc",
1093+
"tracksys",
1094+
"voi",
1095+
"stain",
1096+
"trc",
10911097
]
10921098

10931099
def __init__(

heudiconv/convert.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -525,24 +525,35 @@ def update_uncombined_name(
525525
def update_multiorient_name(
526526
metadata: dict[str, Any],
527527
filename: str,
528+
iops: set,
528529
) -> str:
530+
"""
531+
Insert `_chunk-<num>` entity into filename if data are from a sequence
532+
that outputs multiple FoV (localizer, multi-FoV bold)
533+
534+
Parameters
535+
----------
536+
metadata : dict
537+
Scan metadata dictionary from BIDS sidecar file.
538+
filename : str
539+
Incoming filename
540+
541+
Returns
542+
-------
543+
filename : str
544+
Updated filename with chunk entity added, if appropriate.
545+
"""
529546
bids_file = BIDSFile.parse(filename)
530-
if bids_file["acq"]:
547+
if bids_file["chunk"]:
531548
lgr.warning(
532-
"Not embedding multi-orientation information as `%r` already uses acq- parameter.",
549+
"Not embedding multi-orientation information as `%r` already uses chunk- parameter.",
533550
filename,
534551
)
535552
return filename
536-
iop = metadata.get("ImageOrientationPatientDICOM")
537-
assert isinstance(iop, list)
538-
cross_prod = [
539-
iop[1] * iop[5] - iop[2] * iop[4],
540-
iop[2] * iop[3] - iop[0] * iop[5],
541-
iop[0] * iop[4] - iop[1] * iop[3],
542-
]
543-
cross_prod = [abs(x) for x in cross_prod]
544-
slice_orient = ["sagittal", "coronal", "axial"][cross_prod.index(1)]
545-
bids_file["acq"] = slice_orient
553+
iops = sorted(list(iops))
554+
bids_file["chunk"] = str(
555+
iops.index(str(metadata["ImageOrientationPatientDICOM"])) + 1
556+
)
546557
return str(bids_file)
547558

548559

@@ -1117,7 +1128,7 @@ def rename_files() -> None:
11171128

11181129
if is_multiorient:
11191130
this_prefix_basename = update_multiorient_name(
1120-
bids_meta, this_prefix_basename
1131+
bids_meta, this_prefix_basename, iops
11211132
)
11221133

11231134
# Fallback option:

heudiconv/tests/test_bids.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,12 +1385,12 @@ def test_convert_multiorient(
13851385

13861386
# Check that the expected files have been extracted.
13871387
# This also checks that the "echo" entity comes before "part":
1388-
for orient in ["sagittal", "coronal", "axial"]:
1388+
for orient in [1, 2, 3]:
13891389
for ext in ["nii.gz", "json"]:
1390-
assert op.exists(
1391-
op.join(outdir, "sub-%s", "anat", "sub-%s_acq-%s_localizer.%s")
1392-
% (subID, subID, orient, ext)
1393-
)
1390+
fname = op.join(
1391+
outdir, "sub-%s", "anat", "sub-%s_chunk-%d_localizer.%s"
1392+
) % (subID, subID, orient, ext)
1393+
assert op.exists(fname)
13941394

13951395

13961396
@pytest.mark.skipif(not have_datalad, reason="no datalad")

heudiconv/tests/test_convert.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ def test_update_uncombined_name() -> None:
146146

147147
def test_update_multiorient_name() -> None:
148148
"""Unit testing for heudiconv.convert.update_multiorient_name(), which updates
149-
filenames with the acq field if appropriate.
149+
filenames with the chunk field if appropriate.
150150
"""
151151
# Standard name update
152152
base_fn = "sub-X_ses-Y_task-Z_run-01_bold"
153153
metadata = {"ImageOrientationPatientDICOM": [0, 1, 0, 0, 0, -1]}
154-
out_fn_true = "sub-X_ses-Y_task-Z_acq-sagittal_run-01_bold"
155-
out_fn_test = update_multiorient_name(metadata, base_fn)
154+
out_fn_true = "sub-X_ses-Y_task-Z_run-01_chunk-1_bold"
155+
out_fn_test = update_multiorient_name(
156+
metadata, base_fn, set(["[0, 1, 0, 0, 0, -1]"])
157+
)
156158
assert out_fn_test == out_fn_true
157159

158160

0 commit comments

Comments
 (0)