ome / omero-cli-zarr

https://pypi.org/project/omero-cli-zarr/
GNU General Public License v2.0
16 stars 10 forks source link

Use of write_multiscale_labels for image #107

Closed will-moore closed 2 years ago

will-moore commented 2 years ago

Testing write_multiscale_labels() added in https://github.com/ome/ome-zarr-py/pull/178/

sbesson commented 2 years ago

This feature has now been released as part of ome-zarr 0.4.0 .

sbesson commented 2 years ago

Unfortunately, my test of plate labels export failes using sample plates from idr0001 as the masks derived from the polygon ROIs seem to be overlapping

(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ omero zarr polygons Plate:2669
Using session for public@idr.openmicroscopy.org:4064. Idle timeout: 10 min. Current group: Public
Found 0 mask shapes in 0 ROIs
Found 19 mask shapes in 19 ROIs
Unique dimensions: {'T': {None}, 'C': {None}, 'Z': {None}}
source_image 2669.zarr/D/9/1
Ignoring dimensions {'Z', 'C', 'T'}
Traceback (most recent call last):
  File "/home/sbesson/miniconda3/envs/conversion/bin/omero", line 10, in <module>
    sys.exit(main())
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/main.py", line 125, in main
    rv = omero.cli.argv()
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1784, in argv
    cli.invoke(args[1:])
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1222, in invoke
    stop = self.onecmd(line, previous_args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1299, in onecmd
    self.execute(line, previous_args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1381, in execute
    args.func(args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/cli.py", line 102, in _wrapper
    return func(self, *args, **kwargs)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/cli.py", line 298, in polygons
    plate_shapes_to_zarr(plate, ["Polygon"], args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/masks.py", line 89, in plate_shapes_to_zarr
    saver.save(list(masks.values()), args.label_name)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/masks.py", line 301, in save
    labels, fill_colors, properties = self.masks_to_labels(
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/masks.py", line 523, in masks_to_labels
    raise Exception(
Exception: Mask 413187 overlaps with existing labels
(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ omero zarr polygons Plate:2551
Using session for public@idr.openmicroscopy.org:4064. Idle timeout: 10 min. Current group: Public
Found 0 mask shapes in 0 ROIs
Found 0 mask shapes in 0 ROIs
Found 0 mask shapes in 0 ROIs
Found 0 mask shapes in 0 ROIs
Found 0 mask shapes in 0 ROIs
Found 0 mask shapes in 0 ROIs
Found 65 mask shapes in 65 ROIs
Unique dimensions: {'T': {None}, 'C': {None}, 'Z': {None}}
source_image 2551.zarr/D/5/0
Ignoring dimensions {'C', 'Z', 'T'}
Traceback (most recent call last):
  File "/home/sbesson/miniconda3/envs/conversion/bin/omero", line 10, in <module>
    sys.exit(main())
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/main.py", line 125, in main
    rv = omero.cli.argv()
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1784, in argv
    cli.invoke(args[1:])
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1222, in invoke
    stop = self.onecmd(line, previous_args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1299, in onecmd
    self.execute(line, previous_args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero/cli.py", line 1381, in execute
    args.func(args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/cli.py", line 102, in _wrapper
    return func(self, *args, **kwargs)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/cli.py", line 298, in polygons
    plate_shapes_to_zarr(plate, ["Polygon"], args)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/masks.py", line 89, in plate_shapes_to_zarr
    saver.save(list(masks.values()), args.label_name)
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/masks.py", line 301, in save
    labels, fill_colors, properties = self.masks_to_labels(
  File "/home/sbesson/miniconda3/envs/conversion/lib/python3.9/site-packages/omero_zarr/masks.py", line 523, in masks_to_labels
    raise Exception(
Exception: Mask 632718 overlaps with existing labels

The export of a single image with non overlapping polygons works as expected

(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ omero zarr export Image:1229945
Using session for public@idr.openmicroscopy.org:4064. Idle timeout: 10 min. Current group: Public
Exporting to 1229945.zarr (0.4)
Finished.
(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ omero zarr polygons Image:1229945
Using session for public@idr.openmicroscopy.org:4064. Idle timeout: 10 min. Current group: Public
Export Polygons on Image: JL_120731_S6A [Well F-8; Field #1]
Found 3 mask shapes in 3 ROIs
Unique dimensions: {'T': {None}, 'C': {None}, 'Z': {None}}
source_image 1229945.zarr
Ignoring dimensions {'Z', 'T', 'C'}

Barring the plate label export workflow, the only remaining issue is the loss of the version in the image-label dictionary.

sbesson commented 2 years ago

https://github.com/ome/ome-zarr-py/pull/206 proposes to address the regression mentioned in https://github.com/ome/omero-cli-zarr/pull/107#pullrequestreview-1007701234 by updating the underlying API to write the version metadata.

will-moore commented 2 years ago

@sbesson Thanks for releasing ome-zarr-py 0.5.0 and bumping the requirements here. This good to merge now?

sbesson commented 2 years ago

I am retesting the PR with the data regeneration and validation process described above. Once this is successful, yes I'd propose to merge and release omero-cli-zarr. Should I also regenerate and upload some (all?) of the sample OME-NGFF datasets and add them to idr.github.io/ome-ngff-samples/ as examples of label images with 8-bit and/or 16-bit types?

will-moore commented 2 years ago

I would like to update as many of the sample OME-NGFF datasets as possible, since that allows viewing the labels on the web (zarr.js). I guess it might be useful to keep a sample as 64-bit, in case someone wants to test with it, but in general I'd like to replace existing labels, since having both is confusing / redundant. Happy to help with regeneration/update etc.