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 Feb 28, 2025
1 parent f01f471 commit 03bde3a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 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 = dask,numpy,ome_zarr,omero,omero_zarr,setuptools,skimage,zarr
known_third_party = dask,numpy,ome_zarr,omero,omero_sys_ParametersI,omero_zarr,setuptools,skimage,zarr
21 changes: 11 additions & 10 deletions src/omero_zarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from zarr.hierarchy import open_group
from zarr.storage import FSStore

from .extinfo import get_images, set_external_info
from .masks import (
MASK_DTYPE_SIZE,
MaskSaver,
Expand All @@ -41,10 +42,6 @@
image_to_zarr,
plate_to_zarr,
)
from .extinfo import (
get_images,
set_external_info,
)

HELP = """Export data in zarr format.
Expand Down Expand Up @@ -114,6 +111,7 @@

EXTINFO_HELP = """Set the external info path for an ome.zarr image."""


def gateway_required(func: Callable) -> Callable:
"""
Decorator which initializes a client (self.client),
Expand Down Expand Up @@ -290,9 +288,9 @@ def _configure(self, parser: Parser) -> None:
)

exinfo = parser.add(sub, self.extinfo, EXTINFO_HELP)
exinfo.add_argument("object",
type=ProxyStringType(),
help="Object in Class:ID format")
exinfo.add_argument(
"object", type=ProxyStringType(), help="Object in Class:ID format"
)

for subcommand in (polygons, masks, export):
subcommand.add_argument(
Expand Down Expand Up @@ -352,10 +350,13 @@ def extinfo(self, args: argparse.Namespace) -> None:
try:
img = set_external_info(self.gateway, img, well, idx)
img = self.gateway.getUpdateService().saveAndReturnObject(img)
self.ctx.out(f"Set path to '{img.details.externalInfo.lsid._val}' for image {img.id._val}")
self.ctx.out(
f"Set path to '{img.details.externalInfo.lsid._val}' for image {img.id._val}"
)
except Exception as e:
self.ctx.err(f"Failed to set external info for image {img.id._val}: {e}")

self.ctx.err(
f"Failed to set external info for image {img.id._val}: {e}"
)

def _lookup(
self, gateway: BlitzGateway, otype: str, oid: int
Expand Down
32 changes: 14 additions & 18 deletions src/omero_zarr/extinfo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from omero.gateway import BlitzGateway
from omero.gateway import BlitzObjectWrapper
from omero.model import ExternalInfoI, ImageI
from omero.rtypes import rstring, rlong
from omero_sys_ParametersI import ParametersI
from omero.model import Image
from omero.model import Plate
from omero.model import Screen
from omero.model import Dataset
from omero.model import Project
import re

from omero.gateway import BlitzGateway, BlitzObjectWrapper
from omero.model import Dataset, ExternalInfoI, Image, ImageI, Plate, Project, Screen
from omero.rtypes import rlong, rstring
from omero_sys_ParametersI import ParametersI

# Regex to match well positions (eg. A1)
WELL_POS_RE = re.compile(r"(?P<row>\D+)(?P<col>\d+)")
Expand Down Expand Up @@ -65,7 +59,9 @@ def _lookup(conn: BlitzGateway, type: str, oid: int) -> BlitzObjectWrapper:
return obj


def get_images(conn: BlitzGateway, object) -> tuple[BlitzObjectWrapper, str | None, int | None]:
def get_images(
conn: BlitzGateway, object
) -> tuple[BlitzObjectWrapper, str | None, int | None]:
"""
Generator that yields images from any OMERO container object.
Expand Down Expand Up @@ -117,30 +113,30 @@ def get_images(conn: BlitzGateway, object) -> tuple[BlitzObjectWrapper, str | No
def set_external_info(conn: BlitzGateway, img: ImageI, well: str, idx: int) -> ImageI:
"""
Set external info for an image to enable omero zarr pixel buffer handling.
This function configures an image for use with the omero-zarr-pixel-buffer by:
1. Retrieving the original file path
2. Converting it to point to the 5d multiscale image directory
3. Setting up the external info with the path and metadata
For plate-based images (with wells), the path structure follows:
/<base_path>/<row>/<column>/<field index>
For regular images:
/<base_path>/0
Args:
conn (BlitzGateway): Active OMERO gateway connection
img (ImageI): OMERO image object to modify
well (str): Well position (e.g., 'A1', 'B2') for plate-based images, or None
idx (int): Well sample / field index for plate-based images, or None
Returns:
ImageI: Modified image object with updated external info
Raises:
ValueError: If the image path is not an OME-Zarr format or if well position is invalid
Note:
The external info is configured with entity type 'com.glencoesoftware.ngff:multiscales'
and entity ID 3, which are required by the omero-zarr-pixel-buffer.
Expand Down

0 comments on commit 03bde3a

Please sign in to comment.