-
Notifications
You must be signed in to change notification settings - Fork 7
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
Introduce Pydantic models for NGFF metadata #528
Introduce Pydantic models for NGFF metadata #528
Conversation
Coverage reportThe coverage rate went from
Diff Coverage details (click to unfold)fractal_tasks_core/lib_ngff.py
fractal_tasks_core/lib_zattrs_utils.py
fractal_tasks_core/tasks/apply_registration_to_ROI_tables.py
fractal_tasks_core/tasks/apply_registration_to_image.py
fractal_tasks_core/tasks/calculate_registration_image_based.py
fractal_tasks_core/tasks/cellpose_segmentation.py
fractal_tasks_core/tasks/copy_ome_zarr.py
fractal_tasks_core/tasks/create_ome_zarr.py
fractal_tasks_core/tasks/illumination_correction.py
fractal_tasks_core/tasks/maximum_intensity_projection.py
fractal_tasks_core/tasks/napari_workflows_wrapper.py
fractal_tasks_core/tasks/yokogawa_to_ome_zarr.py
|
…than-from-metadata-whenever-possible
Old version had `scale` transformation with 3 items instead of 4
Great. |
…, and `lib_image.py->lib_ngff.py`
…tion_to_ROI_tables` task
This PR is essentially ready on my side. Its contents is briefly summarized as:
Relevant issues closed by this PR:
It is quite a large PR, but at least a high-level review would be very useful - cc @jluethi. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tcompa This looks great! I added a few minor comments on the NGFF pydantic models and some questions on whether some lines should now be moved to a different part of the task (open to hear where they are placed better, just stood out that we could move them together with this refactor).
Also, we can use the NGFF Pydantic models to start generalizing axes. Sounds like a good idea to start like this with an pixel_sizes_zyx
property and then move to more flexible handling in the Pydantic model that the tasks can adopt :)
I didn't review the test changes.
…than-from-metadata-whenever-possible
…than-from-metadata-whenever-possible
1. Extract pixel sizes together with other attributes; 2. Remove redundant extraction of pixel sizes for anisotropy calculation; 3. Remove redundant X/Y homogeneity check (now part of `coarsening_xy` extraction); 4. Improve logging.
These should all be covered now.
That's OK. |
close #351
close #501
close #532
close #533
metadata
.lib_ngff.py
lib_zattrs_utils.py
lib_ngff.py
CHANGELOG.md
lib_channels.py
- ref De-duplicate Pydantic models inlib_channels.py
andlib_ngff.py
#540The main goal is to extract some ome-ngff-related metadata directly from an ome-zarr, rather than from the
metadata
input parameter (ref #351). This is a clear goal, that can be achieved in multiple ways. The simplest one is to have several helper functions that go and construct a given parameter (e.g.num_levels
) based on the attributes of an OME-Zarr group.With the current PR, I'm proposing a different approach that brings in broader changes. I'm introducing Pydantic models that encode (part of) OME-NGFF specs, and then implementing additional logic as part of these models (via properties or methods), e.g. to extract
num_levels
.Instead of writing the Pydantic models myself, I generated them automatically from the JSON Schema of 0.4 NGFF (via https://github.com/koxudaxi/datamodel-code-generator) and then tweaked them a bit - resulting e.g. in a
NgffImage
model - see also note below on effort duplication.If we pursue this route, then most of the functions in
lib_zattrs_utils.py
will become methods of the appropriate NGFF object (e.g.NgffImage
orNgffWell
). The example I already included in the preliminary commits of this PR is that alsoextract_zyx_pixel_sizes
can be re-written in a simpler way as a method ofNgffImage
. Example:Scope of this change
To be clear: this new
lib_image.py
module (to be renamed intolib_ngff.py
as soon as we also include Well or something else) may become an important one, since it will also contribute to defining our compliance/support w.r.t OME-NGFF. Some aspects:multiscale
perimage
). This information would be more centralized if a set of validators were in place for each Well/Image/Plate model...lib_ngff.py
modules would also be one way to simplify support for multiple versions in the future (e.g. by usingNgffImageV04
orNgffImageV05
based on the version stored in the zarr attributes).This PR may also affect:
coordinateTransformations
flexible for axes & comply with spec (include channels transformation) #420 (see also logic introduced in Add 2D support for Cellpose & napari workflows task (closes #398) #403, for theextract_zyx_pixel_sizes
function).zattrs
file with accessing zarr attrs #501A note on effort duplication
The same procedure (transorming at least a subset of the NGFF specs into Python models) is already done elsewhere:
If/when one of these efforts grows and/or becomes the officially sanctioned Pydantic version of OME-NGFF (or something we want to rely on, for whatever reason), then we should consider using their models instead of our "custom" ones. The transition would take place by defining a
FractalNgffImage
class that inherits from the "official" one and adds additional methods/properties that are needed for fractal-tasks-core tasks (e.g it would expose anum_levels
property).Neglecting the different attribute names, the change could be as smooth as in: