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 support for label properties in zattrs and plugin #61

Merged
merged 8 commits into from
Nov 30, 2020

Conversation

DragaDoncila
Copy link

Add support for label properties of the form

        "properties": [
            {
                "label-value": 1,
                "class": "Urban",
                "m2": "100"
            },
            {
                "label-value": 2,
                "class": "Water",
                "m2": "200"

            },
            {
                "label-value": 3,
                "class": "Deciduous Woody Horticulture"

            },
            {
                "label-value": 4,
                "class": "Evergreen Woody Horticulture"

            },
            ...

as discussed in #60 .

Read these properties in as dictionary of label-value to properties.

Transform these properties in the napari reader to:

{
    "index": [
        1,
        2,
        3,
        4,
       ...
    ],
    "class": [
        "Urban",
        "Water",
        "Deciduous Woody Horticulture",
        "Evergreen Woody Horticulture",
        ...
    ],
    "m2": [
        "100",
        "200",
        "None",
        "None",
        "None",
       ...
    ]
}

This is the very first pass, so would appreciate feedback on the general approach before I move on to updating spec, documentation, tests, etc.

We probably also wish to consider what types of property keys and values we want to accept.

Comment on lines 223 to 225
label_val = props['label-value']
del props['label-value']
properties[label_val] = props
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain what's happening here? We'll need to check whether the underlying dictionary is a deep-copy of the original, or whether it returns a reference which means this may update the properties seen by other code.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if I do image_label.get('properties', []) after this for loop, I get the properties without the label-values so you probably should create a copy of the props before editing.
This seems to work:

                properties[label_val] = dict(props)
                del properties[label_val]['label-value']

# napari expects lists of equal length so we must fill with None
for prop_key in all_keys:
reader_props[prop_key] = [
props[i][prop_key] if prop_key in props[i] else "None"
Copy link
Member

Choose a reason for hiding this comment

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

This can probably be an actual None value here instead of a string "None" (unless it has to be a string for some reason). Since if some code is testing for the value being None, then the string won't be recognised as None.

@will-moore
Copy link
Member

This works fine for me. Can see the values in napari (bottom left) when hovering over the mask:

Screenshot 2020-11-16 at 14 05 01

Few minor comments but generally looking good.

@joshmoore
Copy link
Member

Pushed a commit to update the miniconda action since it looks like your PR was running into:

Error: Unable to process command '::set-env name=CONDA_PKGS_DIR::/home/runner/conda_pkgs_dir' successfully.
25
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

@DragaDoncila
Copy link
Author

Pushed a commit to update the miniconda action since it looks like your PR was running into:

Error: Unable to process command '::set-env name=CONDA_PKGS_DIR::/home/runner/conda_pkgs_dir' successfully.
25
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

Thanks for this, pre-commit was giving me the run around...

@DragaDoncila
Copy link
Author

DragaDoncila commented Nov 20, 2020

@joshmoore I've added a test to test_napari.py for label properties. I was going to add one to test_reader.py as well but it looks like that doesn't really check metadata. Is there anywhere else I should add tests?

Aside from tests I've now also added a PR for the spec update - I hope that's the right approach. What else needs doing to fully incorporate the label properties into the package?

@joshmoore
Copy link
Member

Ah, @DragaDoncila. Sorry, I see I owe(d) you a comment regarding the spec & more tests. Your PR against omero-ms-zarr was perfect and against the right repo at the time. 💯 You saw that I migrated it. Further PRs welcome against ome/zarr. 😄 Regarding tests, I imagine there will need to be a new file created for what you were wanted to accomplish. Feel free to open a new PR if you're interested. All the best, ~Josh

Merging along with ome/ngff#3

@joshmoore joshmoore merged commit 8cfe679 into ome:master Nov 30, 2020
OME Zarr HCS (Fall 2020) automation moved this from In progress to Done Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants