Skip to content

Commit

Permalink
split dwi preproc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Oct 16, 2023
1 parent e1ed37e commit 301a153
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -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 }}
18 changes: 9 additions & 9 deletions .github/workflows/test_pipelines_dwi_preprocessing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: DWI Preprocessing Pipelines Tests
name: DWI Preprocessing Using T1 Pipelines Tests

on:
push:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }}
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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)

0 comments on commit 301a153

Please sign in to comment.