spatialdata
spatialdata copied to clipboard
Error when applying `spatialdata.transform` to multiscale images (related to scale handling)
Bug description
I recently stumbled upon a bug when trying to aggregate intensities on large multi-scale image elements. The bug occurs actually occurs in spatialdata.transform.
Reproducer
import numpy as np
from spatialdata.models import Image2DModel
from spatialdata import SpatialData, transform
from spatialdata.transformations import Identity, Translation, Scale
test_image = Image2DModel.parse(
np.ones((1, 10, 10)),
dims=('c','y', 'x'),
scale_factors=[2,4],
transformations={
'global': Scale([0.9] * 2, axes=['y', 'x']),
# 'global': Translation([9] * 2, axes=['y', 'x']), # somehow this also fails
}
)
test_image_t = transform(test_image, to_coordinate_system="global")
leads to:
ValueError: Scale factors must be finite.
When does this happen?
The error occurs when the transformed multi-scale image contains a scale that has a dimension with shape 0.
Diagnose and potential fix
spatialdata.transform transforms each of the scales of a multi-scale image and keeps scales that have shape 0 dimensions. Probably having transform keep only scales with non-zero shapes represents a fix to the issue.