Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def _rasterize_if_necessary(
else:
return image

logger.info("Rasterizing image for faster rendering.")
logger.info("Rasterizing image for faster rendering. Rasterization may change the image's value range.")
image = _rasterize_to_bbox(image, bbox, coordinate_system, target_x_dims, target_y_dims)
if hasattr(image.data, "compute"):
# rasterize is lazy; downstream reads the result once per channel (NaN check, compositing,
Expand Down
20 changes: 20 additions & 0 deletions tests/pl/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,26 @@ def fake_rasterize(*args, **kwargs):
)


def test_rasterization_logs_changed_value_range(caplog, monkeypatch):
import logging

from xarray import DataArray

from spatialdata_plot.pl import utils as plut

image = DataArray(np.zeros((120, 120)))
rasterized = DataArray(np.zeros((10, 10)))
monkeypatch.setattr(plut, "_rasterize_to_bbox", lambda *args: rasterized)
extent = {"x": (0, 120), "y": (0, 120)}

with caplog.at_level(logging.INFO, logger=plut.logger.name):
assert plut._rasterize_if_necessary(image, 10, 15, 15, "global", extent) is image
assert not caplog.records
assert plut._rasterize_if_necessary(image, 10, 1, 1, "global", extent) is rasterized

assert "value range" in caplog.text


def _add_shapes_table(sdata: SpatialData, element: str = "blobs_polygons", name: str = "shapes_table") -> SpatialData:
"""Add a table annotating a shapes element so it can be measured."""
gdf = sdata[element]
Expand Down