|
29 | 29 | from zarr.hierarchy import open_group |
30 | 30 | from zarr.storage import FSStore |
31 | 31 |
|
| 32 | +from .extinfo import external_info_str, get_extinfo, get_images, set_external_info |
32 | 33 | from .masks import ( |
33 | 34 | MASK_DTYPE_SIZE, |
34 | 35 | MaskSaver, |
|
41 | 42 | image_to_zarr, |
42 | 43 | plate_to_zarr, |
43 | 44 | ) |
44 | | -from .extinfo import ( |
45 | | - get_images, |
46 | | - set_external_info, |
47 | | - get_extinfo, |
48 | | - external_info_str |
49 | | -) |
50 | 45 |
|
51 | 46 | HELP = """Export data in zarr format. |
52 | 47 |
|
|
120 | 115 | or --reset in order to remove the ExternalInfo from the image. |
121 | 116 | """ |
122 | 117 |
|
| 118 | + |
123 | 119 | def gateway_required(func: Callable) -> Callable: |
124 | 120 | """ |
125 | 121 | Decorator which initializes a client (self.client), |
@@ -296,33 +292,29 @@ def _configure(self, parser: Parser) -> None: |
296 | 292 | ) |
297 | 293 |
|
298 | 294 | extinfo = parser.add(sub, self.extinfo, EXTINFO_HELP) |
299 | | - extinfo.add_argument("object", |
300 | | - type=ProxyStringType(), |
301 | | - help="Object in Class:ID format") |
302 | 295 | 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" |
306 | 300 | ) |
307 | 301 | extinfo.add_argument( |
308 | 302 | "--path", |
309 | 303 | 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)", |
311 | 305 | ) |
312 | 306 | extinfo.add_argument( |
313 | 307 | "--entityType", |
314 | 308 | 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)", |
316 | 310 | ) |
317 | 311 | extinfo.add_argument( |
318 | 312 | "--entityId", |
319 | 313 | 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)", |
321 | 315 | ) |
322 | 316 | extinfo.add_argument( |
323 | | - "--reset", |
324 | | - action="store_true", |
325 | | - help="Removes the ExternalInfo" |
| 317 | + "--reset", action="store_true", help="Removes the ExternalInfo" |
326 | 318 | ) |
327 | 319 |
|
328 | 320 | for subcommand in (polygons, masks, export): |
@@ -376,32 +368,50 @@ def export(self, args: argparse.Namespace) -> None: |
376 | 368 | plate = self._lookup(self.gateway, "Plate", args.object.id) |
377 | 369 | plate_to_zarr(plate, args) |
378 | 370 |
|
379 | | - |
380 | 371 | @gateway_required |
381 | 372 | def extinfo(self, args: argparse.Namespace) -> None: |
382 | 373 | for img, well, idx in get_images(self.gateway, args.object): |
383 | 374 | img = img._obj |
384 | 375 | extinfo = get_extinfo(self.gateway, img) |
385 | 376 | if args.set: |
386 | 377 | 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 | + ) |
388 | 387 | 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 | + ) |
390 | 391 | 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 | + ) |
392 | 395 | elif args.reset: |
393 | 396 | if extinfo: |
394 | 397 | img.details.externalInfo = None |
395 | 398 | 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 | + ) |
397 | 402 | 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 | + ) |
399 | 406 | else: |
400 | 407 | 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 | + ) |
402 | 411 | 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 | + ) |
405 | 415 |
|
406 | 416 | def _lookup( |
407 | 417 | self, gateway: BlitzGateway, otype: str, oid: int |
|
0 commit comments