OME-ZARR conversion plugin
Write any array or image file to a pyramidal OME-ZARR store, add resolution
levels to an existing store, or store a label image inside an OME-ZARR under
the NGFF labels/ group. Uses only the core dependencies for arrays and
.zarr inputs; reading other file formats needs the optional bioio extra
(pip install "patchworks[bioio]").
Pyramids downsample X and Y only — Z (and channel/time) are kept at full
resolution, matching anisotropic microscopy stacks.
to_ome_zarr
patchworks.plugins.ome_zarr.to_ome_zarr(source: Union[da.Array, np.ndarray, str, Path], out_path: Union[str, Path], *, axes: Union[str, None] = None, pixel_size: Union[PixelSize, tuple, None] = None, scene: int = 0, n_levels: int = 5, downscale: int = 2, chunks: Union[tuple[int, ...], None] = None, shard: ShardSpec = False, reuse_pyramid: bool = False, progress: bool = True, overwrite: bool = False) -> str
Write source as a pyramidal, calibrated OME-ZARR store.
source may be a dask/NumPy array, a .zarr store, an Imaris .ims
file, or any image format readable by bioio (CZI, LIF, ND2, OME-TIFF, …).
File inputs are read lazily; the pyramid is built level-by-level from disk
with bounded chunks, so the full volume never needs to fit in RAM. Only
x/y are downsampled; z (and channel/time) stay full-resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
(Array, ndarray, str or Path)
|
Array or path to convert. |
required |
out_path
|
str or Path
|
Destination |
required |
axes
|
str
|
One character per array dimension, e.g. |
None
|
pixel_size
|
(dict, tuple or None)
|
Physical voxel size in micrometers, as |
None
|
scene
|
int
|
Scene index for multi-scene bioio files. |
0
|
n_levels
|
int
|
Maximum number of pyramid levels including full resolution. |
5
|
downscale
|
int
|
Per-level X/Y downsampling factor (default 2). |
2
|
chunks
|
tuple of int
|
Chunk shape for the written levels. |
None
|
shard
|
bool or tuple of int
|
Pack many chunks into one shard file (zarr v3), cutting the file count
~100× on huge arrays. |
False
|
progress
|
bool
|
Show a per-level dask progress bar (default |
True
|
reuse_pyramid
|
bool
|
Imaris |
False
|
overwrite
|
bool
|
Overwrite an existing store at out_path. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The path to the written store ( |
Examples:
>>> from patchworks.plugins.ome_zarr import to_ome_zarr
>>> to_ome_zarr("scan.ims", "scan.zarr", n_levels=4)
'scan.zarr'
Source code in src/patchworks/plugins/ome_zarr.py
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 | |
add_pyramid
patchworks.plugins.ome_zarr.add_pyramid(group_path: Union[str, Path], *, base: str = '0', axes: Union[str, None] = None, pixel_size: Union[PixelSize, tuple, None] = None, n_levels: int = 5, downscale: int = 2, chunks: Union[tuple[int, ...], None] = None, shard: ShardSpec = False, progress: bool = True) -> str
Add downsampled pyramid levels to an existing single-resolution zarr.
Reads the full-resolution array already at group_path/base, writes the
missing levels next to it (lazily, from disk), and (re)writes the NGFF
multiscales metadata. Existing calibration is preserved; pass
pixel_size to set it.
Returns:
| Type | Description |
|---|---|
str
|
The path to the updated group. |
Source code in src/patchworks/plugins/ome_zarr.py
write_labels
patchworks.plugins.ome_zarr.write_labels(image_store: Union[str, Path], labels: Union[da.Array, np.ndarray], *, name: str = 'labels', axes: Union[str, None] = None, pixel_size: Union[PixelSize, tuple, None] = None, n_levels: int = 5, downscale: int = 2, chunks: Union[tuple[int, ...], None] = None, shard: ShardSpec = False, progress: bool = True, overwrite: bool = False) -> str
Store labels inside image_store under the NGFF labels/ group.
The labels are written as their own multi-scale pyramid at
image_store/labels/<name>/ and registered in
image_store/labels/.zattrs, so the image and its segmentation live in a
single OME-ZARR store. Calibration is inherited from the parent image
unless pixel_size is given.
Returns:
| Type | Description |
|---|---|
str
|
Path to the written label group ( |
Source code in src/patchworks/plugins/ome_zarr.py
register_labels
patchworks.plugins.ome_zarr.register_labels(image_store: Union[str, Path], name: str = 'labels', *, axes: Union[str, None] = None, pixel_size: Union[PixelSize, tuple, None] = None, n_levels: int = 5, downscale: int = 2, chunks: Union[tuple[int, ...], None] = None, shard: ShardSpec = False, progress: bool = True) -> str
Pyramidalise and register an existing labels/<name>/0 base level.
Assumes the full-resolution label array already exists at
image_store/labels/<name>/0. Adds the downsampled levels, tags the
group with NGFF image-label metadata, lists name in
labels/.zattrs, and inherits the parent image's pixel calibration
(unless pixel_size is given).
Returns:
| Type | Description |
|---|---|
str
|
Path to the label group ( |