Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zarr export tests #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/omero_plugin.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .omeroci/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLUGIN=zarr
4 changes: 3 additions & 1 deletion src/omero_zarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/omero_zarr/raw_pixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
Expand Down
64 changes: 64 additions & 0 deletions test/test_export.py
Original file line number Diff line number Diff line change
@@ -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)