Skip to content
Snippets Groups Projects
Commit a96611b1 authored by fima's avatar fima :beers:
Browse files

Saving zarr now does not use dask

parent 08915229
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,7 @@ class DataSaver:
self.compression = kwargs.get("compression", False)
self.basename = kwargs.get("basename", None)
self.sliced_dim = kwargs.get("sliced_dim", 0)
self.chunk_shape = kwargs.get("chunk_shape", "auto")
def save_tiff(self, path, data):
"""Save data to a TIFF file to the given path.
......@@ -267,11 +268,17 @@ class DataSaver:
Returns:
zarr.core.Array: The Zarr array saved on disk.
"""
assert isinstance(data, da.Array), 'data must be a dask array'
# forces compute when saving to zarr
da.to_zarr(data, path, compute=True, overwrite=self.replace, compressor=zarr.Blosc(cname='zstd', clevel=3, shuffle=2))
# Old version that is using dask
# assert isinstance(data, da.Array), 'data must be a dask array'
# # forces compute when saving to zarr
# da.to_zarr(data, path, compute=True, overwrite=self.replace, compressor=zarr.Blosc(cname='zstd', clevel=3, shuffle=2))
zarr_array = zarr.open(
path, mode="w", shape=data.shape, chunks=self.chunk_shape, dtype=data.dtype
)
zarr_array[:] = data
def save_PIL(self, path, data):
"""Save data to a PIL file to the given path.
......@@ -396,7 +403,14 @@ class DataSaver:
def save(
path, data, replace=False, compression=False, basename=None, sliced_dim=0, **kwargs
path,
data,
replace=False,
compression=False,
basename=None,
sliced_dim=0,
chunk_shape="auto",
**kwargs,
):
"""Save data to a specified file path.
......@@ -427,5 +441,6 @@ def save(
compression=compression,
basename=basename,
sliced_dim=sliced_dim,
chunk_shape=chunk_shape,
**kwargs,
).save(path, data)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment