Skip to content

Commit

Permalink
MAINT: Update tests after changes in ds001771's structure
Browse files Browse the repository at this point in the history
The new tests also exercise the problems being addressed in nipreps#197.
  • Loading branch information
oesteban committed May 13, 2021
1 parent 2a045e4 commit 21c0566
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 66 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
datalad install -r https://github.com/nipreps-data/ds001771.git
datalad update -r --merge -d ds001771/
datalad get -r -d ds001771/ ds001771/sub-36/*
datalad get -r -d ds001771/derivatives ds001771/derivatives/openneuro/sub-36/*
- run:
name: Install ds000206
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ jobs:
# ds001771
datalad install -r https://github.com/nipreps-data/ds001771.git
datalad update --merge -d ds001771/
datalad update -r --merge -d ds001771/
datalad get -r -d ds001771/ ds001771/sub-36/*
datalad get -r -d ds001771/derivatives ds001771/derivatives/openneuro/sub-36/*
# ds000054
datalad install -r https://github.com/nipreps-data/ds000054.git
Expand Down
63 changes: 26 additions & 37 deletions sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ def find_estimators(*, layout, subject, fmapless=True, force_fmapless=False):
[FieldmapEstimation(sources=<3 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00000')]
OpenNeuro's dataset with fake :math:`B_0` maps derived from two *PEPOLAR* acquisitions
has a total of 4 possible estimations: the two original *PEPOLAR* acquisitions and the
corresponding two that are just renamed versions of the former:
OpenNeuro's dataset with four *PEPOLAR* EPI files, two runs per phase-encoding direction
(AP, PA):
>>> find_estimators(
... layout=layouts['ds001771'],
... subject="36",
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.MAPPED: 4>, bids_id='auto_00001'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.MAPPED: 4>, bids_id='auto_00002'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00003'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00004')]
[FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00001')]
OpenNeuro's ``ds001600`` is an SDC test-dataset containing many different possibilities
for fieldmap estimation:
Expand All @@ -74,13 +69,13 @@ def find_estimators(*, layout, subject, fmapless=True, force_fmapless=False):
... subject="1",
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00005'),
bids_id='auto_00002'),
FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00006'),
bids_id='auto_00003'),
FieldmapEstimation(sources=<3 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00007'),
bids_id='auto_00004'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00008')]
bids_id='auto_00005')]
We can also pick one (simplified) HCP subject for testing purposes:
Expand All @@ -89,9 +84,9 @@ def find_estimators(*, layout, subject, fmapless=True, force_fmapless=False):
... subject="101006",
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00009'),
bids_id='auto_00006'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00010')]
bids_id='auto_00007')]
Finally, *SDCFlows*' "*dataset A*" contains a BIDS structure with zero-bytes
NIfTI files and some corresponding metadata:
Expand All @@ -101,15 +96,15 @@ def find_estimators(*, layout, subject, fmapless=True, force_fmapless=False):
... subject="01",
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.MAPPED: 4>,
bids_id='auto_00011'),
bids_id='auto_00008'),
FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00012'),
bids_id='auto_00009'),
FieldmapEstimation(sources=<3 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00013'),
bids_id='auto_00010'),
FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00014'),
bids_id='auto_00011'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00015')]
bids_id='auto_00012')]
After cleaning the registry, we can see how the "*fieldmap-less*" estimation
can be forced:
Expand All @@ -134,20 +129,14 @@ def find_estimators(*, layout, subject, fmapless=True, force_fmapless=False):
... subject="36",
... force_fmapless=True,
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.MAPPED: 4>,
[FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00002'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.MAPPED: 4>,
bids_id='auto_00003'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00004'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00005'),
FieldmapEstimation(sources=<7 files>, method=<EstimatorType.ANAT: 5>,
bids_id='auto_00006'),
bids_id='auto_00003'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.ANAT: 5>,
bids_id='auto_00007'),
bids_id='auto_00004'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.ANAT: 5>,
bids_id='auto_00008')]
bids_id='auto_00005')]
Because "*dataset A*" contains very few metadata fields available, "*fieldmap-less*"
heuristics come back empty (BOLD and DWI files are missing
Expand All @@ -159,15 +148,15 @@ def find_estimators(*, layout, subject, fmapless=True, force_fmapless=False):
... force_fmapless=True,
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.MAPPED: 4>,
bids_id='auto_00009'),
bids_id='auto_00006'),
FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00010'),
bids_id='auto_00007'),
FieldmapEstimation(sources=<3 files>, method=<EstimatorType.PHASEDIFF: 3>,
bids_id='auto_00011'),
bids_id='auto_00008'),
FieldmapEstimation(sources=<4 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00012'),
bids_id='auto_00009'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.PEPOLAR: 2>,
bids_id='auto_00013')]
bids_id='auto_00010')]
This function should also correctly investigate multi-session datasets:
Expand All @@ -186,9 +175,9 @@ def find_estimators(*, layout, subject, fmapless=True, force_fmapless=False):
... force_fmapless=False,
... ) # doctest: +ELLIPSIS
[FieldmapEstimation(sources=<2 files>, method=<EstimatorType.ANAT: 5>,
bids_id='auto_00014'),
bids_id='auto_00011'),
FieldmapEstimation(sources=<2 files>, method=<EstimatorType.ANAT: 5>,
bids_id='auto_00015')]
bids_id='auto_00012')]
"""
from .. import fieldmaps as fm
Expand Down
37 changes: 10 additions & 27 deletions sdcflows/workflows/fit/tests/test_pepolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,26 @@

@pytest.mark.skipif(os.getenv("TRAVIS") == "true", reason="this is TravisCI")
@pytest.mark.skipif(os.getenv("GITHUB_ACTIONS") == "true", reason="this is GH Actions")
@pytest.mark.parametrize(
"epi_file",
[
(
"ds001771/sub-36/fmap/sub-36_acq-topup1_dir-01_epi.nii.gz",
"ds001771/sub-36/fmap/sub-36_acq-topup1_dir-02_epi.nii.gz",
),
(
"ds001771/sub-36/fmap/sub-36_acq-topup2_dir-01_epi.nii.gz",
"ds001771/sub-36/fmap/sub-36_acq-topup2_dir-02_epi.nii.gz",
),
(
"HCP101006/sub-101006/fmap/sub-101006_dir-LR_epi.nii.gz",
"HCP101006/sub-101006/fmap/sub-101006_dir-RL_epi.nii.gz",
),
],
)
def test_topup_wf(tmpdir, datadir, workdir, outdir, epi_file):
@pytest.mark.parametrize("ds", ("ds001771", "HCP101006"))
def test_topup_wf(tmpdir, bids_layouts, workdir, outdir, ds):
"""Test preparation workflow."""
epi_path = [datadir / f for f in epi_file]
in_data = [str(f.absolute()) for f in epi_path]

wf = pe.Workflow(
name=f"topup_{epi_path[0].name.replace('.nii.gz', '').replace('-', '_')}"
layout = bids_layouts[ds]
epi_path = sorted(
layout.get(suffix="epi", extension=["nii", "nii.gz"]), key=lambda k: k.path
)
in_data = [f.path for f in epi_path]

wf = pe.Workflow(name=f"topup_{ds}")
topup_wf = init_topup_wf(omp_nthreads=2, debug=True, sloppy=True)
metadata = [
loads(Path(str(f).replace(".nii.gz", ".json")).read_text()) for f in in_data
]
metadata = [layout.get_metadata(f.path) for f in epi_path]

topup_wf.inputs.inputnode.in_data = in_data
topup_wf.inputs.inputnode.metadata = metadata

if outdir:
from ...outputs import init_fmap_derivatives_wf, init_fmap_reports_wf

outdir = outdir / "unittests" / epi_file[0].split("/")[0]
outdir = outdir / "unittests" / f"topup_{ds}"
fmap_derivatives_wf = init_fmap_derivatives_wf(
output_dir=str(outdir),
write_coeff=True,
Expand Down
4 changes: 3 additions & 1 deletion sdcflows/workflows/fit/tests/test_phdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"ds001600/sub-1/fmap/sub-1_acq-v2_phase1.nii.gz",
"ds001600/sub-1/fmap/sub-1_acq-v2_phase2.nii.gz",
),
("ds001771/sub-36/fmap/sub-36_acq-topup1_fieldmap.nii.gz",),
(
"ds001771/derivatives/openneuro/sub-36/fmap/sub-36_acq-topup1_fieldmap.nii.gz",
),
("HCP101006/sub-101006/fmap/sub-101006_phasediff.nii.gz",),
],
)
Expand Down

0 comments on commit 21c0566

Please sign in to comment.