Skip to content

Commit 3ee3cca

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 837af45 commit 3ee3cca

File tree

3 files changed

+56
-43
lines changed

3 files changed

+56
-43
lines changed

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[settings]
2-
known_third_party = dask,numpy,ome_zarr,omero,omero_zarr,setuptools,skimage,zarr
2+
known_third_party = dask,numpy,ome_zarr,omero,omero_sys_ParametersI,omero_zarr,setuptools,skimage,zarr

src/omero_zarr/cli.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from zarr.hierarchy import open_group
3030
from zarr.storage import FSStore
3131

32+
from .extinfo import external_info_str, get_extinfo, get_images, set_external_info
3233
from .masks import (
3334
MASK_DTYPE_SIZE,
3435
MaskSaver,
@@ -41,12 +42,6 @@
4142
image_to_zarr,
4243
plate_to_zarr,
4344
)
44-
from .extinfo import (
45-
get_images,
46-
set_external_info,
47-
get_extinfo,
48-
external_info_str
49-
)
5045

5146
HELP = """Export data in zarr format.
5247
@@ -120,6 +115,7 @@
120115
or --reset in order to remove the ExternalInfo from the image.
121116
"""
122117

118+
123119
def gateway_required(func: Callable) -> Callable:
124120
"""
125121
Decorator which initializes a client (self.client),
@@ -296,33 +292,29 @@ def _configure(self, parser: Parser) -> None:
296292
)
297293

298294
extinfo = parser.add(sub, self.extinfo, EXTINFO_HELP)
299-
extinfo.add_argument("object",
300-
type=ProxyStringType(),
301-
help="Object in Class:ID format")
302295
extinfo.add_argument(
303-
"--set",
304-
action="store_true",
305-
help="Set the ExternalInfo path"
296+
"object", type=ProxyStringType(), help="Object in Class:ID format"
297+
)
298+
extinfo.add_argument(
299+
"--set", action="store_true", help="Set the ExternalInfo path"
306300
)
307301
extinfo.add_argument(
308302
"--path",
309303
default=None,
310-
help="Use a specific path (default: Determine from clientPath) (only used in combination with --set)"
304+
help="Use a specific path (default: Determine from clientPath) (only used in combination with --set)",
311305
)
312306
extinfo.add_argument(
313307
"--entityType",
314308
default="com.glencoesoftware.ngff:multiscales",
315-
help="Use a specific entityType (default: com.glencoesoftware.ngff:multiscales) (only used in combination with --set)"
309+
help="Use a specific entityType (default: com.glencoesoftware.ngff:multiscales) (only used in combination with --set)",
316310
)
317311
extinfo.add_argument(
318312
"--entityId",
319313
default="3",
320-
help="Use a specific entityId (default: 3) (only used in combination with --set)"
314+
help="Use a specific entityId (default: 3) (only used in combination with --set)",
321315
)
322316
extinfo.add_argument(
323-
"--reset",
324-
action="store_true",
325-
help="Removes the ExternalInfo"
317+
"--reset", action="store_true", help="Removes the ExternalInfo"
326318
)
327319

328320
for subcommand in (polygons, masks, export):
@@ -376,32 +368,50 @@ def export(self, args: argparse.Namespace) -> None:
376368
plate = self._lookup(self.gateway, "Plate", args.object.id)
377369
plate_to_zarr(plate, args)
378370

379-
380371
@gateway_required
381372
def extinfo(self, args: argparse.Namespace) -> None:
382373
for img, well, idx in get_images(self.gateway, args.object):
383374
img = img._obj
384375
extinfo = get_extinfo(self.gateway, img)
385376
if args.set:
386377
try:
387-
img = set_external_info(self.gateway, img, well, idx, args.path, args.entityType, int(args.entityId))
378+
img = set_external_info(
379+
self.gateway,
380+
img,
381+
well,
382+
idx,
383+
args.path,
384+
args.entityType,
385+
int(args.entityId),
386+
)
388387
img = self.gateway.getUpdateService().saveAndReturnObject(img)
389-
self.ctx.out(f"Set ExternalInfo for image ({img.id._val}) {img.name._val}:\n{external_info_str(img.details.externalInfo)}")
388+
self.ctx.out(
389+
f"Set ExternalInfo for image ({img.id._val}) {img.name._val}:\n{external_info_str(img.details.externalInfo)}"
390+
)
390391
except Exception as e:
391-
self.ctx.err(f"Failed to set external info for image ({img.id._val}) {img.name._val}: {e}")
392+
self.ctx.err(
393+
f"Failed to set external info for image ({img.id._val}) {img.name._val}: {e}"
394+
)
392395
elif args.reset:
393396
if extinfo:
394397
img.details.externalInfo = None
395398
img = self.gateway.getUpdateService().saveAndReturnObject(img)
396-
self.ctx.out(f"Removed ExternalInfo from image ({img.id._val}) {img.name._val}")
399+
self.ctx.out(
400+
f"Removed ExternalInfo from image ({img.id._val}) {img.name._val}"
401+
)
397402
else:
398-
self.ctx.out(f"Image ({img.id._val}) {img.name._val} has no ExternalInfo")
403+
self.ctx.out(
404+
f"Image ({img.id._val}) {img.name._val} has no ExternalInfo"
405+
)
399406
else:
400407
if extinfo:
401-
self.ctx.out(f"ExternalInfo for image ({img.id._val}) {img.name._val}:\n{external_info_str(extinfo)}")
408+
self.ctx.out(
409+
f"ExternalInfo for image ({img.id._val}) {img.name._val}:\n{external_info_str(extinfo)}"
410+
)
402411
else:
403-
self.ctx.out(f"Image ({img.id._val}) {img.name._val} has no ExternalInfo")
404-
412+
self.ctx.out(
413+
f"Image ({img.id._val}) {img.name._val} has no ExternalInfo"
414+
)
405415

406416
def _lookup(
407417
self, gateway: BlitzGateway, otype: str, oid: int

src/omero_zarr/extinfo.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
from omero.gateway import BlitzGateway, ImageWrapper
2-
from omero.gateway import BlitzObjectWrapper
3-
from omero.model import ExternalInfoI, ImageI
4-
from omero.rtypes import rstring, rlong
5-
from omero_sys_ParametersI import ParametersI
6-
from omero.model import Image
7-
from omero.model import Plate
8-
from omero.model import Screen
9-
from omero.model import Dataset
10-
from omero.model import Project
111
import re
122

3+
from omero.gateway import BlitzGateway, BlitzObjectWrapper, ImageWrapper
4+
from omero.model import Dataset, ExternalInfoI, Image, ImageI, Plate, Project, Screen
5+
from omero.rtypes import rlong, rstring
6+
from omero_sys_ParametersI import ParametersI
137

148
# Regex to match well positions (eg. A1)
159
WELL_POS_RE = re.compile(r"(?P<row>\D+)(?P<col>\d+)")
@@ -41,7 +35,7 @@ def get_extinfo(conn: BlitzGateway, image: ImageWrapper) -> ExternalInfoI:
4135
extinfo = conn.getQueryService().findByQuery(query, params)
4236
return extinfo
4337
return None
44-
38+
4539

4640
def _get_path(conn: BlitzGateway, image_id: int) -> str:
4741
"""
@@ -93,7 +87,9 @@ def _lookup(conn: BlitzGateway, type: str, oid: int) -> BlitzObjectWrapper:
9387
return obj
9488

9589

96-
def get_images(conn: BlitzGateway, object) -> tuple[ImageWrapper, str | None, int | None]:
90+
def get_images(
91+
conn: BlitzGateway, object
92+
) -> tuple[ImageWrapper, str | None, int | None]:
9793
"""
9894
Generator that yields images from any OMERO container object.
9995
@@ -142,8 +138,15 @@ def get_images(conn: BlitzGateway, object) -> tuple[ImageWrapper, str | None, in
142138
raise ValueError(f"Unsupported type: {object.__class__.__name__}")
143139

144140

145-
def set_external_info(conn: BlitzGateway, img: ImageI, well: str, idx: int,
146-
lsid: str | None = None, entityType: str | None = None, entityId: int | None = None) -> ImageI:
141+
def set_external_info(
142+
conn: BlitzGateway,
143+
img: ImageI,
144+
well: str,
145+
idx: int,
146+
lsid: str | None = None,
147+
entityType: str | None = None,
148+
entityId: int | None = None,
149+
) -> ImageI:
147150
"""
148151
Set the external info for an OMERO image.
149152
@@ -166,7 +169,7 @@ def set_external_info(conn: BlitzGateway, img: ImageI, well: str, idx: int,
166169
if not entityType:
167170
entityType = "com.glencoesoftware.ngff:multiscales"
168171
if not entityId:
169-
entityId = 3
172+
entityId = 3
170173
if lsid:
171174
path = lsid
172175
else:

0 commit comments

Comments
 (0)