Skip to content

Commit

Permalink
add data and bids tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpinsard committed Sep 25, 2024
1 parent 09c9115 commit 8a22f12
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
4 changes: 1 addition & 3 deletions heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def update_multiorient_name(
)
return filename
iop = metadata.get("ImageOrientationPatientDICOM")
iop = [round(x) for x in iop]
# iop = [round(x) for x in iop]
cross_prod = [
iop[1] * iop[5] - iop[2] * iop[4],
iop[2] * iop[3] - iop[0] * iop[5],
Expand Down Expand Up @@ -1002,8 +1002,6 @@ def save_converted_files(
except KeyError:
pass

print(iops)

is_multiecho = (
len(set(filter(bool, echo_times))) > 1
) # Check for varying echo times
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,12 @@ def infotodict(
seqitem: run number during scanning
subindex: sub index within group
"""
bold = create_key("sub-{subject}/func/sub-{subject}_task-test_run-{item}_bold")
megre_mag = create_key("sub-{subject}/anat/sub-{subject}_part-mag_MEGRE")
megre_phase = create_key("sub-{subject}/anat/sub-{subject}_part-phase_MEGRE")
localizer = create_key("sub-{subject}/anat/sub-{subject}_localizer")

info: dict[tuple[str, tuple[str, ...], None], list[str]] = {
bold: [],
megre_mag: [],
megre_phase: [],
localizer: [],
}
for s in seqinfo:
if "_ME_" in s.series_description:
info[bold].append(s.series_id)
if "GRE_QSM" in s.series_description:
if s.image_type[2] == "M":
info[megre_mag].append(s.series_id)
elif s.image_type[2] == "P":
info[megre_phase].append(s.series_id)
if "localizer" in s.series_description:
info[localizer].append(s.series_id)
return info
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions heudiconv/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,31 @@ def test_BIDSFile() -> None:
assert my_bids_file["echo"] == "2"


@pytest.mark.skipif(not have_datalad, reason="no datalad")
def test_convert_multiorient(
tmp_path: Path,
heuristic: str = "bids_localizer.py",
subID: str = "loc",
) -> None:
"""Unit test for the case of multi-orient localizer data.
The different orientations should be labeled in `acq` entity.
"""
datadir = op.join(TESTS_DATA_PATH, "01-localizer_64ch")
outdir = tmp_path / "out"
outdir.mkdir()
args = gen_heudiconv_args(datadir, str(outdir), subID, heuristic)
runner(args)

# Check that the expected files have been extracted.
# This also checks that the "echo" entity comes before "part":
for orient in ["sagittal", "coronal", "axial"]:
for ext in ["nii.gz", "json"]:
assert op.exists(
op.join(outdir, "sub-%s", "anat", "sub-%s_acq-%s_localizer.%s")
% (subID, subID, orient, ext)
)


@pytest.mark.skipif(not have_datalad, reason="no datalad")
def test_ME_mag_phase_conversion(
monkeypatch: pytest.MonkeyPatch,
Expand Down

0 comments on commit 8a22f12

Please sign in to comment.