Error in aggregate over Image2DModel by Labels2DModel when transform is more complex than translation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 394
- Forks
- 95
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 7
Description
Bug description
I stumbled upon an error when trying to aggregate an Image2DModel by a Labels2DModel in the case one of the two has a transform attached which is more complex than a translation.
Reproducer
import numpy as np
from spatialdata.models import Image2DModel, Labels2DModel
from spatialdata import SpatialData, transform, aggregate
from spatialdata.transformations import Identity, Translation, Scale
sdata = SpatialData()
sdata['image'] = Image2DModel.parse(
np.ones((1, 10, 10)),
dims=('c','y', 'x'),
transformations={
# 'global': Scale([0.9] * 2, axes=['y', 'x']), # doesn't work with aggregate
# 'global': Translation([1] * 2, axes=['y', 'x']), # works with aggregate
'global': Identity(), # works with aggregate
}
)
labels_array = np.zeros((10, 10)).astype('int')
labels_array[5:8, 5:8] = 1 # Create a
sdata['labels'] = Labels2DModel.parse(
labels_array,
dims=('y', 'x'),
transformations={
# 'global': Translation([6] * 2, axes=['y', 'x']),
'global': Identity(),
}
)
sdata.aggregate(
values='image',
by='labels',
target_coordinate_system='global'
)
ValueError: input arrays must have equal shapes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided reproducer for SpatialData.aggregate with Image2DModel and Labels2DModel, comparing Identity, Translation, and Scale transformations. Trace the aggregate path and transformation handling to find why complex transforms produce unequal input shapes; done means the Scale case aggregates successfully without the ValueError while existing Identity and Translation behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100