From 7600f9b3e9d9329cf1082ee81c62a3a13ac19664 Mon Sep 17 00:00:00 2001 From: algol Date: Mon, 1 Dec 2025 16:47:42 +0000 Subject: [PATCH 1/2] first attempt to fix the issue --- httomo/darks_flats.py | 10 ++++++--- httomo/runner/dataset.py | 2 +- httomo/transform_loader_params.py | 36 +++++++++++++----------------- tests/runner/test_dataset_block.py | 8 +++---- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/httomo/darks_flats.py b/httomo/darks_flats.py index 254d98032..a0997f94b 100644 --- a/httomo/darks_flats.py +++ b/httomo/darks_flats.py @@ -56,7 +56,7 @@ class DarksFlatsFileConfig(NamedTuple): """ file: Path - data_path: str + data_path: Optional[str] image_key_path: Optional[str] ignore: bool = False @@ -145,8 +145,12 @@ def get_separate(config: DarksFlatsFileConfig): ] if darks_config.file != flats_config.file: - darks = get_separate(darks_config) - flats = get_separate(flats_config) + darks = None + flats = None + if not darks_config.ignore: + darks = get_separate(darks_config) + if not flats_config.ignore: + flats = get_separate(flats_config) return darks, flats # type: ignore return get_together_or_dummy() diff --git a/httomo/runner/dataset.py b/httomo/runner/dataset.py index d1cc5ffda..bb55c5525 100644 --- a/httomo/runner/dataset.py +++ b/httomo/runner/dataset.py @@ -171,7 +171,7 @@ def slicing_dim(self) -> Literal[0, 1, 2]: def _empty_aux_array(self): empty_shape = list(self._data.shape) - empty_shape[self.slicing_dim] = 0 + empty_shape[self.slicing_dim] = 1 return np.empty_like(self._data, shape=empty_shape) @property diff --git a/httomo/transform_loader_params.py b/httomo/transform_loader_params.py index e13240317..0f241068b 100644 --- a/httomo/transform_loader_params.py +++ b/httomo/transform_loader_params.py @@ -322,8 +322,8 @@ class DarksFlatsParam(TypedDict): Darks/flats configuration dict. """ - file: str - data_path: str + file: Path + data_path: Optional[str] image_key_path: Optional[str] ignore: bool @@ -425,26 +425,22 @@ def parse_config( data_config = DataConfig(in_file=input_file, data_path=str(data_path)) + darks_value = config.get("darks", None) - ignore_darks = False - if darks_value == "ignore": - ignore_darks = True # ignore darks in the data - darks_value = None - if darks_value is not None and "image_key_path" not in darks_value: - darks_value["image_key_path"] = None - darks_config = parse_darks_flats( - data_config, image_key_path, darks_value, ignore=ignore_darks - ) + if darks_value == "ignore" or darks_value is None: + darks_config = DarksFlatsFileConfig(file=input_file,data_path=None,image_key_path=None, ignore=True) + else: + if "image_key_path" not in darks_value: + darks_value["image_key_path"] = None + darks_config = parse_darks_flats(data_config, image_key_path, darks_value, ignore=False) + flats_value = config.get("flats", None) - ignore_flats = False - if flats_value == "ignore": - ignore_flats = True # ignore flats in the data - flats_value = None - if flats_value is not None and "image_key_path" not in flats_value: - flats_value["image_key_path"] = None - flats_config = parse_darks_flats( - data_config, image_key_path, flats_value, ignore=ignore_flats - ) + if flats_value == "ignore" or flats_value is None: + flats_config = DarksFlatsFileConfig(file=input_file,data_path=None,image_key_path=None, ignore=True) + else: + if "image_key_path" not in flats_value: + flats_value["image_key_path"] = None + flats_config = parse_darks_flats(data_config, image_key_path, flats_value, ignore=False) return ( data_config, diff --git a/tests/runner/test_dataset_block.py b/tests/runner/test_dataset_block.py index 5081fe5c5..9cf71ed67 100644 --- a/tests/runner/test_dataset_block.py +++ b/tests/runner/test_dataset_block.py @@ -33,10 +33,10 @@ def test_full_block_for_global_data(): np.testing.assert_array_equal(data, block.data) np.testing.assert_array_equal(angles, block.angles) np.testing.assert_array_equal(angles, block.angles_radians) - assert block.darks.shape == (0, 10, 10) - assert block.dark.shape == (0, 10, 10) - assert block.flats.shape == (0, 10, 10) - assert block.flat.shape == (0, 10, 10) + assert block.darks.shape == (1, 10, 10) + assert block.dark.shape == (1, 10, 10) + assert block.flats.shape == (1, 10, 10) + assert block.flat.shape == (1, 10, 10) assert block.darks.dtype == data.dtype assert block.flats.dtype == data.dtype assert block.dark.dtype == data.dtype From 39d33a82b545f817b6d599fc2026b8a5cb0c4ccb Mon Sep 17 00:00:00 2001 From: algol Date: Mon, 1 Dec 2025 16:47:51 +0000 Subject: [PATCH 2/2] first attempt to fix the issue --- httomo/transform_loader_params.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/httomo/transform_loader_params.py b/httomo/transform_loader_params.py index 0f241068b..994a9b485 100644 --- a/httomo/transform_loader_params.py +++ b/httomo/transform_loader_params.py @@ -425,22 +425,29 @@ def parse_config( data_config = DataConfig(in_file=input_file, data_path=str(data_path)) - darks_value = config.get("darks", None) if darks_value == "ignore" or darks_value is None: - darks_config = DarksFlatsFileConfig(file=input_file,data_path=None,image_key_path=None, ignore=True) + darks_config = DarksFlatsFileConfig( + file=input_file, data_path=None, image_key_path=None, ignore=True + ) else: if "image_key_path" not in darks_value: - darks_value["image_key_path"] = None - darks_config = parse_darks_flats(data_config, image_key_path, darks_value, ignore=False) + darks_value["image_key_path"] = None + darks_config = parse_darks_flats( + data_config, image_key_path, darks_value, ignore=False + ) flats_value = config.get("flats", None) if flats_value == "ignore" or flats_value is None: - flats_config = DarksFlatsFileConfig(file=input_file,data_path=None,image_key_path=None, ignore=True) + flats_config = DarksFlatsFileConfig( + file=input_file, data_path=None, image_key_path=None, ignore=True + ) else: if "image_key_path" not in flats_value: flats_value["image_key_path"] = None - flats_config = parse_darks_flats(data_config, image_key_path, flats_value, ignore=False) + flats_config = parse_darks_flats( + data_config, image_key_path, flats_value, ignore=False + ) return ( data_config,