zarr
insert_omero_metadata #
insert_omero_metadata(src, window_max=None, window_min=None, window_start=None, window_end=None, id=None, name=None, dry_run=False)
Insert or update missing omero transitional metadata into .zattrs metadata of parent group for the input zarr array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Path to Zarr array. |
required |
window_max
|
int
|
Max view window value. Defaults to None. |
None
|
window_min
|
int
|
Min view window value. Defaults to None. |
None
|
window_start
|
int
|
Contrast min value. Defaults to None. |
None
|
window_end
|
int
|
Contrast max value. Defaults to None. |
None
|
id
|
int
|
Defaults to None. |
None
|
name
|
str
|
Name of the dataset. Defaults to None. |
None
|
dry_run
|
bool
|
if True, compute the omero metadata but do not write it to the group's attrs. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
the omero metadata that was written (or would have been written, if dry_run is True). |
Source code in src/cellmap_utils/zarr/metadata.py
get_single_scale_metadata #
get_single_scale_metadata(ds_name, voxel_size, translation, name, units='nanometer', axes=['z', 'y', 'x'])
Returns multiscales ngff metadata with a single level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds_name
|
str
|
name of the dataset that contains the data. |
required |
voxel_size
|
list[float]
|
scale. Example: [1.0, 1.0, 1.0] |
required |
translation
|
list[float]
|
offset. Example: [0.0, 0.0, 0.0] |
required |
name
|
str
|
Name of a multiscale set. |
required |
units
|
str
|
Physical units. Defaults to 'nanometer'. |
'nanometer'
|
axes
|
list[str]
|
Axes labeling. Defaults to ['z', 'y', 'x']. |
['z', 'y', 'x']
|
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
description |
Source code in src/cellmap_utils/zarr/metadata.py
get_multiscale_metadata #
get_multiscale_metadata(voxel_size, translation, levels, units='nanometer', axes=['z', 'y', 'x'], name='')
Generates a multiscale metadata from specified voxel size, offset and multi-scale pyramid levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_size
|
list[float]
|
physical size of the voxel |
required |
translation
|
list[float]
|
physical translation of the center of the voxel. |
required |
levels
|
int
|
how many levels are present in the multis-scale pyramid. |
required |
units
|
str
|
Physical units. Defaults to 'nanometer'. |
'nanometer'
|
axes
|
list[str]
|
Axis order. Defaults to ['z', 'y', 'x']. |
['z', 'y', 'x']
|
name
|
str
|
Name of the dataset that would utilize multi-scale metadata. Defaults to ''. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
description |
Source code in src/cellmap_utils/zarr/metadata.py
ome_ngff_only #
Delete all attrs from .zattrs that are not part of the OME-NGFF Zarr spec and CellMap metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zg
|
Group
|
zarr group that contains multiscale metadata. |
required |
dry_run
|
bool
|
if True, compute which attrs would be deleted but do not delete them. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
the attr names that were deleted (or would have been deleted, if dry_run is True). |
Source code in src/cellmap_utils/zarr/metadata.py
round_decimals #
Round scale and translation metadata
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
Group
|
zarr group with ome-zarr metadata |
required |
decimals
|
int
|
number of decimals to round |
required |
dry_run
|
bool
|
if True, compute the rounded metadata but do not write it back to the group's attrs. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
the rounded 'multiscales' metadata that was written (or would have been written, if dry_run is True). |
Source code in src/cellmap_utils/zarr/metadata.py
get_s0_level #
Read the base (s0) level's scale and translation.
Supports both OME-NGFF 0.4 (Zarr v2 stores) and OME-NGFF 0.5 (Zarr v3 stores). Requires the optional 'zarr3' extra (ome-zarr-models).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zg
|
Group
|
zarr group with OME-NGFF multiscale metadata. |
required |
strict
|
bool
|
if True (default), require full OME-NGFF schema validation, and raise if it fails. If False, fall back to a best-effort, unvalidated read of the attrs when schema validation fails, instead of raising. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Tuple[list[float], list[float]]
|
Tuple[list[float], list[float]]: (scale, translation) of the s0 level. |
Source code in src/cellmap_utils/zarr/metadata.py
remove_checksum #
Remove checksum parameter from zarr array metadata, to make it compatible with tensorstore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_to_arr
|
str
|
path to Zarr array |
required |
dry_run
|
bool
|
if True, compute the corrected metadata but do not write it back to the .zarray file. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
the array metadata with the checksum removed (or that would have been written, if dry_run is True). |
Source code in src/cellmap_utils/zarr/metadata.py
access_parent #
Get the parent (zarr.Group) of an input zarr array(ds).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Array or Group
|
description |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
returned if the node array is in the parent group, |
Returns:
| Type | Description |
|---|---|
|
zarr.hierarchy.Group : parent group that contains input group/array |
Source code in src/cellmap_utils/zarr/node.py
repair_zarr_branch #
A recursive methond that adds missing .zgroup file in any parent zarr group between input zarr group and root of the zarr container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_zarr_path
|
str
|
description |
required |
dry_run
|
bool
|
if True, only report which paths are missing a .zgroup file, without writing anything. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
paths that had a .zgroup file written (or that would have, if dry_run is True). |
Source code in src/cellmap_utils/zarr/node.py
get_matching_scale #
Find the roi pyramid level whose scale matches the dataset's s0 scale.
Supports both OME-NGFF 0.4 (Zarr v2 stores) and OME-NGFF 0.5 (Zarr v3 stores). Requires the optional 'zarr3' extra (ome-zarr-models).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Group
|
dataset zarr group with a multiscale pyramid. |
required |
roi
|
Group
|
roi zarr group with a multiscale pyramid. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[list[float], list[float]]
|
Tuple[list[float], list[float]]: (matching roi scale, matching roi translation) |
Source code in src/cellmap_utils/zarr/roi.py
get_normalized_scale #
Correct a dataset's voxel size to match the reference pyramid level that has the same array shape.
This is useful when a dataset (for example, a segmentation) was labeled with the wrong voxel size, but its array shape matches one of the levels of a trusted reference multiscale image. The scale of the matching reference level is treated as the correct voxel size for the dataset. The dataset's translation (offset) is not changed, because translation already stores an absolute physical position in nanometers, and does not depend on the scale label.
Supports both OME-NGFF 0.4 (Zarr v2 stores) and OME-NGFF 0.5 (Zarr v3 stores). Requires the optional 'zarr3' extra (ome-zarr-models).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Group
|
reference zarr group with a multiscale pyramid. |
required |
dataset
|
Group
|
dataset zarr group to normalize, for example a segmentation. |
required |
dataset_level
|
str
|
path of the dataset level to normalize. Defaults to 's0'. |
's0'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
{'scale': matched reference scale, 'translation': dataset's own translation, unchanged} |
Source code in src/cellmap_utils/zarr/roi.py
apply_normalized_scale #
Write a corrected scale into a dataset's OME-NGFF metadata.
Use this after get_normalized_scale() to save its result. Only the scale for dataset_level changes. The translation already in the dataset's metadata is not touched.
Supports both OME-NGFF 0.4 (top-level "multiscales" attrs key) and OME-NGFF 0.5 ("ome" -> "multiscales" attrs key).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Group
|
dataset zarr group to update. |
required |
dataset_level
|
str
|
path of the level to update. Example: 's0'. |
required |
normalized
|
dict
|
output of get_normalized_scale(). Must have a 'scale' key. |
required |
dry_run
|
bool
|
if True (default), compute the updated metadata but do not write it to the group's attrs. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
the full 'multiscales' metadata that was written, or that would have been written if dry_run is True. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if dataset_level is not present in the dataset's metadata. |
Source code in src/cellmap_utils/zarr/roi.py
recalibrate_offset #
The offset of the roi at multiscale level with scale=grid_spacing must be divisible by grid_spacing. This method would recalibrate offset, if roi grid does not align with grid {scale : grid_spacing, translation : [0.0, 0.0, 0.0]}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roi
|
Group
|
roi zarr group with multiscale pyramid |
required |
grid_spacing
|
list[float]
|
grid spacing, with assumption that translation=[0.0, 0.0, 0.0] |
required |
Returns:
| Type | Description |
|---|---|
Tuple[list[float], list[float]]
|
Tuple[list[float], list[float]]: returns (ROI s0 scale, recalibrated offset) |
Source code in src/cellmap_utils/zarr/roi.py
separate_store_path #
sometimes you can pass a total os path to node, leading to an empty('') node.path attribute. the correct way is to separate path to container(.n5, .zarr) from path to array within a container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
string
|
path to store |
required |
path
|
string
|
path array/group (.n5 or .zarr) |
required |
Returns:
| Type | Description |
|---|---|
(string, string)
|
returns regularized store and group/array path |
Source code in src/cellmap_utils/zarr/store.py
is_valid_ome #
Check whether a zarr group's OME-NGFF metadata validates, without raising.
Supports both OME-NGFF 0.4 (Zarr v2 stores) and OME-NGFF 0.5 (Zarr v3 stores). Requires the optional 'zarr3' extra (ome-zarr-models).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zg
|
Group
|
the zarr group to check. |
required |
version
|
str
|
restrict the check to a specific OME-NGFF version ('0.4', '0.5', or '0.6'). Defaults to None, which tries every version. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the metadata validates against a known OME-NGFF model, False otherwise. |
Source code in src/cellmap_utils/zarr/validate.py
validate_ome #
Validate that a zarr group has well-formed OME-NGFF multiscale metadata.
Supports both OME-NGFF 0.4 (Zarr v2 stores) and OME-NGFF 0.5 (Zarr v3 stores).
Requires the optional 'zarr3' extra (ome-zarr-models). Raises if the metadata
does not validate against any known OME-NGFF version. Use is_valid_ome()
instead if you want a boolean result rather than an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zg
|
Group
|
the input zarr group to validate. |
required |