scverse / scverse/spatialdata

Error when applying `spatialdata.transform` to multiscale images (related to scale handling)

Open
#947 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
394
Forks
95
Avg merge
4d 3h
Merged PRs (30d)
7

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at spatialdata.transform and reproduce the failure with the provided multiscale Image2DModel example using Scale or Translation. Trace how transformed scales with zero-sized dimensions are retained, then verify that the reproducer completes without the “Scale factors must be finite” error and that valid scales remain available.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.