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: ...@@ -77,6 +77,7 @@ class DataSaver:
self.compression = kwargs.get("compression", False) self.compression = kwargs.get("compression", False)
self.basename = kwargs.get("basename", None) self.basename = kwargs.get("basename", None)
self.sliced_dim = kwargs.get("sliced_dim", 0) self.sliced_dim = kwargs.get("sliced_dim", 0)
self.chunk_shape = kwargs.get("chunk_shape", "auto")
def save_tiff(self, path, data): def save_tiff(self, path, data):
"""Save data to a TIFF file to the given path. """Save data to a TIFF file to the given path.
...@@ -267,11 +268,17 @@ class DataSaver: ...@@ -267,11 +268,17 @@ class DataSaver:
Returns: Returns:
zarr.core.Array: The Zarr array saved on disk. 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 # Old version that is using dask
da.to_zarr(data, path, compute=True, overwrite=self.replace, compressor=zarr.Blosc(cname='zstd', clevel=3, shuffle=2))
# 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): def save_PIL(self, path, data):
"""Save data to a PIL file to the given path. """Save data to a PIL file to the given path.
...@@ -396,7 +403,14 @@ class DataSaver: ...@@ -396,7 +403,14 @@ class DataSaver:
def save( 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. """Save data to a specified file path.
...@@ -427,5 +441,6 @@ def save( ...@@ -427,5 +441,6 @@ def save(
compression=compression, compression=compression,
basename=basename, basename=basename,
sliced_dim=sliced_dim, sliced_dim=sliced_dim,
chunk_shape=chunk_shape,
**kwargs, **kwargs,
).save(path, data) ).save(path, data)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment