Skip to content

Avoid removing lowres transformation from visium#61

Merged
LucaMarconato merged 1 commit into
mainfrom
fix/visium-missing-lowres-transformation
May 7, 2026
Merged

Avoid removing lowres transformation from visium#61
LucaMarconato merged 1 commit into
mainfrom
fix/visium-missing-lowres-transformation

Conversation

@LucaMarconato
Copy link
Copy Markdown
Collaborator

Closes #59

Before the fix (with scverse/spatialdata#1118), we would get:

Traceback (most recent call last):
  File "/Users/macbook/embl/projects/basel/spatialdata-sandbox/visium/to_zarr.py", line 57, in <module>
    sdata = sd.concatenate([sdataST8059048, sdataST8059050], concatenate_tables=True)
  File "/Users/macbook/embl/projects/basel/spatialdata/src/spatialdata/_core/concatenate.py", line 208, in concatenate
    sdata = SpatialData(
        images=merged_images,
    ...<4 lines>...
        attrs=attrs,
    )
  File "/Users/macbook/embl/projects/basel/spatialdata/src/spatialdata/_core/spatialdata.py", line 142, in __init__
    with raise_validation_errors(
         ~~~~~~~~~~~~~~~~~~~~~~~^
        title="Cannot construct SpatialData object, input contains invalid elements.\n"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        "For renaming, please see the discussion here https://github.com/scverse/spatialdata/discussions/707 .",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        exc_type=(ValueError, KeyError),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ) as collect_error:
    ^
  File "/Users/macbook/embl/projects/basel/spatialdata/src/spatialdata/_core/validation.py", line 386, in __exit__
    raise ValidationError(
    ...<2 lines>...
    )
spatialdata._core.validation.ValidationError: Cannot construct SpatialData object, input contains invalid elements.
For renaming, please see the discussion here https://github.com/scverse/spatialdata/discussions/707 .
To fix, run `spatialdata.utils.sanitize_table(adata)`.
  images/ST8059048_lowres_image: No transformation found for `<xarray.DataArray 'image' (c: 3, y: 600, x: 591)> Size: 1MB
dask.array<transpose, shape=(3, 600, 591), dtype=uint8, chunksize=(3, 600, 591), chunktype=numpy.ndarray>
Coordinates:
  * c        (c) <U1 12B 'r' 'g' 'b'
  * y        (y) float64 5kB 0.5 1.5 2.5 3.5 4.5 ... 596.5 597.5 598.5 599.5
  * x        (x) float64 5kB 0.5 1.5 2.5 3.5 4.5 ... 587.5 588.5 589.5 590.5
Attributes:
    transform:  {}`. At least one transformation is required for raster elements, e.g. images, labels.
  images/ST8059050_lowres_image: No transformation found for `<xarray.DataArray 'image' (c: 3, y: 600, x: 590)> Size: 1MB
dask.array<transpose, shape=(3, 600, 590), dtype=uint8, chunksize=(3, 600, 590), chunktype=numpy.ndarray>
Coordinates:
  * c        (c) <U1 12B 'r' 'g' 'b'
  * y        (y) float64 5kB 0.5 1.5 2.5 3.5 4.5 ... 596.5 597.5 598.5 599.5
  * x        (x) float64 5kB 0.5 1.5 2.5 3.5 4.5 ... 586.5 587.5 588.5 589.5
Attributes:
    transform:  {}`. At least one transformation is required for raster elements, e.g. images, labels.

Process finished with exit code 1

Now we get

SpatialData object, with associated Zarr store: /Users/macbook/embl/projects/basel/spatialdata-sandbox/visium/data.zarr
├── Images
│     ├── 'ST8059048_hires_image': DataArray[cyx] (3, 2000, 1969)
│     ├── 'ST8059048_lowres_image': DataArray[cyx] (3, 600, 591)
│     ├── 'ST8059050_hires_image': DataArray[cyx] (3, 2000, 1968)
│     └── 'ST8059050_lowres_image': DataArray[cyx] (3, 600, 590)
├── Shapes
│     ├── 'ST8059048': GeoDataFrame shape: (2987, 2) (2D shapes)
│     └── 'ST8059050': GeoDataFrame shape: (3497, 2) (2D shapes)
└── Tables
      └── 'table': AnnData (6484, 31053)
with coordinate systems:
    ▸ 'ST8059048', with elements:
        ST8059048_hires_image (Images), ST8059048 (Shapes)
    ▸ 'ST8059048_downscaled_lowres', with elements:
        ST8059048_lowres_image (Images), ST8059048 (Shapes)
    ▸ 'ST8059050', with elements:
        ST8059050_hires_image (Images), ST8059050 (Shapes)
    ▸ 'ST8059050_downscaled_lowres', with elements:
        ST8059050_lowres_image (Images), ST8059050 (Shapes)

@LucaMarconato LucaMarconato merged commit c8d3e69 into main May 7, 2026
@LucaMarconato LucaMarconato deleted the fix/visium-missing-lowres-transformation branch May 7, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Visium io removes all transformations ?

1 participant