-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
Hey everyone,
When I use a scale transform and write/read my data to a zarr store, the dimensions of the scale transform are changed for the image only. That breaks followup aggregations, as the dimensions between the transforms mismatch.
import spatialdata as sd
from spatialdata.datasets import blobs
from spatialdata.transformations import get_transformation, set_transformation, Scale
sdata = blobs()
scale_transform = Scale([0.1, 0.1], ("x", "y"))
set_transformation(sdata["blobs_image"], transformation=scale_transform, to_coordinate_system="global")
set_transformation(sdata["blobs_labels"], transformation=scale_transform, to_coordinate_system="global")
# Initial aggregation works
_ = sdata.aggregate(values="blobs_image", by="blobs_labels", target_coordinate_system="global")
# Write to zarr and read back (as for example recommended for better performance for visualization)
sdata.write("blobs.zarr")
sdata_zarr = sd.read_zarr("blobs.zarr")
# Aggregate no longer works
try:
_ = sdata_zarr.aggregate(values="blobs_image", by="blobs_labels", target_coordinate_system="global")
except Exception as e:
print(f"Error: {e}")
# Error: operands could not be broadcast together with shapes (2,) (3,)
# This is due to a new first dimension added to the scale transform for the image only, resulting in 3 vs 2 dimensions
transform_image = get_transformation(sdata_zarr["blobs_image"], get_all=True)
print(transform_image)
# {'global': Scale (c, y, x)
# [1. 0.1 0.1]}
transform_labels = get_transformation(sdata_zarr["blobs_labels"], get_all=True)
print(transform_labels)
#{'global': Scale (y, x)
# [0.1 0.1]}Metadata
Metadata
Assignees
Labels
No labels