Skip to content

Conversation

@will-moore
Copy link
Member

@will-moore will-moore commented Dec 17, 2024

NB: this is on top of #404 (reading OME-Zarr v0.5), which needs to be reviewed & merged first

This PR adds support for writing OME-Zarr v0.5, which becomes the default CurrentFormat().

If you want to choose e.g. v0.4, this is specified in parse_url():

    store = parse_url(path, mode="w", fmt=FormatV04()).store
    root = zarr.group(store=store)
    write_image(image=data, group=root)

This creates a zarr v2 store and group. So when we write_image() with that group, we know that we want to use v0.4 rather than v0.5. The default fmt for write_image() and other write... methods is now None rather than CurrentFormat(), so that we can detect when a user hasn't specified a format and pick the right one.

if you try to use a mix of formats, e.g. v04 and v05, this will throw an Exception:

    store = parse_url(path, mode="w", fmt=FormatV04()).store
    root = zarr.group(store=store)
    write_image(image=data, group=root, fmt=FormatV05())

Same with this, since parse_url() will use CurrentFormat():

    store = parse_url(path, mode="w").store
    root = zarr.group(store=store)
    write_image(image=data, group=root, fmt=FormatV04())

Known issues:

../ome_zarr/writer.py:589: in write_image
    dask_delayed_jobs = _write_dask_image(
../ome_zarr/writer.py:709: in _write_dask_image
    da.to_zarr(
../../../../opt/anaconda3/envs/omeroweb_zarrv3/lib/python3.12/site-packages/dask/array/core.py:3934: in to_zarr
    z = zarr.create(
../../../../opt/anaconda3/envs/omeroweb_zarrv3/lib/python3.12/site-packages/zarr/api/synchronous.py:712: in create
    sync(
../../../../opt/anaconda3/envs/omeroweb_zarrv3/lib/python3.12/site-packages/zarr/core/sync.py:163: in sync
    raise return_result
../../../../opt/anaconda3/envs/omeroweb_zarrv3/lib/python3.12/site-packages/zarr/core/sync.py:119: in _runner
    return await coro
../../../../opt/anaconda3/envs/omeroweb_zarrv3/lib/python3.12/site-packages/zarr/api/asynchronous.py:1055: in create
    return await AsyncArray._create(
...
            if compressor != "auto":
>               raise ValueError(
                    "compressor cannot be used for arrays with zarr_format 3. Use bytes-to-bytes codecs instead."
                )
E               ValueError: compressor cannot be used for arrays with zarr_format 3. Use bytes-to-bytes codecs instead.

Testing:

  • Reading via napari-ome-zarr... images and plates, v0.1, 0.3, 0.4, 0.5...

    • $ napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/9836844.zarr
    • $ napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/idr0079A/9836998.zarr
    • $ napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0072B/9512.zarr
    • $ napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0083/9822152.zarr
    • $ napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0010/76-45.ome.zarr
  • See the changes in docs/source/python.rst and test the various code samples. By default, the examples will write OME-Zarr v0.5. Also try writing v0.4 as described.

will-moore and others added 30 commits October 26, 2024 23:03
Fixes TypeError: Unsupported type for store_like: 'LocalPath'
@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/reading-ome-zarr-v0-5-with-python/114280/4

@ralfox
Copy link

ralfox commented Jul 3, 2025

@will-moore
Copy link
Member Author

Thanks @ralfox - I'm away now and all next week but will get back to this on return...

@will-moore
Copy link
Member Author

It looks like the docs in this PR are working OK based on my testing and the comment and the last comment on the forum discussion above: https://forum.image.sc/t/reading-ome-zarr-v0-5-with-python/114280/4.

@will-moore
Copy link
Member Author

Apologies @ralfox - the confusing and unnecessary line: store = parse_url(url, mode="r").store should be removed from the example code...

@will-moore will-moore force-pushed the ome-zarr-v0.5_writing branch from 15a1df5 to 1cf5273 Compare July 23, 2025 11:08
@jburel jburel mentioned this pull request Jul 31, 2025
Copy link
Member

@joshmoore joshmoore left a comment

Choose a reason for hiding this comment

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

Really only one main thought re: --version, otherwise super excited to get this out. ❤️

ome_zarr/cli.py Outdated
)
parser_create.add_argument("path")
parser_create.add_argument(
"--version", help="OME-Zarr version to create. e.g. '0.4'"
Copy link
Member

Choose a reason for hiding this comment

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

--version is kinda universally "tell me the current version of the library". I could see calling this --format and then if need be, it could even take a class name.

Copy link
Member Author

@will-moore will-moore Aug 7, 2025

Choose a reason for hiding this comment

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

done in 1a5b773

# skip test - can't get this to pass. Fails with:
# ValueError: compressor cannot be used for arrays with zarr_format 3.
# Use bytes-to-bytes codecs instead.
pytest.skip("Dask arrays not supported with zarr v3")
Copy link
Member

Choose a reason for hiding this comment

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

Just adding a written reminder of our chat: 👍 for having a reproducer for this.

@dyf
Copy link

dyf commented Aug 6, 2025

Really only one main thought re: --version, otherwise super excited to get this out. ❤️

Nothing to add, just very excited for this to land!

@joshmoore
Copy link
Member

Thanks, @will-moore! Moving forward with the RC.

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.

5 participants