Skip to content

Commit 1a560ff

Browse files
committed
fix tests, use BIDSFile for renaming
1 parent 0e83074 commit 1a560ff

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

heudiconv/convert.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .bids import (
2121
BIDS_VERSION,
2222
BIDSError,
23+
BIDSFile,
2324
add_participant_record,
2425
populate_bids_templates,
2526
populate_intended_for,
@@ -525,9 +526,11 @@ def update_multiorient_name(
525526
metadata: dict[str, Any],
526527
filename: str,
527528
) -> str:
528-
if "_acq-" in filename:
529+
bids_file = BIDSFile.parse(filename)
530+
if bids_file["acq"]:
529531
lgr.warning(
530-
"Not embedding multi-orientation information as `%r` already uses acq- parameter.", filename
532+
"Not embedding multi-orientation information as `%r` already uses acq- parameter.",
533+
filename,
531534
)
532535
return filename
533536
iop = metadata.get("ImageOrientationPatientDICOM")
@@ -539,14 +542,8 @@ def update_multiorient_name(
539542
]
540543
cross_prod = [abs(x) for x in cross_prod]
541544
slice_orient = ["sagittal", "coronal", "axial"][cross_prod.index(1)]
542-
bids_pairs = filename.split("_")
543-
# acq needs to be inserted right after sub- or ses-
544-
ses_or_sub_idx = sum(
545-
[bids_pair.split("-")[0] in ["sub", "ses"] for bids_pair in bids_pairs]
546-
)
547-
bids_pairs.insert(ses_or_sub_idx, "acq-%s" % slice_orient)
548-
filename = "_".join(bids_pairs)
549-
return filename
545+
bids_file["acq"] = slice_orient
546+
return str(bids_file)
550547

551548

552549
def convert(

heudiconv/tests/test_bids.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,6 @@ def test_BIDSFile() -> None:
13691369
assert my_bids_file["echo"] == "2"
13701370

13711371

1372-
@pytest.mark.skipif(not have_datalad, reason="no datalad")
13731372
def test_convert_multiorient(
13741373
tmp_path: Path,
13751374
heuristic: str = "bids_localizer.py",

heudiconv/tests/test_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_update_multiorient_name() -> None:
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_acq-sagittal_task-Z_run-01_bold"
154+
out_fn_true = "sub-X_ses-Y_task-Z_acq-sagittal_run-01_bold"
155155
out_fn_test = update_multiorient_name(metadata, base_fn)
156156
assert out_fn_test == out_fn_true
157157

0 commit comments

Comments
 (0)