Skip to content

Commit

Permalink
remove MultiChannelImage.dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Oct 25, 2024
1 parent 7184747 commit 287ecf0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 26 deletions.
7 changes: 0 additions & 7 deletions src/depiction/image/multi_channel_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
18 changes: 9 additions & 9 deletions src/depiction/tools/simulate/generate_synthetic_imzml.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions system_tests/calibration/test_pipeline_calibration_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 1 addition & 5 deletions tests/unit/image/test_multi_channel_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/image/test_multi_channel_image_concatenation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/tools/simulate/test_generate_label_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand Down

0 comments on commit 287ecf0

Please sign in to comment.