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

Merge branch 'OME_export_from_dask_array' into 'main'

Working for both Dask and Numpy arrays

See merge request !114
parents 46430997 2d3eea14
No related branches found
No related tags found
1 merge request!114Working for both Dask and Numpy arrays
...@@ -6,7 +6,13 @@ import os ...@@ -6,7 +6,13 @@ import os
import numpy as np import numpy as np
import zarr import zarr
from ome_zarr.io import parse_url from ome_zarr.io import parse_url
from ome_zarr.writer import write_image from ome_zarr.writer import (
write_image,
_create_mip,
write_multiscale,
CurrentFormat,
Format,
)
from ome_zarr.reader import Reader from ome_zarr.reader import Reader
from ome_zarr import scale from ome_zarr import scale
import math import math
...@@ -100,14 +106,24 @@ def export_ome_zarr( ...@@ -100,14 +106,24 @@ def export_ome_zarr(
os.mkdir(path) os.mkdir(path)
store = parse_url(path, mode="w").store store = parse_url(path, mode="w").store
root = zarr.group(store=store) root = zarr.group(store=store)
write_image(
image=data, fmt = CurrentFormat()
log.info("Creating a multi-scale pyramid")
mip, axes = _create_mip(image=data, fmt=fmt, scaler=scaler, axes="zyx")
log.info("Writing data to disk")
write_multiscale(
mip,
group=root, group=root,
axes="zyx", fmt=fmt,
storage_options=dict(chunks=(chunk_size, chunk_size, chunk_size)), axes=axes,
scaler=scaler, name=None,
compute=False,
) )
log.info("All done!")
return
def import_ome_zarr(path, scale=0, load=True): def import_ome_zarr(path, scale=0, load=True):
""" """
...@@ -160,7 +176,9 @@ def import_ome_zarr(path, scale=0, load=True): ...@@ -160,7 +176,9 @@ def import_ome_zarr(path, scale=0, load=True):
scale = len(dask_data) - 1 scale = len(dask_data) - 1
if scale >= len(dask_data): if scale >= len(dask_data):
raise ValueError(f"Scale {scale} does not exist in the data. Please choose a scale between 0 and {len(dask_data)-1}.") raise ValueError(
f"Scale {scale} does not exist in the data. Please choose a scale between 0 and {len(dask_data)-1}."
)
log.info(f"\nLoading scale {scale} with shape {dask_data[scale].shape}") log.info(f"\nLoading scale {scale} with shape {dask_data[scale].shape}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment