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

Use of write_multiscale_labels for image #107

Merged
merged 6 commits into from
Jun 21, 2022

Conversation

will-moore
Copy link
Member

Testing write_multiscale_labels() added in ome/ome-zarr-py#178

@sbesson
Copy link
Member

sbesson commented May 5, 2022

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

@will-moore will-moore marked this pull request as ready for review May 20, 2022 12:33
@will-moore will-moore changed the title Initial use of write_multiscale_labels for image Use of write_multiscale_labels for image May 25, 2022
Copy link
Member

@sbesson sbesson left a comment

Choose a reason for hiding this comment

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

Tested using the same set of samples as the ones generated in #116

To compare the output, I used the following minimal script which should compare arrays and flag difference in attributes

import zarr
import sys

z1 = zarr.open(sys.argv[1])
z2 = zarr.open(sys.argv[2])

if z1.attrs != z2.attrs:
  print("Different top-level attributes")

assert len(z1) == len(z2)


for a in z1.arrays():
  key = a[0]
  assert (z1[key][:] == z2[key][:]).all()

if z1['labels'].attrs != z2['labels'].attrs:
  print("Different labels attributes")

for g in z1['labels'].groups():
  label_name = g[0]
  if z1['labels'][label_name].attrs != z2['labels'][label_name].attrs:
    print("Different image-label attributes")
  assert len(z1['labels'][label_name]) == len(z2['labels'][label_name])
  for a in z1['labels'][label_name].arrays():
    key = a[0]
    assert (z1['labels'][label_name][key][:] == z2['labels'][label_name][key][:]).all()

The execution of this script reveals no difference in the binary data content when comparing the arrays but a few mismatches in the attributes

(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_116]$ for i in *.zarr; do echo $i && python diff.py $i ../omero-cli-zarr_107/$i; done
10501752.zarr
Different top-level attributes
Different image-label attributes
4496763.zarr
Different top-level attributes
Different image-label attributes
5514375.zarr
Different top-level attributes
Different image-label attributes
Different image-label attributes
6001247.zarr
Different top-level attributes
Different image-label attributes

The top-level attribute difference comes from the version of the creation tool and is expected

(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_116]$ for i in *.zarr; do diff $i/.zattrs ../omero-cli-zarr_107/$i/.zattrs; done
4c4
<         "version": "0.3.1.dev33+gf305941"
---
>         "version": "0.3.1.dev40+gcd84f02"
4c4
<         "version": "0.3.1.dev33+gf305941"
---
>         "version": "0.3.1.dev40+gcd84f02"
4c4
<         "version": "0.3.1.dev33+gf305941"
---
>         "version": "0.3.1.dev40+gcd84f02"
4c4
<         "version": "0.3.1.dev33+gf305941"
---
>         "version": "0.3.1.dev40+gcd84f02"

For the attribute of the image-label layer, the new code adds the name of the multiscales but the version in the image-label specification seems to be lost and should be restored

(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_116]$ find * -mindepth 2 -iname .zattrs -exec diff ../omero-cli-zarr_107/{} {} \; 
23991c23991,23992
<         }
---
>         },
>         "version": "0.4"
24076d24076
<             "name": "0",
6029c6029,6030
<         }
---
>         },
>         "version": "0.4"
6152d6152
<             "name": "0",
609c609,610
<         }
---
>         },
>         "version": "0.4"
700d700
<             "name": "Cell",
609c609,610
<         }
---
>         },
>         "version": "0.4"
700d700
<             "name": "Chromosomes",
681c681,682
<         }
---
>         },
>         "version": "0.4"
764d764
<             "name": "0",

I will also have a go at testing a plate labels export

@sbesson
Copy link
Member

sbesson commented Jun 16, 2022

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
Copy link
Member

sbesson commented Jun 20, 2022

ome/ome-zarr-py#206 proposes to address the regression mentioned in #107 (review) by updating the underlying API to write the version metadata.

setup.py Outdated Show resolved Hide resolved
Co-authored-by: Sébastien Besson <seb.besson@gmail.com>
@sbesson sbesson self-requested a review June 20, 2022 14:04
@will-moore
Copy link
Member Author

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

@sbesson
Copy link
Member

sbesson commented Jun 21, 2022

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
Copy link
Member Author

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.

Copy link
Member

@sbesson sbesson left a comment

Choose a reason for hiding this comment

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

Retested the conversion workflow and confirmed that the arrays are identical and the only metadata difference are 1- the creator version 2- the addition of image names

(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ for i in *.zarr; do echo $i && python diff.py $i ../omero-cli-zarr_116/$i; done
10501752.zarr
Different top-level attributes
Different image-label attributes
4496763.zarr
Different top-level attributes
Different image-label attributes
5514375.zarr
Different top-level attributes
Different image-label attributes
Different image-label attributes
6001247.zarr
Different top-level attributes
Different image-label attributes
(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ for i in *.zarr; do diff $i/.zattrs ../omero-cli-zarr_116/$i/.zattrs; done
4c4
<         "version": "0.3.1.dev41+g5c73169"
---
>         "version": "0.3.1.dev33+gf305941"
4c4
<         "version": "0.3.1.dev41+g5c73169"
---
>         "version": "0.3.1.dev33+gf305941"
4c4
<         "version": "0.3.1.dev41+g5c73169"
---
>         "version": "0.3.1.dev33+gf305941"
4c4
<         "version": "0.3.1.dev41+g5c73169"
---
>         "version": "0.3.1.dev33+gf305941"
(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ find * -mindepth 2 -iname .zattrs -exec diff ../omero-cli-zarr_116/{} {} \;
24076a24077
>             "name": "0",
6152a6153
>             "name": "0",
700a701
>             "name": "Cell",
700a701
>             "name": "Chromosomes",
764a765
>             "name": "0",

and confirmed that the dtype of the labels is still int8 or int16 as per #107

(conversion) [sbesson@pilot-zarr1-dev omero-cli-zarr_107]$ find * -mindepth 3 -iname .zarray -exec grep dtype {} \;
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "<i2",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",
    "dtype": "|i1",

@sbesson sbesson merged commit 06a1ddf into ome:master Jun 21, 2022
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.

2 participants