From f2c2100b48cc62c2911f2eb790e4019e5b22ad6e Mon Sep 17 00:00:00 2001 From: algol Date: Thu, 23 Jul 2026 13:15:48 +0100 Subject: [PATCH] adding input_data shortcut --- docs/source/reference/loaders.rst | 21 ++++++++++++++++++++- httomo/darks_flats.py | 4 ++-- httomo/transform_loader_params.py | 2 ++ tests/test_transform_loader_params.py | 15 +++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/source/reference/loaders.rst b/docs/source/reference/loaders.rst index 3624be48f..6c716c970 100644 --- a/docs/source/reference/loaders.rst +++ b/docs/source/reference/loaders.rst @@ -182,7 +182,26 @@ in the older scan should be ignored. In this instance, we need to provide a para file: path/to/new/file.nxs data_path: /entry1/tomo_entry/data/data image_key_path: /entry1/tomo_entry/instrument/detector/image_key - + +If darks and/or flats are in the same dataset as the input dataset, one can use the :code:`input_data` shortcut for :code:`file` fields. For instance, +in the situation when darks and flats are the part of the same input dataset, but there are no keys: + +.. code-block:: yaml + :emphasize-lines: 7,11 + + + - method: standard_tomo + module_path: httomo.data.hdf.loaders + parameters: + darks: + file: input_data + data_path: /exchange/darks + image_key_path: null + flats: + file: input_data + data_path: /exchange/flats + image_key_path: null + Data without darks/flats ++++++++++++++++++++++++ diff --git a/httomo/darks_flats.py b/httomo/darks_flats.py index 2ba54508f..b8129b510 100644 --- a/httomo/darks_flats.py +++ b/httomo/darks_flats.py @@ -5,7 +5,7 @@ from enum import Enum from pathlib import Path -from typing import NamedTuple, Optional, Tuple +from typing import NamedTuple, Optional, Tuple, Union import h5py import numpy as np @@ -72,7 +72,7 @@ class DarksFlatsFileConfig(NamedTuple): with the other types of data correction or reconstruction avoiding normalisation to d/f. """ - file: Path + file: Union[Path, str] data_path: str image_key_path: Optional[str] diff --git a/httomo/transform_loader_params.py b/httomo/transform_loader_params.py index 8533cc315..671f85b96 100644 --- a/httomo/transform_loader_params.py +++ b/httomo/transform_loader_params.py @@ -348,6 +348,8 @@ def parse_darks_flats( pipeline file, into an internal darks/flats configuration type that loaders can use. """ in_file = config["file"] if config is not None else data_config.in_file + if in_file == "input_data": + in_file = data_config.in_file if isinstance(in_file, str): in_file = Path(in_file) data_path = config["data_path"] if config is not None else data_config.data_path diff --git a/tests/test_transform_loader_params.py b/tests/test_transform_loader_params.py index be4427bb9..fc8a9f19e 100644 --- a/tests/test_transform_loader_params.py +++ b/tests/test_transform_loader_params.py @@ -475,11 +475,26 @@ def test_parse_data(): image_key_path="/path/to/keys/data_two", ), ), + ( + DataConfig(Path("/some/path/to/data.nxs"), "/entry1/tomo_entry/data/data"), + "/path/to/keys/data_one", + { + "file": "input_data", + "data_path": "/exchange/data", + "image_key_path": "/path/to/keys/data_two", + }, + DarksFlatsFileConfig( + file=Path("/some/path/to/data.nxs"), + data_path="/exchange/data", + image_key_path="/path/to/keys/data_two", + ), + ), ], ids=[ "darks/flats-in-input-file", "darks/flats-in-separate-file", "darks/flats-in-separate-file-with-image-key", + "darks/flats-in-same-file-with-different-data-path-shortcut", ], ) def test_parse_darks_flats_(