Skip to content

Conversation

@LucaMarconato
Copy link
Member

@LucaMarconato LucaMarconato commented Feb 10, 2026

Closes #1069

This PR (still work-in-progress) aims at implementing a function to generate a pyramidal image given a dask array, by relying on ome-zarr internal APIs and by extending functionalities currently not available via ome_zarr.scale.Scaler. Such a function is also provided by the multiscale-spatial-image package, but as explained in the linked issue we hit a performance roadblock.

ome-zarr-py does not support downscaling of the z dimension, nor downscaling via scale factors specified per dimension (both cases are supported by multiscale-spatial-image); these cases will be covered by this PR. The implementation could also live in ome-zarr-py (CC @will-moore @joshmoore @jo-mueller), I'd be happy if someone later can pick up the code so I can remove it from spatialdata and use it from upstream.

Side technical note:

  • the previous implementation in spatialdata uses xarray_coarsen (from multiscale-spatial-image) for images, (which is fully lazy), and itk_nearest (from multiscale-spatial-image) for labels (which is not lazy and therefore problematic). Since downscaling for images doesn't give problems, we could use the old implementation, but I'm reimplementing it with ome-zarr-py APIs anyway. So far it seems that both implementations lead to identical results when the scale factors are all 2.

@jo-mueller
Copy link

Hi @LucaMarconato ,

PR ome/ome-zarr-py#516 also addresses the issues with the downscaling in z (now built in for all methods) 👍

@LucaMarconato
Copy link
Member Author

That's perfect! Then I'll use that PR instead.

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 97.97980% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.93%. Comparing base (e88c24e) to head (0d4ae59).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata/models/pyramids_utils.py 94.87% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1068      +/-   ##
==========================================
+ Coverage   91.89%   91.93%   +0.04%     
==========================================
  Files          49       51       +2     
  Lines        7598     7664      +66     
==========================================
+ Hits         6982     7046      +64     
- Misses        616      618       +2     
Files with missing lines Coverage Δ
src/spatialdata/_io/io_raster.py 93.84% <100.00%> (-0.10%) ⬇️
src/spatialdata/datasets.py 100.00% <100.00%> (ø)
src/spatialdata/models/chunks_utils.py 100.00% <100.00%> (ø)
src/spatialdata/models/models.py 88.42% <100.00%> (ø)
src/spatialdata/models/pyramids_utils.py 94.87% <94.87%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaMarconato LucaMarconato changed the title wip new lazy to_multiscale() for labels New lazy to_multiscale() for labels Feb 11, 2026
@LucaMarconato LucaMarconato marked this pull request as ready for review February 11, 2026 14:17
@LucaMarconato
Copy link
Member Author

The PR is ready. I'll merge and test it with downstream libraries, as it will provide a significant performance boost that I want to make available soon. Additionally, I've created an issue (#1070) to align the code with the z-support from ome-zarr-py once the corresponding PR is merged (ome/ome-zarr-py#516).

@LucaMarconato
Copy link
Member Author

I actually now also added the per-dimension scaling to the tests. I put some plots here to show it in action. Here the actual numerical values of the pixels differ between resize and coarse (expected). So I relaxed the tests.

image image image image

@LucaMarconato LucaMarconato merged commit d98785d into main Feb 11, 2026
9 checks passed
@LucaMarconato LucaMarconato deleted the fix/lazy-to-multiscale branch February 11, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_multiscale() is not lazy for labels

2 participants