Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Apr 4, 2023
1 parent 20c4941 commit a4ed52b
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions test/nonregression/pipelines/test_run_pipelines_dwi.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def test_prepare_phasediff_fmap(cmdopt, tmp_path):
prepare_phasediff_fmap,
)
from clinica.utils.filemanip import extract_metadata_from_json

base_dir = Path(cmdopt["input"])
base_dir = Path(cmdopt["input"])
input_dir, tmp_dir, ref_dir = configure_paths(
base_dir, tmp_path, "DWIPreparePhasediffFmap"
)
Expand Down Expand Up @@ -175,6 +174,57 @@ def test_prepare_phasediff_fmap(cmdopt, tmp_path):
assert similarity_measure(out_file, ref_file, 0.99)


@pytest.mark.fast
def test_dwi_calibrate_and_register_fmap(cmdopt, tmp_path):
"""Test step 2 of pipeline DWIPreprocessingUsingPhaseDiff."""
from clinica.pipelines.dwi_preprocessing_using_fmap.dwi_preprocessing_using_phasediff_fmap_workflows import (
calibrate_and_register_fmap,
)
from clinica.utils.filemanip import extract_metadata_from_json

base_dir = Path(cmdopt["input"])
input_dir, tmp_dir, ref_dir = configure_paths(
base_dir, tmp_path, "DWICalibrateAndRegisterFmap"
)
(tmp_path / "tmp").mkdir()

[echo_time1, echo_time2] = extract_metadata_from_json(
str(input_dir / "sub-01_ses-M000_phasediff.json"), ["EchoTime1", "EchoTime2"]
)
delta_echo_time = abs(echo_time2 - echo_time1)

wf = calibrate_and_register_fmap()
wf.inputs.inputnode.reference_b0 = str(
input_dir / "sub-01_ses-M000_avg_b0_brain.nii.gz"
)
wf.inputs.inputnode.bias_magnitude_fmap = str(
input_dir / "sub-01_ses-M000_magnitude1.nii.gz"
)
wf.inputs.inputnode.fmap_phasediff = str(
input_dir / "sub-01_ses-M000_phasediff.nii.gz"
)
wf.inputs.inputnode.delta_echo_time = delta_echo_time

wf.run()

for folder, filename in zip(
[
"smooth_calibrated_fmap",
"bet_magnitude_fmap_registered_onto_b0",
"registered_calibrated_fmap",
],
[
"sub-01_ses-M000_phasediff_rads_unwrapped_radsec_fieldmap_demean_maths_flirt_smooth.nii.gz",
"sub-01_ses-M000_magnitude1_corrected_brain_flirt.nii.gz",
"sub-01_ses-M000_phasediff_rads_unwrapped_radsec_fieldmap_demean_maths_flirt.nii.gz",
],
):
out_file = fspath(tmp_path / "tmp" / folder / filename)
ref_file = fspath(ref_dir / folder / filename)

assert similarity_measure(out_file, ref_file, 0.99)


@pytest.mark.slow
def test_dwi_preprocessing_using_phase_diff_field_map(cmdopt, tmp_path):
base_dir = Path(cmdopt["input"])
Expand Down

0 comments on commit a4ed52b

Please sign in to comment.