diff --git a/src/depiction/image/multi_channel_image.py b/src/depiction/image/multi_channel_image.py index e401335..c76f4df 100644 --- a/src/depiction/image/multi_channel_image.py +++ b/src/depiction/image/multi_channel_image.py @@ -153,13 +153,6 @@ def bg_mask_flat(self) -> DataArray: """A boolean mask indicating the background values as `True` and non-background values as `False`.""" return ~self.fg_mask_flat - @property - 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""" diff --git a/src/depiction/tools/simulate/generate_synthetic_imzml.py b/src/depiction/tools/simulate/generate_synthetic_imzml.py index 6b5d332..339c73b 100644 --- a/src/depiction/tools/simulate/generate_synthetic_imzml.py +++ b/src/depiction/tools/simulate/generate_synthetic_imzml.py @@ -1,9 +1,8 @@ -from pathlib import Path - import cyclopts import numpy as np import polars as pl from numpy.typing import NDArray +from pathlib import Path from perlin_noise import PerlinNoise from depiction.image.multi_channel_image import MultiChannelImage @@ -63,11 +62,12 @@ def generate_centroided_spectrum( def write_file(self, labels: MultiChannelImage, target_masses: NDArray[float], output: GenericWriteFile): # input validation - if labels.n_channels != len(target_masses): - msg = f"Number of channels in labels ({labels.n_channels}) does not match the number of target masses ({len(target_masses)})" - raise ValueError(msg) - if labels.dimensions != (self._width, self._height): - msg = f"Dimensions of labels ({labels.dimensions}) do not match the dimensions of the synthetic image ({self._width}, {self._height})" + target_sizes = {"x": self._width, "y": self._height, "c": len(target_masses)} + if labels.sizes != target_sizes: + msg = ( + f"Dimensions of labels {labels.sizes} do not match the dimensions of the synthetic image " + f"{target_sizes}." + ) raise ValueError(msg) # collect the relevant input information @@ -127,8 +127,8 @@ def generate_imzml( panel_df = pl.read_csv(mass_list_file) gen = GenerateSyntheticImzml( - height=label_img.dimensions[1], - width=label_img.dimensions[0], + height=label_img.sizes["y"], + width=label_img.sizes["x"], rng=np.random.default_rng(), mz_min=panel_df["mass"].min(), mz_max=panel_df["mass"].max(), diff --git a/system_tests/calibration/test_pipeline_calibration_only.py b/system_tests/calibration/test_pipeline_calibration_only.py index c4b7067..d387aa7 100644 --- a/system_tests/calibration/test_pipeline_calibration_only.py +++ b/system_tests/calibration/test_pipeline_calibration_only.py @@ -34,6 +34,5 @@ def test_run_pipeline(work_dir: Path): process_chunk(chunk_dir=work_dir) # basic checks of the .ome.tiff image image = OmeTiff.read_image(work_dir / "images_default.ome.tiff", bg_value=0.0) - assert image.n_channels == 118 + assert image.sizes == {"x": 128, "y": 137, "c": 118} assert image.n_nonzero == 10131 - assert image.dimensions == (128, 137) diff --git a/tests/unit/image/test_multi_channel_image.py b/tests/unit/image/test_multi_channel_image.py index a9aefb8..52cdbd4 100644 --- a/tests/unit/image/test_multi_channel_image.py +++ b/tests/unit/image/test_multi_channel_image.py @@ -120,10 +120,6 @@ def test_fg_mask_flat(mock_image_sparse) -> None: xarray.testing.assert_equal(expected_fg_mask_flat, mock_image_sparse.fg_mask_flat) -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} @@ -245,7 +241,7 @@ def test_read_hdf5(mocker: MockerFixture, mock_data: DataArray) -> None: def test_with_channel_names(mock_image: MultiChannelImage) -> None: image = mock_image.with_channel_names(channel_names=["New Channel Name", "B"]) assert image.channel_names == ["New Channel Name", "B"] - assert image.dimensions == mock_image.dimensions + assert image.sizes == mock_image.sizes assert image.n_channels == mock_image.n_channels == 2 np.testing.assert_array_equal(image.data_spatial.values, mock_image.data_spatial.values) diff --git a/tests/unit/image/test_multi_channel_image_concatenation.py b/tests/unit/image/test_multi_channel_image_concatenation.py index 7c39f95..662b546 100644 --- a/tests/unit/image/test_multi_channel_image_concatenation.py +++ b/tests/unit/image/test_multi_channel_image_concatenation.py @@ -80,7 +80,7 @@ def test_get_combined_image_index(concat_image: MultiChannelImageConcatenation) def test_get_single_image(request, concat_image: MultiChannelImageConcatenation, image_index: int, image_fixture: str): expected_image = request.getfixturevalue(image_fixture) result_image = concat_image.get_single_image(index=image_index) - assert result_image.dimensions == expected_image.dimensions + assert result_image.sizes == expected_image.sizes xarray.testing.assert_equal(result_image.coordinates_flat, expected_image.coordinates_flat) xarray.testing.assert_equal(result_image.data_flat, expected_image.data_flat) diff --git a/tests/unit/tools/simulate/test_generate_label_image.py b/tests/unit/tools/simulate/test_generate_label_image.py index 52c0945..b332896 100644 --- a/tests/unit/tools/simulate/test_generate_label_image.py +++ b/tests/unit/tools/simulate/test_generate_label_image.py @@ -60,8 +60,7 @@ def test_render(generate) -> None: generate._image_height = 2 generate._image_width = 2 image = generate.render() - assert image.n_channels == 3 - assert image.dimensions == (2, 2) + assert image.sizes == {"x": 2, "y": 2, "c": 3} assert image.channel_names == ["synthetic_0", "synthetic_1", "synthetic_2"]