Skip to content

Commit

Permalink
Add test for the dataset that raised nipy#541
Browse files Browse the repository at this point in the history
  • Loading branch information
pvelasco committed Feb 28, 2022
1 parent 405d0ac commit 2bccb7c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 2 deletions.
9 changes: 8 additions & 1 deletion heudiconv/heuristics/bids_ME.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ def infotodict(seqinfo):
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')

info = {bold: []}
info = {bold: [], megre_mag: [], megre_phase: []}
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)
return info
Binary file added heudiconv/tests/data/MEGRE/mag/00001.dcm
Binary file not shown.
Binary file added heudiconv/tests/data/MEGRE/mag/00017.dcm
Binary file not shown.
Binary file added heudiconv/tests/data/MEGRE/mag/00033.dcm
Binary file not shown.
Binary file added heudiconv/tests/data/MEGRE/phase/00001.dcm
Binary file not shown.
Binary file added heudiconv/tests/data/MEGRE/phase/00017.dcm
Binary file not shown.
Binary file added heudiconv/tests/data/MEGRE/phase/00033.dcm
Binary file not shown.
33 changes: 32 additions & 1 deletion heudiconv/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
maybe_na,
treat_age,
)
from heudiconv.cli.run import main as runner
from .utils import TESTS_DATA_PATH

from os.path import (
join as pjoin,
exists as pexists,
)


def test_maybe_na():
Expand All @@ -23,4 +30,28 @@ def test_treat_age():
assert treat_age('1M') == '0.08'
assert treat_age('12M') == '1'
assert treat_age('0000.1') == '0.1'
assert treat_age(0000.1) == '0.1'
assert treat_age(0000.1) == '0.1'


def test_ME_mag_phase_conversion(tmpdir):
""" Unit test for the case of multi-echo GRE data with
magnitude and phase.
The different echoes should be labeled automatically.
"""
tmppath = tmpdir.strpath
subID = 'MEGRE'
args = (
"-c dcm2niix -o %s -b -f bids_ME --files %s -s %s"
% (tmpdir, pjoin(TESTS_DATA_PATH, subID), subID)
).split(' ')
runner(args)

# Check that the expected files have been extracted.
# This also checks that the "echo" entity comes before "part":
for part in ['mag', 'phase']:
for e in range(1,4):
for ext in ['nii.gz', 'json']:
assert pexists(
pjoin(tmppath, 'sub-%s', 'anat', 'sub-%s_echo-%s_part-%s_MEGRE.%s')
% (subID, subID, e, part, ext)
)

0 comments on commit 2bccb7c

Please sign in to comment.