Enhancement: Local SpatialData object with remotely accessed pyramidal OME-ZARR image
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 394
- Forks
- 95
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 7
Description
WSIs can account for > 90% of a Spatial Transcriptomics experiment.
This can limit the number of datasets i can host and open on my laptop or workstation
Describe the solution you'd like
I'd like to leave the WSIs (saved as pyramidal ZARR files) on a S3 bucket or on a distant SSH server, and work with SpatialData "as if" the WSI was local.
Describe alternatives you've considered
I can open a multiscale image in napari, overlay a label layer (with coarser pixels) for an annotation tasks.
Zoom in and out is very smooth.
Below is the code for display the image and 2 screenshots of the usecase.
import numpy as np
import zarr
import dask.array as da
import napari
def open_pyramidal_zarr_img(uri, v, layer_name=None, reorder_axes=False):
store = zarr.open(uri, mode="r")
multiscale_data = [da.from_zarr(store[key]) for key in store.array_keys()]
if reorder_axes:
if reorder_axes == "CYX -> XYC":
multiscale_data = [da.swapaxes(data, 0, -1) for data in multiscale_data]
else:
raise ValueError(f"reorder_axes must be False or 'CYX -> XYC', got {reorder_axes}")
v.add_image(multiscale_data, name=layer_name, rgb=True)
(EDIT: scalebar is wrong, obviously 🙄)
Loading is fast (10-20s). Zooming in is smooth enough in my opinion for typical tasks.
It would be very nice to be able to do the same in the napari-spatialdata context.
What i tried
# open local sdata object
sdata = sd.read_zarr(local_path)
# add distant image
store = zarr.open(distant_uri, "r")
image = Image2DModel.parse(da.from_zarr(store["0"]), dims=('c', 'x', 'y'), c_coords=["r", "g", "b"])
sdata["full_res"] = image
# interactive display
interactive = Interactive(sdata)
It takes > 1 min, probably loading all image (then zooming is fast).
Each time layer visibility is toggled, it takes another minute
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 comparing the provided open_pyramidal_zarr_img example with the attempted Image2DModel.parse and Interactive workflow, including sd.read_zarr and the remote URI handling. Done means a remote pyramidal image can be added to a local SpatialData object without loading the whole image, while visibility changes and zooming remain responsive.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100