Skip to content

Commit

Permalink
add MultiChannelImage.sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Oct 25, 2024
1 parent d81a850 commit 6307e46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/depiction/image/multi_channel_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/image/test_multi_channel_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 6307e46

Please sign in to comment.