Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions src/squidpy/experimental/im/_make_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ def _save_tiles_to_shapes(
)

sdata.shapes[shapes_key] = ShapesModel.parse(tile_gdf)
try:
transformations = get_transformation(sdata.images[image_key], get_all=True)
except (KeyError, ValueError):
transformations = None
if transformations:
set_transformation(sdata.shapes[shapes_key], transformations, set_all=True)
logger.info(f"Saved tile grid as 'sdata.shapes[\"{shapes_key}\"]'")


Expand Down
17 changes: 17 additions & 0 deletions tests/experimental/test_make_tiles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import spatialdata_plot as sdp
from spatialdata.transformations import Identity, get_transformation, set_transformation

import squidpy as sq
from tests.conftest import PlotTester, PlotTesterMeta
Expand Down Expand Up @@ -104,3 +105,19 @@ def test_plot_make_tiles_center_grid_on_tissue(self):
center_grid_on_tissue=True,
preview=True,
)


def test_make_tiles_copies_image_transformations(sdata_hne):
"""Tiles saved from images inherit the image transformations."""
image_key = "hne"
custom_cs = Identity()
set_transformation(sdata_hne.images[image_key], {"custom_cs": custom_cs}, set_all=True)

sq.experimental.im.make_tiles(sdata_hne, image_key=image_key, preview=False)

img_tfs = get_transformation(sdata_hne.images[image_key], get_all=True)
tile_tfs = get_transformation(sdata_hne.shapes[f"{image_key}_tiles"], get_all=True)

assert "custom_cs" in img_tfs and "custom_cs" in tile_tfs
assert isinstance(img_tfs["custom_cs"], Identity)
assert isinstance(tile_tfs["custom_cs"], Identity)