From 10bce0a37908b02b15f20c10fe0dbc615db367c7 Mon Sep 17 00:00:00 2001 From: NicolasGensollen Date: Tue, 3 Dec 2024 10:17:01 +0100 Subject: [PATCH] Add test for handling pet images registered on T1w image --- clinica/utils/testing_utils.py | 9 ++++++++ .../pipelines/pet/test_pet_linear_pipeline.py | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/clinica/utils/testing_utils.py b/clinica/utils/testing_utils.py index 03c978285..2da6b0853 100644 --- a/clinica/utils/testing_utils.py +++ b/clinica/utils/testing_utils.py @@ -236,6 +236,15 @@ def _build_pet_linear(directory: Path, sub: str, ses: str, config: dict) -> None tracer = Tracer(config["acq_label"]) suvr = SUVRReferenceRegion(config["suvr_reference_region"]) + if config.get("save_PETinT1w", False): + ( + directory + / "subjects" + / sub + / ses + / "pet_linear" + / f"{sub}_{ses}_trc-{tracer.value}_pet_space-T1w_pet.nii.gz" + ).touch() for filename in ( f"{sub}_{ses}_trc-{tracer.value}_pet_space-MNI152NLin2009cSym_desc-Crop_res-1x1x1_suvr-{suvr.value}_pet.nii.gz", f"{sub}_{ses}_trc-{tracer.value}_pet_space-T1w_rigid.mat", diff --git a/test/unittests/pipelines/pet/test_pet_linear_pipeline.py b/test/unittests/pipelines/pet/test_pet_linear_pipeline.py index 41e85af54..f25bd88a3 100644 --- a/test/unittests/pipelines/pet/test_pet_linear_pipeline.py +++ b/test/unittests/pipelines/pet/test_pet_linear_pipeline.py @@ -88,6 +88,7 @@ def test_pet_linear_get_processed_visits(tmp_path, mocker): ├── ses-M000 │ └── pet_linear │ ├── sub-02_ses-M000_trc-18FFDG_pet_space-MNI152NLin2009cSym_desc-Crop_res-1x1x1_suvr-pons_pet.nii.gz + │ ├── sub-02_ses-M000_trc-18FFDG_pet_space-T1w_pet.nii.gz │ └── sub-02_ses-M000_trc-18FFDG_pet_space-T1w_rigid.mat └── ses-M006 └── pet_linear @@ -116,6 +117,7 @@ def test_pet_linear_get_processed_visits(tmp_path, mocker): "acq_label": Tracer.FDG, "suvr_reference_region": SUVRReferenceRegion.PONS, "uncropped_image": False, + "save_PETinT1w": True, } }, "subjects": { @@ -140,6 +142,26 @@ def test_pet_linear_get_processed_visits(tmp_path, mocker): }, }, ) + # We remove the pet image registered on the T1w image for sub-01 and session M006 + ( + caps + / "subjects" + / "sub-01" + / "ses-M006" + / "pet_linear" + / "sub-01_ses-M006_trc-18FFDG_pet_space-T1w_pet.nii.gz" + ).unlink() + pipeline = PETLinear( + bids_directory=str(bids), + caps_directory=str(caps), + parameters={ + "acq_label": Tracer.FDG, + "suvr_reference_region": SUVRReferenceRegion.PONS, + "uncropped_image": False, + "save_PETinT1w": True, + }, + ) + assert pipeline.get_processed_visits() == [Visit("sub-02", "ses-M000")] pipeline = PETLinear( bids_directory=str(bids), @@ -148,6 +170,7 @@ def test_pet_linear_get_processed_visits(tmp_path, mocker): "acq_label": Tracer.FDG, "suvr_reference_region": SUVRReferenceRegion.PONS, "uncropped_image": False, + "save_PETinT1w": False, }, )