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

[feature wish] Convenience function to load label that is closest in resolution to the provided pixel_size #29

Open
jluethi opened this issue Feb 7, 2025 · 1 comment
Labels

Comments

@jluethi
Copy link

jluethi commented Feb 7, 2025

During the napari-ome-zarr-navigator refactor to ngio (see fractal-napari-plugins-collection/napari-ome-zarr-navigator#31), I've looked for a way to do the following:
Given the pixel size of my intensity image, load the label image that is closest to it in resolution. If "closest" means 4x downsampled, that's totally fine.

I tried this:

img_pixel_size = ome_zarr_image.get_image(path=level).pixel_size
ngio_label = ome_zarr_image.labels.get_label(name=label, pixel_size=img_pixel_size)

but get:

File ~/mambaforge/envs/navigator_ngio/lib/python3.10/site-packages/ngio/ngff_meta/fractal_image_meta.py:997, in BaseMeta._get_dataset_by_pixel_size(self=<ngio.ngff_meta.fractal_image_meta.LabelMeta object>, pixel_size=PixelSize(x=0.1625, y=0.1625, z=1.0, unit=<SpaceUnits.micrometer: 'micrometer'>, virtual=False), strict=True, tol=1e-06)
    996 if strict and min_dist > tol:
--> 997     raise ValueError("No dataset with a pixel size close enough.")
    999 return closest_dataset

ValueError: No dataset with a pixel size close enough.

It looks like there is a strict mode at play here. Would it work with strict=False? If so, can we expose that for get_label?

I had a way to do that with my old ome-zarr-image model class, see https://github.com/fractal-napari-plugins-collection/napari-ome-zarr-navigator/blob/0356e8854075555267dfc86e037aee739a691ffe/src/napari_ome_zarr_navigator/ome_zarr_image.py#L240

@lorenzocerrone
Copy link
Collaborator

lorenzocerrone commented Feb 13, 2025

Setting strict to false would fix this issue, and the logic is fully implemented. But this has not yet been exposed in the API.

Before exposing it, we need to decide if we want to also expose the dynamic scaling of the images when loading the array.

If the answer is no, we can expose the strict: bool = True.
If the answer is yes, it would be better to have something like mode: Literal["strict", "closest", "dynamic"] = "strict"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants