Skip to content

Commit 414eaa9

Browse files
committed
add data and bids tests
1 parent 09c9115 commit 414eaa9

6 files changed

+70
-3
lines changed

heudiconv/convert.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def update_multiorient_name(
533533
)
534534
return filename
535535
iop = metadata.get("ImageOrientationPatientDICOM")
536-
iop = [round(x) for x in iop]
536+
# iop = [round(x) for x in iop]
537537
cross_prod = [
538538
iop[1] * iop[5] - iop[2] * iop[4],
539539
iop[2] * iop[3] - iop[0] * iop[5],
@@ -1002,8 +1002,6 @@ def save_converted_files(
10021002
except KeyError:
10031003
pass
10041004

1005-
print(iops)
1006-
10071005
is_multiecho = (
10081006
len(set(filter(bool, echo_times))) > 1
10091007
) # Check for varying echo times
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Heuristic demonstrating conversion of the Multi-Echo sequences.
2+
3+
It only cares about converting sequences which have _ME_ in their
4+
series_description and outputs to BIDS.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from typing import Optional
10+
11+
from heudiconv.utils import SeqInfo
12+
13+
14+
def create_key(
15+
template: Optional[str],
16+
outtype: tuple[str, ...] = ("nii.gz",),
17+
annotation_classes: None = None,
18+
) -> tuple[str, tuple[str, ...], None]:
19+
if template is None or not template:
20+
raise ValueError("Template must be a valid format string")
21+
return (template, outtype, annotation_classes)
22+
23+
24+
def infotodict(
25+
seqinfo: list[SeqInfo],
26+
) -> dict[tuple[str, tuple[str, ...], None], list[str]]:
27+
"""Heuristic evaluator for determining which runs belong where
28+
29+
allowed template fields - follow python string module:
30+
31+
item: index within category
32+
subject: participant id
33+
seqitem: run number during scanning
34+
subindex: sub index within group
35+
"""
36+
localizer = create_key("sub-{subject}/anat/sub-{subject}_localizer")
37+
38+
info: dict[tuple[str, tuple[str, ...], None], list[str]] = {
39+
localizer: [],
40+
}
41+
for s in seqinfo:
42+
if "localizer" in s.series_description:
43+
info[localizer].append(s.series_id)
44+
return info

heudiconv/tests/test_bids.py

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

13711371

1372+
@pytest.mark.skipif(not have_datalad, reason="no datalad")
1373+
def test_convert_multiorient(
1374+
tmp_path: Path,
1375+
heuristic: str = "bids_localizer.py",
1376+
subID: str = "loc",
1377+
) -> None:
1378+
"""Unit test for the case of multi-orient localizer data.
1379+
The different orientations should be labeled in `acq` entity.
1380+
"""
1381+
datadir = op.join(TESTS_DATA_PATH, "01-localizer_64ch")
1382+
outdir = tmp_path / "out"
1383+
outdir.mkdir()
1384+
args = gen_heudiconv_args(datadir, str(outdir), subID, heuristic)
1385+
runner(args)
1386+
1387+
# Check that the expected files have been extracted.
1388+
# This also checks that the "echo" entity comes before "part":
1389+
for orient in ["sagittal", "coronal", "axial"]:
1390+
for ext in ["nii.gz", "json"]:
1391+
assert op.exists(
1392+
op.join(outdir, "sub-%s", "anat", "sub-%s_acq-%s_localizer.%s")
1393+
% (subID, subID, orient, ext)
1394+
)
1395+
1396+
13721397
@pytest.mark.skipif(not have_datalad, reason="no datalad")
13731398
def test_ME_mag_phase_conversion(
13741399
monkeypatch: pytest.MonkeyPatch,

0 commit comments

Comments
 (0)