diff --git a/src/squidpy/experimental/im/_make_tiles.py b/src/squidpy/experimental/im/_make_tiles.py index f706f974..49387284 100644 --- a/src/squidpy/experimental/im/_make_tiles.py +++ b/src/squidpy/experimental/im/_make_tiles.py @@ -228,6 +228,9 @@ def _save_tiles_to_shapes( ) sdata.shapes[shapes_key] = ShapesModel.parse(tile_gdf) + # we know that a) the element exists and b) it has at least an Identity transformation + transformations = get_transformation(sdata.images[image_key], get_all=True) + set_transformation(sdata.shapes[shapes_key], transformations, set_all=True) logger.info(f"Saved tile grid as 'sdata.shapes[\"{shapes_key}\"]'") diff --git a/tests/conftest.py b/tests/conftest.py index a8ac1c1a..1dfe7b0a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,6 +48,7 @@ def pytest_sessionstart(session: pytest.Session) -> None: warnings.simplefilter("ignore", OldFormatWarning) sc.pl.set_rcParams_defaults() + sc.set_figure_params(dpi=40, color_map="viridis") @pytest.fixture(scope="session") diff --git a/tests/experimental/test_make_tiles.py b/tests/experimental/test_make_tiles.py index b089f502..d7072063 100644 --- a/tests/experimental/test_make_tiles.py +++ b/tests/experimental/test_make_tiles.py @@ -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 @@ -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)