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

Review NGFF models & Fractal OME-Zarr models #681

Open
tcompa opened this issue Apr 9, 2024 · 4 comments
Open

Review NGFF models & Fractal OME-Zarr models #681

tcompa opened this issue Apr 9, 2024 · 4 comments

Comments

@tcompa
Copy link
Collaborator

tcompa commented Apr 9, 2024

Within #671, it appears that the MIP-images zattrs do not include wavelength_id in the omero metadata.

Here is how this leads to a cellpose-task error:

TASK ERROR: Task name: Cellpose Segmentation, position in Workflow: 2
TRACEBACK:
2024-04-09 10:02:11,120; INFO; START cellpose_segmentation task
2024-04-09 10:02:11,120; INFO; zarr_url='/somewhere/Fractal/fractal-demos/examples/01_cardio_tiny_dataset/output_cardiac-tiny-c/20200812-CardiomyocyteDifferentiation14-Cycle1_mip.zarr/B/03/0'
2024-04-09 10:02:11,133; INFO; NGFF image has num_levels=5
2024-04-09 10:02:11,133; INFO; NGFF image has coarsening_xy=2
2024-04-09 10:02:11,133; INFO; NGFF image has full-res pixel sizes [1.0, 0.1625, 0.1625]
2024-04-09 10:02:11,133; INFO; NGFF image has level-2 pixel sizes [1.0, 0.65, 0.65]
2024-04-09 10:02:11,133; CRITICAL; {'color': '00FFFF', 'label': 'DAPI', 'window': {'end': 800.0, 'max': 65535.0, 'min': 0.0, 'start': 110.0}}
Traceback (most recent call last):
  File "/somewhere/Fractal/fractal-server/tests/data/example_server_startup/Tasks/.fractal/fractal-tasks-core1.0.0a0/venv/lib/python3.10/site-packages/fractal_tasks_core/tasks/cellpose_segmentation.py", line 719, in <module>
    run_fractal_task(
  File "/somewhere/Fractal/fractal-server/tests/data/example_server_startup/Tasks/.fractal/fractal-tasks-core1.0.0a0/venv/lib/python3.10/site-packages/fractal_tasks_core/tasks/_utils.py", line 79, in run_fractal_task
    metadata_update = task_function(**pars)
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
  File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
  File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
  File "/somewhere/Fractal/fractal-server/tests/data/example_server_startup/Tasks/.fractal/fractal-tasks-core1.0.0a0/venv/lib/python3.10/site-packages/fractal_tasks_core/tasks/cellpose_segmentation.py", line 342, in cellpose_segmentation
    tmp_channel: OmeroChannel = get_channel_from_image_zarr(
  File "/somewhere/Fractal/fractal-server/tests/data/example_server_startup/Tasks/.fractal/fractal-tasks-core1.0.0a0/venv/lib/python3.10/site-packages/fractal_tasks_core/channels.py", line 221, in get_channel_from_image_zarr
    omero_channels = get_omero_channel_list(image_zarr_path=image_zarr_path)
  File "/somewhere/Fractal/fractal-server/tests/data/example_server_startup/Tasks/.fractal/fractal-tasks-core1.0.0a0/venv/lib/python3.10/site-packages/fractal_tasks_core/channels.py", line 243, in get_omero_channel_list
    channels = [OmeroChannel(**c) for c in channels_dicts]
  File "/somewhere/Fractal/fractal-server/tests/data/example_server_startup/Tasks/.fractal/fractal-tasks-core1.0.0a0/venv/lib/python3.10/site-packages/fractal_tasks_core/channels.py", line 243, in <listcomp>
    channels = [OmeroChannel(**c) for c in channels_dicts]
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for OmeroChannel
wavelength_id
  field required (type=value_error.missing)
@tcompa
Copy link
Collaborator Author

tcompa commented Apr 9, 2024

I think the reason is that our ngff models include

class Channel(BaseModel):
    """
    Model for an element of `Omero.channels`.

    See https://ngff.openmicroscopy.org/0.4/#omero-md.
    """

    window: Optional[Window] = None
    label: Optional[str] = None
    family: Optional[str] = None
    color: str
    active: Optional[bool] = None


class Omero(BaseModel):
    """
    Model for `NgffImageMeta.omero`.

    See https://ngff.openmicroscopy.org/0.4/#omero-md.
    """

    channels: list[Channel]

where wavelength_id is not present.

The reason why this was not an issue in previous versions is that we had

                # Replicate image attrs
                old_image_group = zarr.open_group(
                    f"{zarrurl_old}/{well_path}/{image_path}", mode="r"
                )
                new_image_group = zarr.group(
                    f"{zarrurl_new}/{well_path}/{image_path}"
                )
                new_image_group.attrs.put(old_image_group.attrs.asdict())

while we now have

new_image_group.attrs.put(ngff_image.dict(exclude_none=True))

@tcompa
Copy link
Collaborator Author

tcompa commented Apr 9, 2024

Ref #540

@tcompa tcompa added bug Something isn't working fractal_v2 labels Apr 9, 2024
@jluethi
Copy link
Collaborator

jluethi commented Apr 10, 2024

Let's review whether we can get our models more consistent for this (e.g. having FractalChannels inherited from Channels etc.)

@jluethi jluethi added the High Priority Current Priorities & Blocking Issues label Apr 10, 2024
jluethi added a commit that referenced this issue Apr 10, 2024
@jluethi jluethi removed High Priority Current Priorities & Blocking Issues fractal_v2 labels Apr 10, 2024
@jluethi
Copy link
Collaborator

jluethi commented Apr 10, 2024

I put back a version of just using the attrs of the old image for the moment with 4aac820

It's slightly less elegant, as we have to load the metadata twice now (once for the NGFF model for things like number of pyramid levels, once for adding it to the new image). But with that, it's hopefully not a blocker for V2 anymore but something we can address carefully when we get a chance.

[I still think we should find a good way of using those very useful Pydantic models for this purpose, e.g. having Fractal pydantic models we can use. Just wanted to make the registration testing work ;)]

@jluethi jluethi changed the title MIP V2 task not copying some omero metadata? TBD Review NGFF models & Fractal OME-Zarr models Apr 17, 2024
@jluethi jluethi added enhancement New feature or request and removed bug Something isn't working labels Apr 18, 2024
@jluethi jluethi added the ngio label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants