diff --git a/src/depiction/image/multi_channel_image.py b/src/depiction/image/multi_channel_image.py index 84bd052..e401335 100644 --- a/src/depiction/image/multi_channel_image.py +++ b/src/depiction/image/multi_channel_image.py @@ -9,8 +9,8 @@ from xarray import DataArray from depiction.image.image_channel_stats import ImageChannelStats -from depiction.persistence.image.hdf5_image_format import Hdf5ImageFormat from depiction.image.sparse_representation import SparseRepresentation +from depiction.persistence.image.hdf5_image_format import Hdf5ImageFormat if TYPE_CHECKING: from collections.abc import Sequence @@ -157,8 +157,14 @@ def bg_mask_flat(self) -> DataArray: def dimensions(self) -> tuple[int, int]: """Returns width and height of the image.""" # TODO reconsider this method (adding it now for compatibility) + warnings.warn("dimensions is deprecated, use sizes instead", DeprecationWarning) return self._data.sizes["x"], self._data.sizes["y"] + @property + def sizes(self) -> dict[Literal["y", "x", "c"], int]: + """Size of the image along each dimension""" + return {k: self._data.sizes[k] for k in ["y", "x", "c"]} + @property def channel_names(self) -> list[str]: """Returns the names of the channels.""" diff --git a/tests/unit/image/test_multi_channel_image.py b/tests/unit/image/test_multi_channel_image.py index 31b2d37..a9aefb8 100644 --- a/tests/unit/image/test_multi_channel_image.py +++ b/tests/unit/image/test_multi_channel_image.py @@ -124,6 +124,10 @@ def test_dimensions(mock_image: MultiChannelImage) -> None: assert mock_image.dimensions == (2, 3) +def test_sizes(mock_image: MultiChannelImage) -> None: + assert mock_image.sizes == {"y": 3, "x": 2, "c": 2} + + def test_channel_names_when_set(mock_image: MultiChannelImage) -> None: # TODO there should be some functionality to make it work for on-the-fly generated channel names assert mock_image.channel_names == ["Channel A", "Channel B"]