Skip to content

Commit a1f63de

Browse files
authored
Merge pull request #547 from cbinyu/fix_echo_order_in_filename
Add test for the dataset that raised #541
2 parents 772feeb + aee3d9b commit a1f63de

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

heudiconv/heuristics/bids_ME.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ def infotodict(seqinfo):
2121
subindex: sub index within group
2222
"""
2323
bold = create_key('sub-{subject}/func/sub-{subject}_task-test_run-{item}_bold')
24+
megre_mag = create_key('sub-{subject}/anat/sub-{subject}_part-mag_MEGRE')
25+
megre_phase = create_key('sub-{subject}/anat/sub-{subject}_part-phase_MEGRE')
2426

25-
info = {bold: []}
27+
info = {bold: [], megre_mag: [], megre_phase: []}
2628
for s in seqinfo:
2729
if '_ME_' in s.series_description:
2830
info[bold].append(s.series_id)
31+
if 'GRE_QSM' in s.series_description:
32+
if s.image_type[2] == 'M':
33+
info[megre_mag].append(s.series_id)
34+
elif s.image_type[2] == 'P':
35+
info[megre_phase].append(s.series_id)
2936
return info

heudiconv/tests/test_bids.py

+39
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@
4343
KeyInfoForForce,
4444
BIDSFile,
4545
)
46+
from heudiconv.cli.run import main as runner
4647

4748
from .utils import (
49+
fetch_data,
50+
gen_heudiconv_args,
4851
TESTS_DATA_PATH,
4952
)
5053

5154
import pytest
5255

56+
have_datalad = True
57+
try:
58+
from datalad.support.exceptions import IncompleteResultsError
59+
except ImportError:
60+
have_datalad = False
61+
62+
5363
def gen_rand_label(label_size, label_seed, seed_stdout=True):
5464
seed(label_seed)
5565
rand_char = ''.join(choice(string.ascii_letters) for _ in range(label_size-1))
@@ -1116,3 +1126,32 @@ def test_BIDSFile():
11161126
# -for an existing entity, you can overwrite it with "set":
11171127
my_bids_file.set('echo', '2')
11181128
assert my_bids_file['echo'] == '2'
1129+
1130+
1131+
@pytest.mark.skipif(not have_datalad, reason="no datalad")
1132+
def test_ME_mag_phase_conversion(tmpdir, subID='MEGRE', heuristic='bids_ME.py'):
1133+
""" Unit test for the case of multi-echo GRE data with
1134+
magnitude and phase.
1135+
The different echoes should be labeled automatically.
1136+
"""
1137+
tmpdir.chdir()
1138+
tmppath = tmpdir.strpath
1139+
try:
1140+
datadir = fetch_data(tmppath, f"dicoms/velasco/{subID}")
1141+
except IncompleteResultsError as exc:
1142+
pytest.skip("Failed to fetch test data: %s" % str(exc))
1143+
1144+
outdir = tmpdir.mkdir('out').strpath
1145+
args = gen_heudiconv_args(datadir, outdir, subID, heuristic)
1146+
runner(args) # run conversion
1147+
1148+
# Check that the expected files have been extracted.
1149+
# This also checks that the "echo" entity comes before "part":
1150+
for part in ['mag', 'phase']:
1151+
for e in range(1,4):
1152+
for ext in ['nii.gz', 'json']:
1153+
assert op.exists(
1154+
op.join(outdir, 'sub-%s', 'anat', 'sub-%s_echo-%s_part-%s_MEGRE.%s')
1155+
% (subID, subID, e, part, ext)
1156+
)
1157+

0 commit comments

Comments
 (0)