spatialdata
spatialdata copied to clipboard
`chunks` needs to be passed to `to_multiscale` otherwise it's ignored
Super easy fix.
Problem
The function to_multiscale(), which is called by Image2DModel and Image3DModel when scale_factors is a list, calls this code:
# IPFS and visualization friendly default chunks
if "z" in image.dims:
default_chunks = 64
else:
default_chunks = 256
default_chunks = {d: default_chunks for d in image.dims}
if "t" in image.dims:
default_chunks["t"] = 1
out_chunks = chunks
if out_chunks is None:
out_chunks = default_chunks
This means that if some chunks were already set for the data passed to the model, as in this case
# data = da.ones((3, 32768, 32768), chunks=(1, 4096, 4096))
chunks= (1, 4096, 4096)
data = RNG.random((3, 32768, 32768), chunks=chunks)
xdata = DataArray(data, dims=("c", "y", "x"))
##
im = Image2DModel.parse(
xdata,
scale_factors=[2, 2, 2],
# chunks=chunks
)
They are rechunked, unless we pass chunk explicitly to Image2DModel.parse().
Solution
If the data has already chunks, pass them to to_multiscale(). This needs to be done when the data with a Dask array or an xarray DataArray.