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

add omero metadata to writer #261

Merged
merged 21 commits into from
Nov 24, 2023
Merged

add omero metadata to writer #261

merged 21 commits into from
Nov 24, 2023

Conversation

giovp
Copy link
Contributor

@giovp giovp commented Mar 14, 2023

close #260 .

Validation before write is minimal, feedbacks welcome.

@will-moore
Copy link
Member

Thanks for the PR. I wonder if you would also want to extend the validation a bit, although some of this would be duplicating the schema validation e.g:

  • check that the window has min, max, start, end numbers
  • check that the color is a string

You could even check that the number of omero 'channels' matches the number of channels in the data, although this is a bit more work since you have to handle different axes for different versions to know which is channel dimension. Could be left for now.

@will-moore
Copy link
Member

Hi @giovp - if you could merge in origin/master branch (or rebase onto it) then that should fix some of the broken jobs, thanks

@will-moore will-moore added this to the 0.7.0 milestone Mar 22, 2023
@giovp
Copy link
Contributor Author

giovp commented Mar 22, 2023

hi @will-moore apologies for getting this staled, I hope I will be able to work on it sometime next week. Will rebase as well, and keep you posted, sorry for delay.

@will-moore will-moore removed this from the 0.7.0 milestone Mar 28, 2023
@giovp
Copy link
Contributor Author

giovp commented Mar 31, 2023

@will-moore am back on this and will be able to work on it. I have a question re the overwrite of names in the zarr group.
https://github.com/giovp/ome-zarr-py/blob/58bdf584f10d14c74ed80b9a6ab4a53a58943216/ome_zarr/reader.py#L291

is this desired? what's the logic behind?
thank you!

@will-moore
Copy link
Member

I think the logic there is if you've got no channels then the layer name in napari will be e.g. "myImage" but if you've got channels with names then they will be used for layers instead, "DAPI", "GFP" etc.

@giovp
Copy link
Contributor Author

giovp commented Mar 31, 2023

thanks a lot for the prompt reply, from the ngff specs though seems there can be both? a name and channel names? so why would that be overwritten by Omero reader?

https://ngff.openmicroscopy.org/latest/#omero-md

@will-moore
Copy link
Member

I think this is because the logic in ome-zarr-py was originally built as a napari plugin, so it was designed just to present the best name for each channel.
If you've only got a multiscales name, napari_ome_zarr uses that for each layer:

Screenshot 2023-04-03 at 08 36 19

But if you've got an omero metadata, we can provide better layer names:

Screenshot 2023-04-03 at 08 38 53

But we only have a single place to store that data: node.metadata["name"], so we have to use it for both cases.

It would certainly be an improvement for ome-zarr-py to store both the multiscales name and the omero channel names, so that both are available to all tools - and then napari-ome-zarr could just pick from either to create layer names.

@giovp
Copy link
Contributor Author

giovp commented Apr 3, 2023

But we only have a single place to store that data: node.metadata["name"], so we have to use it for both cases.

It would certainly be an improvement for ome-zarr-py to store both the multiscales name and the omero channel names, so that both are available to all tools - and then napari-ome-zarr could just pick from either to create layer names.

ok great, so would it be ok to keep

node.metadata["name"] = multiscales[0].get("name")

as name of image and use a different one here: https://github.com/giovp/ome-zarr-py/blob/58bdf584f10d14c74ed80b9a6ab4a53a58943216/ome_zarr/reader.py#LL390C13-L390C42
like

node.metadata["channel_names"] = names

?

@will-moore
Copy link
Member

Yes, node.metadata["channel_names"] = names would make sense.
That would be considered a breaking change to ome-zarr-py so it would justify bumping the version, to 0.7.0 I guess; I don't think we're ready to go to 1.0.0 yet.
Then we'd need a corresponding release of napari-ome-zarr that had dependency of ome-zarr-py 0.7.0 and updated logic for reading the channel_names.

@jburel jburel closed this Apr 6, 2023
@jburel jburel reopened this Apr 6, 2023
ome_zarr/reader.py Outdated Show resolved Hide resolved
ome_zarr/writer.py Outdated Show resolved Hide resolved
@will-moore
Copy link
Member

Tests are failing with:

>       if isinstance(metadata, dict) and "omero" in metadata["metadata"]:
E       KeyError: 'metadata'

@codecov
Copy link

codecov bot commented Apr 27, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Files Coverage Δ
ome_zarr/data.py 87.00% <100.00%> (-0.13%) ⬇️
ome_zarr/reader.py 86.70% <100.00%> (-3.97%) ⬇️
ome_zarr/writer.py 94.46% <82.35%> (-0.82%) ⬇️

... and 1 file with indirect coverage changes

📢 Thoughts on this report? Let us know!.

@will-moore
Copy link
Member

Failing (only on python 3.8!) with:

    def test_omero_metadata(self, metadata: Optional[dict[str, Any]]):
E   TypeError: 'type' object is not subscriptable

I think this just needs to be dict -> Dict

@giovp
Copy link
Contributor Author

giovp commented Apr 27, 2023

thanks a lot for prompt feedback and help @will-moore !

Just wanted to clarify one thing regarding metadata: atm, neither color nor windows are mandatory , but if they are present then they should adhere to the types you outlined here: #261 (comment)

therefore, just to recap the specs, they would be as follow:

  • metadata MAY contains "omero"
  • if it does, then it MUST be a "dict" with either "color" or "window", and not be None
  • if it contains "color" then value MUST be string
  • if it contains "window" then value MUST be another dict with min, max, start, end with respective values being int.

is this correct? do you think it'd be worth to update the ngff specs to clarify this?
If this is correct I also plan to create PR in: https://github.com/JaneliaSciComp/pydantic-ome-ngff

ome_zarr/writer.py Outdated Show resolved Hide resolved
@will-moore
Copy link
Member

Apologies for the nit-pick comment. Otherwise I'm happy with this.
@joshmoore @sbesson - any 2nd opinion, or OK for me to merge once I'm happy with it?

@giovp
Copy link
Contributor Author

giovp commented Jul 14, 2023

no problem at all, modified accordingly. Just reminder that this concerns the python implementation of this minor specs change ome/ngff#202

@will-moore
Copy link
Member

thanks - I'm away just now but happy for @joshmoore or @sbesson to merge

@giovp
Copy link
Contributor Author

giovp commented Aug 4, 2023

bump

write_multiscales_metadata(
self.root, datasets, axes="tczyx", metadata={"omero": metadata}
)
elif "color" in metadata["channels"][0]:
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed that with elif here, you'll only test the color validation if there is no window metadata.
Just use if "color".. instead.
But also I don't see that if len(color_metadata) < 6: below is ever true, since all the color in parametrize above are length 6.

@giovp
Copy link
Contributor Author

giovp commented Oct 11, 2023

@will-moore apologies getting back to this only now but it should be fix

@will-moore
Copy link
Member

Hi @giovp - thanks for the update...
Tests are failing with:

    def test_omero(self):
        reader = Reader(parse_url(str(self.path)))()
        image_node = list(reader)[0]
>       omero = image_node.load(Multiscales).zarr.root_attrs.get("omero")
E       NameError: name 'Multiscales' is not defined

Also the Codespell / Check for spelling errors should be fixed by #317 so you can fix that by merging in master branch again.

Thanks!

@giovp
Copy link
Contributor Author

giovp commented Oct 26, 2023

hi @will-moore , test should be fixed, passes locally, sorry again for getting back to you so late

Copy link
Member

@will-moore will-moore left a comment

Choose a reason for hiding this comment

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

Great, thanks - apologies for the delay. All tests passing now 👍

@giovp
Copy link
Contributor Author

giovp commented Nov 24, 2023

looks like it can be merged?

@will-moore
Copy link
Member

@giovp yes, apologies we missed this at the last release.
@joshmoore You OK to merge this?

@joshmoore joshmoore merged commit 371f7f5 into ome:master Nov 24, 2023
13 checks passed
@joshmoore
Copy link
Member

Anything else otherwise I'll push out a quick 0.8.4

@will-moore
Copy link
Member

Thanks Josh - No I don't see any others ready to go. There have been a couple of docs and tox/deps PRs merged recently.
I noticed some build failures https://github.com/ome/ome_zarr_test_suite/actions/workflows/main.yml but I'm not sure why yet.

@joshmoore
Copy link
Member

ewwww

RecursionError: maximum recursion depth exceeded in __instancecheck__

on ome_zarr info

@will-moore
Copy link
Member

I can't work out exactly where that's coming from or how to reproduce it locally

@will-moore
Copy link
Member

I wonder if the recursion error is related to similar recursion errors noted at #339

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.

writer for omero metadata
4 participants