Add image class#515
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #515 +/- ##
==========================================
+ Coverage 85.19% 85.93% +0.74%
==========================================
Files 14 16 +2
Lines 1884 2211 +327
==========================================
+ Hits 1605 1900 +295
- Misses 279 311 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@jo-mueller Thanks for that - This looks like a nice approach to separate the metadata creation and manipulation from the writing to zarr. Comparing APIs:
Various comments, questions. I realise some of this is just not implemented yet... And I haven't tried the code (which might answer some of these)...
|
|
@will-moore thanks for the breakdown. I was aware of some of these points (not all) but decided to send it anyway to not go too far in the wrong direction in case there were strong objections to the approach. Actually, what you wrote is an excellent to-do list :) |
|
@will-moore I think this is taking a bit more shape towards how I'd expect it. But before this can continue, I think there is value in discussing first the current duplicity in functionality between these two functions:
There's a lot of overlap between these two functions which I think can be condensed so we'd have a single place where
Anyway, I just tried the |
|
This pull request has been mentioned on Image.sc Forum. There might be relevant details there: https://forum.image.sc/t/separate-tiles-to-ome-zarr/109071/55 |
|
@jo-mueller Could you update the description to reflect where this is heading now? Are we planning to keep all the existing write methods (any API changes)? |
2b38492 to
c67569d
Compare
|
It would be nice to support writing of "omero" metadata. I think that's covered by ome-zarr-models-py too. |
Agree.
THAT is a good question I'm not entirely sure of myself. I guess if we want to go this way further, we would ultimately deprecate def write_image(args, kwargs):
image = NGffImage(args, kwargs)
multiscales = NgffMultiscales(image, ....)
multiscales.to_ome_zarr(....)which would at least reduce the amount of code to maintain and make sure that everything we do on the class-based API side is covered well by the already existing tests. What's missing hereThe only thing that makes tests fail here currently is this one: ome-zarr-models/ome-zarr-models-py#398. Locally, all tests are passing. Also, note that this branch has been rebased on #544, so that'll have to go in first, too. |
d317e3b to
bcdba78
Compare
|
@will-moore to go forward with this one, my idea for a soft transition would be this: Step 1: Refactor - I am just now trying to see if I can get the existing entrypoints ( |
be59db0 to
8894c02
Compare
This writes an invalid image because the EDIT: Also the |
This image has so the version lookup needs to be a bit more specific |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
blubb feat: use common Label class for image-labels validation
tests: update property parametrization [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci
5c7fd90 to
7af8ca5
Compare
for more information, see https://pre-commit.ci
…/ome-zarr-py into introduce-image-class
|
@will-moore I added a bunch more documentation on how handling labels works in the context of class-based image handling, I think this is coming together nicely :) Some precommit issues to clean up, but otherwise I think this is good to go. I can add some more documentation on omero metadata handling but tht doesn't have to be part of this PR (it's big enough as it is) |
| "# Adding labels to ome-zarrs\n", | ||
| "(advanced:labels:adding_labels)=\n", | ||
| "\n", | ||
| "Unlinke demonstrated in the [basic labels example](basic:labels), in many scenarios, it is nt desirable to write a complete structure consisting of an ome-zarr image and some labels at once.\n", |
| "source": [ | ||
| "## Read OME-ZARR images: Legacy API\n", | ||
| "\n", | ||
| "The code below here demonstrates the legacy API for reading OME-ZARR images.\n", |
There was a problem hiding this comment.
Is this really a "legacy" API?
I think that write_image() is very handy and shouldn't be deprecated / considered legacy?
All the "Customizing the pyramid" examples all use write_image() and it's not described as legacy there.
| "source": [ | ||
| "from ome_zarr import NgffMultiscales\n", | ||
| "\n", | ||
| "url = \"https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0062A/6001240_labels.zarr\"\n", |
There was a problem hiding this comment.
All uk1s3.embassy URLs will need to be updated to livingobjects e.g.
https://livingobjects.ebi.ac.uk/idr/zarr/v0.5/idr0062A/6001240_labels.zarr since the storage is being migrated. uk1s3.embassy will be decommissioned soon.

Hi @will-moore ,
this is an implementation of my idea for a class-based, user-facing API to writing and reading.
Key features
NgffImageandNgffMultiscales(similar to the implementation over at ngff-zarr), that serve as primary entrypoints to the writing.NgffImageaccepts the data to be written as an array and coerces it to dask internally. It requires theaxes(i.e.,"tczyx") to be passed at instantiation. It also accepts kwargs for pixel sizes (scale), axes units (axes_units) and the name of the image (name) which are later serialized in the ome-zarr metadata.The
NgffMultiscalesthen constructs a pyramid using the already existing methods (_build_pyramid) that were implemented in deprecate scaler class #516.Metadataclass from there for simpke serialization and de-serialization in the write/read process. Primarily, the coordinate transformation classes and theMultiscalesmetadata classes are used.Importantly, all metadata is internally coerced to
ozmp.v05.Multiscales. Only on writing the metadata class is converted to whatever ome-zarr version is desired.NgffMultiscales.to_ome_zarr()method. This method makes use of the already existing writing API from Streamline writing #531 (_write_pyramid_to_zarr). It then converts the metadata to the chosen version and uses pydantic'sobject.model_dump()to create the metadata dictionary. Importantly, the version conversion is only implemented in implement version converters ome-zarr-models/ome-zarr-models-py#398, so this is currently blocked by that.NgffMultiscalesclass also has an attachedfrom_ome_zarr(...)classmethod. The argument is simply the path/group of the ome-zarr image. The function then reads the metadata and the multiscales as dask arrays and returns an instance ofNgffMultiscales. The version is automatically detected and again coerced toozmp.v05.Multiscalesinternally.NgffMultiscalesand passing them as a single image or as adict(str, NgffMultiscales)to theto_ome_zarrwriter function. I have yet to implement the same functionality for the reading.All in all, I think especially the
to_ome_zarrandfrom_ome__zarrmethods are super convenient. I have written a follow-up implementation of thescenemetadata from 0.6 and making use of the same API there makes a lot of sense. We could think of similar entrypoints to writing HCS layouts.Further considerations
_build_pyramidandwrite_pyramid_to_zarr- I see no harm in keeping the currently existing API around if it works for people. Maybe we'd have to update thewrite_imagefunction so that it would also accept an instance ofNgffImage, otherwise it may be confusing? I'm not so decided on the reading though.TODOs:
omerometadata andimage-labelmetadata