From 301a1534fba697a6f82f74e00f17fd1334690ad2 Mon Sep 17 00:00:00 2001 From: NicolasGensollen Date: Mon, 16 Oct 2023 09:58:06 +0200 Subject: [PATCH] split dwi preproc tests --- ...ine_dwi_preprocessing_using_phase_diff.yml | 57 ++++++++++++++++ .../test_pipelines_dwi_preprocessing.yml | 18 ++--- .../test_full_phase_diff_pipeline.py | 61 +++++++++++++++++ .../test_phase_diff_sub_workflows.py} | 56 ---------------- .../using_t1/test_full_t1_pipeline.py | 66 +++++++++++++++++++ .../test_t1_sub_workflows.py} | 60 ++--------------- 6 files changed, 198 insertions(+), 120 deletions(-) create mode 100644 .github/workflows/test_pipeline_dwi_preprocessing_using_phase_diff.yml create mode 100644 test/nonregression/pipelines/dwi/preprocessing/using_phase_diff/test_full_phase_diff_pipeline.py rename test/nonregression/pipelines/dwi/preprocessing/{test_phase_diff.py => using_phase_diff/test_phase_diff_sub_workflows.py} (80%) create mode 100644 test/nonregression/pipelines/dwi/preprocessing/using_t1/test_full_t1_pipeline.py rename test/nonregression/pipelines/dwi/preprocessing/{test_t1.py => using_t1/test_t1_sub_workflows.py} (81%) diff --git a/.github/workflows/test_pipeline_dwi_preprocessing_using_phase_diff.yml b/.github/workflows/test_pipeline_dwi_preprocessing_using_phase_diff.yml new file mode 100644 index 000000000..cc294b637 --- /dev/null +++ b/.github/workflows/test_pipeline_dwi_preprocessing_using_phase_diff.yml @@ -0,0 +1,57 @@ +name: DWI Preprocessing Using Phase Diff Pipelines Tests + +on: + push: + branches: [dev] + pull_request: + branches: [dev] + +permissions: + contents: read + +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + +env: + POETRY_VERSION: '1.6.1' + PYTHON_VERSION: '3.10' + +jobs: + test-pipelines-dwi-preprocessing-using-phase-diff-MacOS: + runs-on: + - self-hosted + - macOS + - aramis + timeout-minutes: 720 + steps: + - uses: actions/checkout@v4 + - uses: snok/install-poetry@v1 + - name: Run tests for dwi preprocessing using phase diff pipeline + run: ./scripts/run_nonregression.sh + env: + TEST: dwi/preprocessing/using_phase_diff + MODALITY: dwi_preprocessing_using_phase_diff + WORKSPACE: ${{ github.workspace }} + + test-pipelines-dwi-preprocessing-using-phase-diff-Linux: + runs-on: + - self-hosted + - Linux + timeout-minutes: 720 + steps: + - uses: actions/checkout@v4 + - uses: snok/install-poetry@v1 + with: + version: ${{ env.POETRY_VERSION }} + virtualenvs-create: false + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: poetry + - name: Run tests for dwi preprocessing using phase diff pipeline + run: ./scripts/run_nonregression.sh + env: + TEST: dwi/preprocessing/using_phase_diff + MODALITY: dwi_preprocessing_using_phase_diff + WORKSPACE: ${{ github.workspace }} diff --git a/.github/workflows/test_pipelines_dwi_preprocessing.yml b/.github/workflows/test_pipelines_dwi_preprocessing.yml index fd4c0d28a..b3eb5199e 100644 --- a/.github/workflows/test_pipelines_dwi_preprocessing.yml +++ b/.github/workflows/test_pipelines_dwi_preprocessing.yml @@ -1,4 +1,4 @@ -name: DWI Preprocessing Pipelines Tests +name: DWI Preprocessing Using T1 Pipelines Tests on: push: @@ -18,7 +18,7 @@ env: PYTHON_VERSION: '3.10' jobs: - test-pipelines-dwi-preprocessing-MacOS: + test-pipelines-dwi-preprocessing-using-t1-MacOS: runs-on: - self-hosted - macOS @@ -27,14 +27,14 @@ jobs: steps: - uses: actions/checkout@v4 - uses: snok/install-poetry@v1 - - name: Run tests for dwi preprocessing pipelines + - name: Run tests for dwi preprocessing using t1 pipeline run: ./scripts/run_nonregression.sh env: - TEST: dwi/preprocessing - MODALITY: dwi_preprocessing + TEST: dwi/preprocessing/using_t1 + MODALITY: dwi_preprocessing_using_t1 WORKSPACE: ${{ github.workspace }} - test-pipelines-dwi-preprocessing-Linux: + test-pipelines-dwi-preprocessing-using-t1-Linux: runs-on: - self-hosted - Linux @@ -49,9 +49,9 @@ jobs: with: python-version: ${{ env.PYTHON_VERSION }} cache: poetry - - name: Run tests for dwi preprocessing pipelines + - name: Run tests for dwi preprocessing using t1 pipeline run: ./scripts/run_nonregression.sh env: - TEST: dwi/preprocessing - MODALITY: dwi_preprocessing + TEST: dwi/preprocessing/using_t1 + MODALITY: dwi_preprocessing_using_t1 WORKSPACE: ${{ github.workspace }} diff --git a/test/nonregression/pipelines/dwi/preprocessing/using_phase_diff/test_full_phase_diff_pipeline.py b/test/nonregression/pipelines/dwi/preprocessing/using_phase_diff/test_full_phase_diff_pipeline.py new file mode 100644 index 000000000..c148df000 --- /dev/null +++ b/test/nonregression/pipelines/dwi/preprocessing/using_phase_diff/test_full_phase_diff_pipeline.py @@ -0,0 +1,61 @@ +from os import fspath +from pathlib import Path +from test.nonregression.testing_tools import configure_paths, similarity_measure + +import pytest + + +@pytest.mark.slow +def test_dwi_preprocessing_using_phase_diff_field_map(cmdopt, tmp_path): + base_dir = Path(cmdopt["input"]) + working_dir = Path(cmdopt["wd"]) + input_dir, tmp_dir, ref_dir = configure_paths( + base_dir, + tmp_path, + "DWIPreprocessingUsingPhaseDiffFieldmap", + ) + run_dwi_preprocessing_using_phase_diff_field_map( + input_dir, tmp_dir, ref_dir, working_dir + ) + + +def run_dwi_preprocessing_using_phase_diff_field_map( + input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path +) -> None: + from clinica.pipelines.dwi_preprocessing_using_fmap.dwi_preprocessing_using_phasediff_fmap_pipeline import ( + DwiPreprocessingUsingPhaseDiffFMap, + ) + + caps_dir = output_dir / "caps" + tsv = input_dir / "subjects.tsv" + + parameters = { + "initrand": True, + "low_bval": 5, + "use_cuda": False, + "delete_cache": True, + } + pipeline = DwiPreprocessingUsingPhaseDiffFMap( + bids_directory=fspath(input_dir / "bids"), + caps_directory=fspath(caps_dir), + tsv_file=fspath(tsv), + base_dir=fspath(working_dir), + parameters=parameters, + ) + pipeline.build() + pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) + + out_file = fspath( + caps_dir + / "subjects" + / "sub-PREVDEMALS0010025PG" + / "ses-M000" + / "dwi" + / "preprocessing" + / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-b0_preproc.nii.gz" + ) + ref_file = fspath( + ref_dir / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-b0_preproc.nii.gz" + ) + + assert similarity_measure(out_file, ref_file, 0.95) diff --git a/test/nonregression/pipelines/dwi/preprocessing/test_phase_diff.py b/test/nonregression/pipelines/dwi/preprocessing/using_phase_diff/test_phase_diff_sub_workflows.py similarity index 80% rename from test/nonregression/pipelines/dwi/preprocessing/test_phase_diff.py rename to test/nonregression/pipelines/dwi/preprocessing/using_phase_diff/test_phase_diff_sub_workflows.py index 395ffc116..e86cc3e24 100644 --- a/test/nonregression/pipelines/dwi/preprocessing/test_phase_diff.py +++ b/test/nonregression/pipelines/dwi/preprocessing/using_phase_diff/test_phase_diff_sub_workflows.py @@ -181,59 +181,3 @@ def test_dwi_calibrate_and_register_fmap(cmdopt, tmp_path): ref_file = fspath(ref_dir / folder / filename) assert similarity_measure(out_file, ref_file, 0.98) - - -@pytest.mark.slow -def test_dwi_preprocessing_using_phase_diff_field_map(cmdopt, tmp_path): - base_dir = Path(cmdopt["input"]) - working_dir = Path(cmdopt["wd"]) - input_dir, tmp_dir, ref_dir = configure_paths( - base_dir, - tmp_path, - "DWIPreprocessingUsingPhaseDiffFieldmap", - ) - run_dwi_preprocessing_using_phase_diff_field_map( - input_dir, tmp_dir, ref_dir, working_dir - ) - - -def run_dwi_preprocessing_using_phase_diff_field_map( - input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path -) -> None: - from clinica.pipelines.dwi_preprocessing_using_fmap.dwi_preprocessing_using_phasediff_fmap_pipeline import ( - DwiPreprocessingUsingPhaseDiffFMap, - ) - - caps_dir = output_dir / "caps" - tsv = input_dir / "subjects.tsv" - - parameters = { - "initrand": True, - "low_bval": 5, - "use_cuda": False, - "delete_cache": True, - } - pipeline = DwiPreprocessingUsingPhaseDiffFMap( - bids_directory=fspath(input_dir / "bids"), - caps_directory=fspath(caps_dir), - tsv_file=fspath(tsv), - base_dir=fspath(working_dir), - parameters=parameters, - ) - pipeline.build() - pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) - - out_file = fspath( - caps_dir - / "subjects" - / "sub-PREVDEMALS0010025PG" - / "ses-M000" - / "dwi" - / "preprocessing" - / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-b0_preproc.nii.gz" - ) - ref_file = fspath( - ref_dir / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-b0_preproc.nii.gz" - ) - - assert similarity_measure(out_file, ref_file, 0.95) diff --git a/test/nonregression/pipelines/dwi/preprocessing/using_t1/test_full_t1_pipeline.py b/test/nonregression/pipelines/dwi/preprocessing/using_t1/test_full_t1_pipeline.py new file mode 100644 index 000000000..67f6166d2 --- /dev/null +++ b/test/nonregression/pipelines/dwi/preprocessing/using_t1/test_full_t1_pipeline.py @@ -0,0 +1,66 @@ +"""Non regression test for the full DWIPreprocessingUsingT1 pipeline.""" + +from os import fspath +from pathlib import Path +from test.nonregression.testing_tools import ( + configure_paths, + similarity_measure_large_nifti, +) + +import pytest + + +@pytest.mark.slow +def test_dwi_preprocessing_using_t1(cmdopt, tmp_path): + base_dir = Path(cmdopt["input"]) + working_dir = Path(cmdopt["wd"]) + input_dir, tmp_dir, ref_dir = configure_paths( + base_dir, tmp_path, "DWIPreprocessingUsingT1" + ) + run_dwi_preprocessing_using_t1(input_dir, tmp_dir, ref_dir, working_dir) + + +def run_dwi_preprocessing_using_t1( + input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path +) -> None: + from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_pipeline import ( + DwiPreprocessingUsingT1, + ) + + caps_dir = output_dir / "caps" + tsv = input_dir / "subjects.tsv" + + parameters = { + "initrand": True, + "low_bval": 5, + "use_cuda": False, + "random_seed": 42, + } + pipeline = DwiPreprocessingUsingT1( + bids_directory=fspath(input_dir / "bids"), + caps_directory=fspath(caps_dir), + tsv_file=fspath(tsv), + base_dir=fspath(working_dir), + parameters=parameters, + ) + pipeline.build() + pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) + + output_folder = ( + caps_dir + / "subjects" + / "sub-PREVDEMALS0010025PG" + / "ses-M000" + / "dwi" + / "preprocessing" + ) + out_preprocessed_image = ( + output_folder / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-T1w_preproc.nii.gz" + ) + ref_preprocessed_image = ( + ref_dir / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-T1w_preproc.nii.gz" + ) + + assert similarity_measure_large_nifti( + out_preprocessed_image, ref_preprocessed_image, 0.99 + ) diff --git a/test/nonregression/pipelines/dwi/preprocessing/test_t1.py b/test/nonregression/pipelines/dwi/preprocessing/using_t1/test_t1_sub_workflows.py similarity index 81% rename from test/nonregression/pipelines/dwi/preprocessing/test_t1.py rename to test/nonregression/pipelines/dwi/preprocessing/using_t1/test_t1_sub_workflows.py index 17c6714a4..1e095b086 100644 --- a/test/nonregression/pipelines/dwi/preprocessing/test_t1.py +++ b/test/nonregression/pipelines/dwi/preprocessing/using_t1/test_t1_sub_workflows.py @@ -1,3 +1,5 @@ +"""Non regression tests for sub-workflows of the DWIPreprocessingUsingT1 pipeline.""" + from os import fspath from pathlib import Path from test.nonregression.testing_tools import ( @@ -230,59 +232,7 @@ def test_dwi_eddy_fsl(cmdopt, tmp_path): tmp_path / "tmp" / "out_rotated_bvecs" / "eddy_corrected.eddy_rotated_bvecs" ) ref_file = fspath(ref_dir / "eddy_corrected.eddy_rotated_bvecs") - out_bvecs = np.loadtxt(out_file) - ref_bvecs = np.loadtxt(ref_file) - - assert_array_almost_equal(out_bvecs, ref_bvecs, decimal=3) - - -@pytest.mark.slow -def test_dwi_preprocessing_using_t1(cmdopt, tmp_path): - base_dir = Path(cmdopt["input"]) - working_dir = Path(cmdopt["wd"]) - input_dir, tmp_dir, ref_dir = configure_paths( - base_dir, tmp_path, "DWIPreprocessingUsingT1" - ) - run_dwi_preprocessing_using_t1(input_dir, tmp_dir, ref_dir, working_dir) - - -def run_dwi_preprocessing_using_t1( - input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path -) -> None: - from clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_pipeline import ( - DwiPreprocessingUsingT1, - ) - - caps_dir = output_dir / "caps" - tsv = input_dir / "subjects.tsv" - - parameters = { - "initrand": True, - "low_bval": 5, - "use_cuda": False, - "random_seed": 42, - } - pipeline = DwiPreprocessingUsingT1( - bids_directory=fspath(input_dir / "bids"), - caps_directory=fspath(caps_dir), - tsv_file=fspath(tsv), - base_dir=fspath(working_dir), - parameters=parameters, - ) - pipeline.build() - pipeline.run(plugin="MultiProc", plugin_args={"n_procs": 4}, bypass_check=True) - - out_file = fspath( - caps_dir - / "subjects" - / "sub-PREVDEMALS0010025PG" - / "ses-M000" - / "dwi" - / "preprocessing" - / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-T1w_preproc.nii.gz" - ) - ref_file = fspath( - ref_dir / "sub-PREVDEMALS0010025PG_ses-M000_dwi_space-T1w_preproc.nii.gz" - ) + out_b_vectors = np.loadtxt(out_file) + ref_b_vectors = np.loadtxt(ref_file) - assert similarity_measure_large_nifti(out_file, ref_file, 0.99) + assert_array_almost_equal(out_b_vectors, ref_b_vectors, decimal=3)