diff --git a/.github/workflows/omero_plugin.yml b/.github/workflows/omero_plugin.yml new file mode 100644 index 0000000..df64496 --- /dev/null +++ b/.github/workflows/omero_plugin.yml @@ -0,0 +1,34 @@ +# Install and test and OMERO plugin e.g. a Web app, a CLI plugin or a library +# +# This workflow will install omero-test-infra, start an OMERO environment +# including database, server and web deployment, configure the OMERO plugin +# and run integration tests. +# +# 1. Set up the stage variable depending on the plugin. Supported stages +# are: app, cli, scripts, lib, srv +# +# 2. Adjust the cron schedule as necessary + +name: OMERO +on: + push: + pull_request: + schedule: + - cron: '0 0 * * 0' + +jobs: + test: + name: Run integration tests against OMERO + runs-on: ubuntu-latest + env: + STAGE: cli + steps: + - uses: actions/checkout@v2 + - name: Checkout omero-test-infra + uses: actions/checkout@master + with: + repository: ome/omero-test-infra + path: .omero + ref: ${{ secrets.OMERO_TEST_INFRA_REF }} + - name: Build and run OMERO tests + run: .omero/docker $STAGE diff --git a/.omeroci/env b/.omeroci/env new file mode 100644 index 0000000..f56d437 --- /dev/null +++ b/.omeroci/env @@ -0,0 +1 @@ +PLUGIN=zarr diff --git a/src/omero_zarr/cli.py b/src/omero_zarr/cli.py index e941c3b..5618ba0 100644 --- a/src/omero_zarr/cli.py +++ b/src/omero_zarr/cli.py @@ -262,7 +262,9 @@ def export(self, args: argparse.Namespace) -> None: if args.bf: self._bf_export(image, args) else: - image_to_zarr(image, args) + target_dir = args.output + cache_dir = target_dir if args.cache_numpy else None + image_to_zarr(image, target_dir, cache_dir) elif isinstance(args.object, PlateI): plate = self._lookup(self.gateway, "Plate", args.object.id) plate_to_zarr(plate, args) diff --git a/src/omero_zarr/raw_pixels.py b/src/omero_zarr/raw_pixels.py index 43de8d4..27a5653 100644 --- a/src/omero_zarr/raw_pixels.py +++ b/src/omero_zarr/raw_pixels.py @@ -16,9 +16,9 @@ from .util import open_store, print_status -def image_to_zarr(image: omero.gateway.ImageWrapper, args: argparse.Namespace) -> None: - target_dir = args.output - cache_dir = target_dir if args.cache_numpy else None +def image_to_zarr( + image: omero.gateway.ImageWrapper, target_dir: str, cache_dir: str = None +) -> None: name = os.path.join(target_dir, "%s.zarr" % image.id) print(f"Exporting to {name} ({VERSION})") diff --git a/test/test_export.py b/test/test_export.py new file mode 100644 index 0000000..70b9536 --- /dev/null +++ b/test/test_export.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +# +# Copyright (C) 2022 University of Dundee. All Rights Reserved. +# Use is subject to license terms supplied in LICENSE.txt +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +""" + Test of the omero zarr export plugin. +""" + +from pathlib import Path + +from ome_zarr.io import parse_url +from ome_zarr.reader import Reader +from omero.gateway import BlitzGateway +from omero.testlib import ITest +from omero_zarr.raw_pixels import image_to_zarr + + +class TestZarrExport(ITest): + def test_export(self, tmp_path: Path) -> None: + dir_name = "test_export" + kwargs = {"sizeX": 50, "sizeY": 25, "sizeZ": 2, "sizeC": 3, "sizeT": 4} + export_dir = tmp_path / dir_name + export_dir.mkdir() + imgs = self.import_fake_file(**kwargs) + + assert imgs is not None + image_id = imgs[0].id.val + conn = BlitzGateway(client_obj=self.client) + image = conn.getObject("Image", image_id) + + # Do the export... + image_to_zarr(image, str(export_dir)) + + new_dirs = [str(zdir) for zdir in export_dir.iterdir()] + print("new_dirs", new_dirs) + assert len(new_dirs) == 1 + zarr_path = new_dirs[0] + # Expect a new IMAGE_ID.zarr directory + assert zarr_path.endswith(f"{dir_name}/{image_id}.zarr") + + # try to read... + reader = Reader(parse_url(zarr_path)) + nodes = list(reader()) + assert len(nodes) == 1 + + print("data", nodes[0].data) + shape = [kwargs.get("size" + dim) for dim in "TCZYX"] + assert nodes[0].data[0].shape == tuple(shape)