From c2cc450b165363cce8c12b728499b37bbd474b74 Mon Sep 17 00:00:00 2001 From: neuronflow Date: Thu, 15 Feb 2024 14:21:12 +0100 Subject: [PATCH] handle Nones Signed-off-by: neuronflow --- brainles_preprocessing/modality.py | 35 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/brainles_preprocessing/modality.py b/brainles_preprocessing/modality.py index fca3219..2e320ef 100644 --- a/brainles_preprocessing/modality.py +++ b/brainles_preprocessing/modality.py @@ -42,15 +42,23 @@ def __init__( self, modality_name: str, input_path: str, - raw_bet_output_path: str = None, - raw_skull_output_path: str = None, - normalized_bet_output_path: str = None, - normalized_skull_output_path: str = None, + raw_bet_output_path: str | None = None, + raw_skull_output_path: str | None = None, + normalized_bet_output_path: str | None = None, + normalized_skull_output_path: str | None = None, normalizer: Optional[Normalizer] = None, atlas_correction: bool = True, ) -> None: + # basics self.modality_name = modality_name + self.input_path = turbopath(input_path) + self.current = self.input_path + + self.normalizer = normalizer + self.atlas_correction = atlas_correction + + # check that atleast one output is generated if ( raw_bet_output_path is None and normalized_bet_output_path is None @@ -60,26 +68,27 @@ def __init__( raise ValueError( "All output paths are None. At least one output path must be provided." ) - self.raw_bet_output_path = turbopath(raw_bet_output_path) - self.raw_skull_output_path = turbopath(raw_skull_output_path) + + # handle input paths + if raw_bet_output_path is not None: + self.raw_bet_output_path = turbopath(raw_bet_output_path) + + if raw_skull_output_path is not None: + self.raw_skull_output_path = turbopath(raw_skull_output_path) + if normalized_bet_output_path is not None: if normalizer is None: raise ValueError( "A normalizer must be provided if normalized_bet_output_path is not None." ) - self.normalized_bet_output_path = turbopath(normalized_bet_output_path) + self.normalized_bet_output_path = turbopath(normalized_bet_output_path) if normalized_skull_output_path is not None: if normalizer is None: raise ValueError( "A normalizer must be provided if normalized_skull_output_path is not None." ) - self.normalized_skull_output_path = turbopath(normalized_skull_output_path) - - self.normalizer = normalizer - self.atlas_correction = atlas_correction - - self.current = self.input_path + self.normalized_skull_output_path = turbopath(normalized_skull_output_path) @property def bet(self) -> bool: