From 4d700d75d56f9ada51ee88b66d39966c315d89e3 Mon Sep 17 00:00:00 2001 From: Gensollen Date: Thu, 14 Nov 2024 11:07:16 +0100 Subject: [PATCH] [FIX] Fix circular import with `DTIBasedMeasure` enumeration (#1373) * move DTIBasedMeasure to new clinica.utils.dwi module * update tests --- clinica/pipelines/dwi/dti/utils.py | 13 ++----------- clinica/utils/dwi.py | 12 ++++++++++++ clinica/utils/input_files.py | 2 +- test/nonregression/pipelines/dwi/test_pipelines.py | 2 +- test/unittests/utils/test_input_files.py | 2 +- test/unittests/utils/test_utils_inputs.py | 2 +- 6 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 clinica/utils/dwi.py diff --git a/clinica/pipelines/dwi/dti/utils.py b/clinica/pipelines/dwi/dti/utils.py index 293198fce..730fe7da3 100644 --- a/clinica/pipelines/dwi/dti/utils.py +++ b/clinica/pipelines/dwi/dti/utils.py @@ -1,11 +1,11 @@ """This module contains utilities used by the DWIDTI pipeline.""" -from enum import Enum from pathlib import Path from typing import Dict, List, Tuple +from clinica.utils.dwi import DTIBasedMeasure + __all__ = [ - "DTIBasedMeasure", "compute_statistics_on_atlases", "get_caps_filenames", "rename_into_caps", @@ -15,15 +15,6 @@ ] -class DTIBasedMeasure(str, Enum): - """Possible DTI measures.""" - - FRACTIONAL_ANISOTROPY = "FA" - MEAN_DIFFUSIVITY = "MD" - AXIAL_DIFFUSIVITY = "AD" - RADIAL_DIFFUSIVITY = "RD" - - def compute_statistics_on_atlases( registered_map: Path, name_map: str, dwi_preprocessed_file: Path ) -> List[Path]: diff --git a/clinica/utils/dwi.py b/clinica/utils/dwi.py new file mode 100644 index 000000000..6c52802dc --- /dev/null +++ b/clinica/utils/dwi.py @@ -0,0 +1,12 @@ +from enum import Enum + +__all__ = ["DTIBasedMeasure"] + + +class DTIBasedMeasure(str, Enum): + """Possible DTI measures.""" + + FRACTIONAL_ANISOTROPY = "FA" + MEAN_DIFFUSIVITY = "MD" + AXIAL_DIFFUSIVITY = "AD" + RADIAL_DIFFUSIVITY = "RD" diff --git a/clinica/utils/input_files.py b/clinica/utils/input_files.py index d3ed2ba6c..f3d925116 100644 --- a/clinica/utils/input_files.py +++ b/clinica/utils/input_files.py @@ -7,7 +7,7 @@ from collections.abc import Iterable from typing import Optional, Union -from clinica.pipelines.dwi.dti.utils import DTIBasedMeasure +from clinica.utils.dwi import DTIBasedMeasure from clinica.utils.pet import ReconstructionMethod, SUVRReferenceRegion, Tracer # BIDS diff --git a/test/nonregression/pipelines/dwi/test_pipelines.py b/test/nonregression/pipelines/dwi/test_pipelines.py index 36c05ac71..fe576ba58 100644 --- a/test/nonregression/pipelines/dwi/test_pipelines.py +++ b/test/nonregression/pipelines/dwi/test_pipelines.py @@ -31,8 +31,8 @@ def run_dwi_dti( input_dir: Path, output_dir: Path, ref_dir: Path, working_dir: Path ) -> None: from clinica.pipelines.dwi.dti.pipeline import DwiDti - from clinica.pipelines.dwi.dti.utils import DTIBasedMeasure from clinica.utils.bids import BIDSFileName + from clinica.utils.dwi import DTIBasedMeasure caps_dir = output_dir / "caps" diff --git a/test/unittests/utils/test_input_files.py b/test/unittests/utils/test_input_files.py index 3aa989efb..1625ca53e 100644 --- a/test/unittests/utils/test_input_files.py +++ b/test/unittests/utils/test_input_files.py @@ -2,7 +2,7 @@ import pytest -from clinica.pipelines.dwi.dti.utils import DTIBasedMeasure +from clinica.utils.dwi import DTIBasedMeasure from clinica.utils.pet import ReconstructionMethod, Tracer diff --git a/test/unittests/utils/test_utils_inputs.py b/test/unittests/utils/test_utils_inputs.py index 265ca48da..6dbebc647 100644 --- a/test/unittests/utils/test_utils_inputs.py +++ b/test/unittests/utils/test_utils_inputs.py @@ -703,7 +703,7 @@ def test_clinica_file_reader_dwi_dti_error(tmp_path): def test_clinica_file_reader_dwi_dti(tmp_path): - from clinica.pipelines.dwi.dti.utils import DTIBasedMeasure + from clinica.utils.dwi import DTIBasedMeasure from clinica.utils.input_files import dwi_dti from clinica.utils.inputs import clinica_file_reader, clinica_list_of_files_reader