diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 51d3b3b..8883aea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: hooks: - id: validate-cff - repo: https://github.com/codespell-project/codespell - rev: v2.4.0 + rev: v2.4.1 hooks: - id: codespell exclude: | diff --git a/docs/src/_static/coverage-badge.svg b/docs/src/_static/coverage-badge.svg index ad88956..8a9b8bd 100644 --- a/docs/src/_static/coverage-badge.svg +++ b/docs/src/_static/coverage-badge.svg @@ -1 +1 @@ -coverage: 97.33%coverage97.33% \ No newline at end of file +coverage: 59.47%coverage59.47% \ No newline at end of file diff --git a/src/nviz/image.py b/src/nviz/image.py index 8cd8c29..5ec6c3a 100644 --- a/src/nviz/image.py +++ b/src/nviz/image.py @@ -21,6 +21,7 @@ def image_set_to_arrays( label_dir: Optional[str], channel_map: Dict[str, str], ignore: Optional[List[str]] = ["Merge"], + expected_dim: int = 4, ) -> Dict[str, Dict[str, np.ndarray]]: """ Read a set of images as an array of images. @@ -101,7 +102,6 @@ def image_set_to_arrays( key=lambda x: x.name.split("_")[0], ) } - return zstack_arrays @@ -234,6 +234,7 @@ def tiff_to_ometiff( # noqa: PLR0913 channel_map: Dict[str, str], scaling_values: Union[List[int], Tuple[int]], ignore: Optional[List[str]], + expected_dim: int = 4, ) -> str: """ Convert TIFF files to OME-TIFF format. @@ -286,7 +287,10 @@ def tiff_to_ometiff( # noqa: PLR0913 # Collect label data if label_dir: for compartment_name, stack in frame_zstacks["labels"].items(): - labels_data.append(stack) + if stack.ndim != expected_dim and stack.ndim < expected_dim: + labels_data.append(np.expand_dims(stack, axis=0)) + else: + labels_data.append(stack) label_names.append(f"{compartment_name} (labels)") # Stack the images and labels along a new axis for channels diff --git a/tests/test_image.py b/tests/test_image.py index c13e97e..1f9d4a9 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -11,8 +11,14 @@ import tifffile as tiff import zarr -from nviz.image import image_set_to_arrays, tiff_to_ometiff, tiff_to_zarr -from tests.utils import example_data_for_image_tests +from nviz.image import ( + image_set_to_arrays, + tiff_to_ometiff, + tiff_to_zarr, +) +from tests.utils import ( + example_data_for_image_tests, +) @pytest.mark.parametrize(