From 243554e814be6158a1b3f397bfe070059f0373d1 Mon Sep 17 00:00:00 2001 From: aeisenbarth <54448967+aeisenbarth@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:26:07 +0100 Subject: [PATCH] Fix `transform_to_data_extent` converting labels to images (#791) * Add test case for issue 783 * Pass parameter return_regions_as_labels=True to rasterize to preserve labels --------- Co-authored-by: Luca Marconato --- src/spatialdata/_core/operations/_utils.py | 1 + tests/core/operations/test_spatialdata_operations.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/spatialdata/_core/operations/_utils.py b/src/spatialdata/_core/operations/_utils.py index 00b65500..23722278 100644 --- a/src/spatialdata/_core/operations/_utils.py +++ b/src/spatialdata/_core/operations/_utils.py @@ -125,6 +125,7 @@ def transform_to_data_extent( target_width=target_width, target_height=None, target_depth=None, + return_regions_as_labels=True, ) sdata_to_return_elements[element_name] = rasterized else: diff --git a/tests/core/operations/test_spatialdata_operations.py b/tests/core/operations/test_spatialdata_operations.py index bf63fc4b..95b567bb 100644 --- a/tests/core/operations/test_spatialdata_operations.py +++ b/tests/core/operations/test_spatialdata_operations.py @@ -17,6 +17,7 @@ PointsModel, ShapesModel, TableModel, + get_model, get_table_keys, ) from spatialdata.testing import assert_elements_dict_are_identical, assert_spatial_data_objects_are_identical @@ -474,6 +475,7 @@ def test_transform_to_data_extent(full_sdata: SpatialData, maintain_positioning: for element in elements: before = full_sdata[element] after = sdata[element] + assert get_model(after) == get_model(before) data_extent_before = get_extent(before, coordinate_system="global") data_extent_after = get_extent(after, coordinate_system="global") # huge tolerance because of the bug with pixel perfectness