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

Add extinfo command #167

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Add extinfo command #167

wants to merge 14 commits into from

Conversation

dominikl
Copy link
Member

@dominikl dominikl commented Feb 25, 2025

This command will automatically set the ExternalInfo for ome.zarr images imported using the omero-zarr-pixel-buffer, if the --set option is specified. Default is to just print the ExternalInfo.

I takes the path from the Fileset "usedFiles", which is assumed to only have one entry ..../SOME.ome.zarr/OME/METADATA.ome.xml and then set the ExternalInfo lsid to the full path of the multiscale 5d image; ..../SOME.ome.zarr/0 for an image ..../SOME.ome.zarr/A/1/1 etc. for plates.

Limitations: Only works for ome.zarr imported from the filesystem.

Get the ExternalInfo path of an ome.zarr image.

Use --set to set the external info path
or --reset in order to remove the ExternalInfo from the image.

Positional Arguments:
  object                   Object in Class:ID format

Optional Arguments:
  In addition to any higher level options

  -h, --help               show this help message and exit
  --set                    Set the ExternalInfo path
  --lsid LSID              Use a specific lsid (path) (default: Determine from clientPath) (only used in combination with --set)
  --entityType ENTITYTYPE  Use a specific entityType (default: com.glencoesoftware.ngff:multiscales) (only used in combination with --set)
  --entityId ENTITYID      Use a specific entityId (default: 3) (only used in combination with --set)
  --reset                  Removes the ExternalInfo

@joshmoore
Copy link
Member

💯 As a part of this I can imagine wanting to get and to reset as well.

@will-moore
Copy link
Member

$ omero login
Error loading: /Users/wmoore/Desktop/ZARR/omero-cli-zarr/src/omero/plugins/zarr.py
Traceback (most recent call last):
  File "/Users/wmoore/Desktop/PY/omero-py/target/omero/cli.py", line 1677, in loadpath
    exec(f.read(), loc)
  File "<string>", line 1, in <module>
  File "/Users/wmoore/Desktop/ZARR/omero-cli-zarr/src/omero_zarr/cli.py", line 32, in <module>
    from .extinfo import external_info_str, get_extinfo, get_images, set_external_info
  File "/Users/wmoore/Desktop/ZARR/omero-cli-zarr/src/omero_zarr/extinfo.py", line 92, in <module>
    ) -> tuple[ImageWrapper, str | None, int | None]:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

@dominikl
Copy link
Member Author

dominikl commented Mar 3, 2025

Interesting... is this a python version thing? I use 3.12.9.

@will-moore
Copy link
Member

It could be, I'm on an old env python 3.9.15.

@dominikl
Copy link
Member Author

dominikl commented Mar 3, 2025

Yes, looks like it's supported from 3.10 on. As we still recommend 3.9 I'll remove that stuff again.

select e from ExternalInfo as e
where e.id = :id
"""
extinfo = conn.getQueryService().findByQuery(query, params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In think this needs to be a cross-group query findByQuery(query, params, conn.SERVICE_OPTS) otherwise you won't see it if the extinfo isn't in your default group.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still outstanding. Same for the other conn.getQueryService().findByQuery below too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I do that one line above conn.SERVICE_OPTS.setOmeroGroup("-1") , is that not enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, then you have to pass conn.SERVICE_OPTS that into the function call again. Ok, i'll fix that.

join fetch usedFile.originalFile as f
join fetch f.hasher where image.id = :id
"""
fs = conn.getQueryService().findByQuery(query, params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cross-group query here too

@@ -108,6 +109,12 @@

POLYGONS_HELP = """Export ROI Polygons on the Image or Plate in zarr format"""

EXTINFO_HELP = """Get the ExternalInfo path of an ome.zarr image.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get or set...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get, because that's the default action.

@will-moore
Copy link
Member

I was trying to test this on a non-zarr image, by specifying the --path but...

$ omero zarr extinfo Image:2856 --set --path test_extinfo_path
Previous session expired for will on localhost:4064
Server: [localhost:4064]
Username: [will]
Password:
Created session for will@localhost:4064. Idle timeout: 10 min. Current group: Swedlow Lab
Failed to set external info for image (2856) 438CTR_01_4_R3D_D3D.dv_1: Doesn't seem to be an ome.zarr: Users/wmoore/Desktop/images/DVs/438CTR_01_4_R3D_D3D.dv

It seems that there's something strange about --path, like it's being swallowed / overwritten somehow so that args.path was always None. Renaming this argument to anything else seemed to fix it. I suggest using lsid since that corresponds to the field in the extInfo.

@dominikl
Copy link
Member Author

dominikl commented Mar 7, 2025

There's a check if it is a ome.zarr: https://github.com/ome/omero-cli-zarr/pull/167/files#diff-2d64f99479103ff3050c633344ddf895f61491094e9dab65218a3ec17cbfcb59R177 As that's actually only intended to be used with zarr. Otherwise it wouldn't make sense to have it as omero-cli-zarr plugin!?

@will-moore
Copy link
Member

The point is that you have a --path argument for...

help="Use a specific path (default: Determine from clientPath) (only used in combination with --set)",

but it doesn't work for me. Does it work for you?

@dominikl dominikl force-pushed the extinfo branch 3 times, most recently from ec042a0 to b379cdf Compare March 10, 2025 15:40
@dominikl dominikl force-pushed the extinfo branch 5 times, most recently from a6c74e7 to e922f47 Compare March 11, 2025 09:15
@dominikl dominikl force-pushed the extinfo branch 2 times, most recently from 3cc6c05 to ad4a5b2 Compare March 11, 2025 15:56
hooks:
- id: flake8
additional_dependencies: [
flake8-blind-except,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too re-enable, we'll probably need help from @will-moore on knowing what exceptions can be thrown.

flake8-builtins,
flake8-rst-docstrings,
flake8-logging-format,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it broke in Python 3.12: pytest-dev/pytest-testinfra#765

@dominikl dominikl marked this pull request as ready for review March 11, 2025 16:52
@dominikl
Copy link
Member Author

Thanks Josh for fixing the precommit stuff! So this now suppports single image ome.zarrs, multi-series zarrs, and plates. Did I forget another use case?

@dominikl dominikl requested a review from will-moore March 12, 2025 09:22
"""
if extinfo is not None:
return (
f"[entityType={_checkNone(extinfo.entityType)}\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: wondering why the [ here and ] on the line below?

ExternalInfo for image (2856) 438CTR_01_4_R3D_D3D.dv_1:
[entityType=com.glencoesoftware.ngff:multiscales
 entityId=3
 lsid=test_extinfo_path]

@will-moore
Copy link
Member

When working with images that are not in your default group, you need to specify the group when saving (and use {"omero.group": "-1"} for querying, which is the default in conn.SERVICE_OPTS.

This is what I have to get --set and --reset working for such images:

+++ b/src/omero_zarr/cli.py
@@ -405,6 +405,7 @@ class ZarrControl(BaseControl):
     def extinfo(self, args: argparse.Namespace) -> None:
         for img, well, idx in get_images(self.gateway, args.object):
             img = img._obj
+            group_id = img.getDetails().getGroup().id.val
             extinfo = get_extinfo(self.gateway, img)
 
             if self.gateway is None:
@@ -424,7 +425,7 @@ class ZarrControl(BaseControl):
                         args.entityType,
                         int(args.entityId),
                     )
-                    img = update_service.saveAndReturnObject(img)
+                    img = update_service.saveAndReturnObject(img, {"omero.group": str(group_id)})
                     self.ctx.out(
                         f"Set ExternalInfo for image ({img.id._val}) "
                         f"{img.name._val}:\n"
@@ -438,7 +439,7 @@ class ZarrControl(BaseControl):
             elif args.reset:
                 if extinfo:
                     img.details.externalInfo = None
-                    img = update_service.saveAndReturnObject(img)
+                    img = update_service.saveAndReturnObject(img, {"omero.group": str(group_id)})
                     self.ctx.out(
                         f"Removed ExternalInfo from image "
                         f"({img.id._val}) {img.name._val}"
diff --git a/src/omero_zarr/extinfo.py b/src/omero_zarr/extinfo.py
index 52aaf1c..7c1feb2 100644
--- a/src/omero_zarr/extinfo.py
+++ b/src/omero_zarr/extinfo.py
@@ -34,7 +34,7 @@ def get_extinfo(conn: BlitzGateway, image: ImageWrapper) -> ExternalInfoI:
             where e.id = :id
         """
         conn.SERVICE_OPTS.setOmeroGroup("-1")
-        extinfo = conn.getQueryService().findByQuery(query, params)
+        extinfo = conn.getQueryService().findByQuery(query, params, conn.SERVICE_OPTS)
         return extinfo
     return None
 
@@ -64,7 +64,7 @@ def _get_path(conn: BlitzGateway, image_id: int) -> str:
         where image.id = :id
     """
     conn.SERVICE_OPTS.setOmeroGroup("-1")
-    fs = conn.getQueryService().findByQuery(query, params)
+    fs = conn.getQueryService().findByQuery(query, params, conn.SERVICE_OPTS)
     path = fs._getUsedFiles()[0]._clientPath._val
     return path

@dominikl
Copy link
Member Author

dominikl commented Mar 13, 2025

That's odd. You have to explicitely set the omero.group for saveAndReturnObject even if there are no changes with respect to the group? But well, I can add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants