Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 17, 2021
1 parent 2e3afcc commit 5d66d65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
known_third_party = numpy,ome_zarr,omero,omero_zarr,setuptools,skimage,zarr
known_third_party = dask,numpy,ome_zarr,omero,omero_model_DatasetI,omero_zarr,setuptools,skimage,zarr
3 changes: 2 additions & 1 deletion src/omero_zarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from .raw_pixels import (
add_omero_metadata,
add_toplevel_metadata,
dataset_to_zarr,
image_to_zarr,
plate_to_zarr, dataset_to_zarr,
plate_to_zarr,
)

HELP = """Export data in zarr format.
Expand Down
20 changes: 16 additions & 4 deletions src/omero_zarr/raw_pixels.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import argparse
import os
import time
import dask
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple

import dask
import numpy
import numpy as np
import omero.clients # noqa
Expand All @@ -30,7 +30,10 @@ def _open_store(name: str) -> FSStore:
mode="w",
)

def image_to_zarr(image: omero.gateway.ImageWrapper, target_dir: str, cache_numpy: bool) -> None:

def image_to_zarr(
image: omero.gateway.ImageWrapper, target_dir: str, cache_numpy: bool
) -> None:
cache_dir = target_dir if cache_numpy else None
name = os.path.join(target_dir, "%s.zarr" % image.id)
print(f"Exporting to {name} ({VERSION})")
Expand All @@ -42,25 +45,34 @@ def image_to_zarr(image: omero.gateway.ImageWrapper, target_dir: str, cache_nump
add_toplevel_metadata(root)
print("{name} Finished.")


def image_to_zarr_threadsafe(image_id: int, target_dir: str, cache_numpy: bool) -> None:
with omero.cli.cli_login() as c:
conn = omero.gateway.BlitzGateway(client_obj=c.get_client())
conn.SERVICE_OPTS.setOmeroGroup("-1")
image = conn.getObject("Image", image_id)
image_to_zarr(image, target_dir, cache_numpy)

def dataset_to_zarr(dataset: omero.gateway.DatasetWrapper, args: argparse.Namespace) -> None:

def dataset_to_zarr(
dataset: omero.gateway.DatasetWrapper, args: argparse.Namespace
) -> None:
target_dir = os.path.join(args.output, "%s" % dataset.getId())
os.makedirs(target_dir, exist_ok=True)
jobs = []
for image in dataset.listChildren():
jobs.append(dask.delayed(image_to_zarr_threadsafe)(image.getId(), target_dir, args.cache_numpy))
jobs.append(
dask.delayed(image_to_zarr_threadsafe)(
image.getId(), target_dir, args.cache_numpy
)
)
if args.max_workers:
with dask.config.set(num_workers=int(args.max_workers)):
dask.delayed()(jobs).compute()
else:
dask.delayed()(jobs).compute()


def add_image(
image: omero.gateway.ImageWrapper, parent: Group, cache_dir: Optional[str] = None
) -> Tuple[int, List[str]]:
Expand Down

0 comments on commit 5d66d65

Please sign in to comment.