Skip to content
Snippets Groups Projects
Commit b2fa4120 authored by Christian Kento Rasmussen's avatar Christian Kento Rasmussen
Browse files

created function to save to zarr

parent e78615ef
Branches
No related tags found
4 merge requests!102Conv zarr tiff folders,!100Conv zarr nifti,!99Zarr cli,!96Zarr loading and converting
......@@ -24,12 +24,14 @@ Example:
import datetime
import os
import dask.array as da
import h5py
import nibabel as nib
import numpy as np
import PIL
import pydicom
import tifffile
import zarr
from pydicom.dataset import FileDataset, FileMetaDataset
from pydicom.uid import UID
......@@ -235,6 +237,21 @@ class DataSaver:
ds.save_as(path)
def save_to_zarr(self, path, data):
""" Saves a Dask array to a Zarr array on disk.
Args:
path (str): The path to the Zarr array on disk.
data (dask.array): The Dask array to be saved to disk.
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))
def save_PIL(self, path, data):
""" Save data to a PIL file to the given path.
......@@ -330,6 +347,8 @@ class DataSaver:
return self.save_vol(path, data)
elif path.endswith((".dcm",".DCM")):
return self.save_dicom(path, data)
elif path.endswith((".zarr")):
return self.save_to_zarr(path, data)
elif path.endswith((".jpeg",".jpg", ".png")):
return self.save_PIL(path, data)
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment