cellmap_flow.utils.ds

Attributes

logger

Classes

LazyNormalization

Functions

get_scale_info(zarr_grp)

find_target_scale(zarr_grp_path, target_resolution)

ends_with_scale(string)

split_dataset_path(→ tuple[str, str])

Split the dataset path into the filename and dataset

apply_norms(data)

open_ds_tensorstore(dataset_path[, mode, ...])

to_ndarray_tensorstore(dataset[, roi, voxel_size, ...])

Read a region of a tensorstore dataset and return it as a numpy array

get_url(→ str)

separate_store_path(store, path)

sometimes you can pass a total os path to node, leading to

access_parent(node)

Get the parent (zarr.Group) of an input zarr array(ds).

check_for_multiscale(group)

check if multiscale attribute exists in the input group and for any parent level group

check_for_voxel_size(array, order)

checks specific attributes(resolution, scale,

check_for_offset(array, order)

checks specific attributes(offset, transform["translate"]) for offset

check_for_units(array, order)

checks specific attributes(units, pixelResolution["unit"] transform["units"])

check_for_attrs_multiscale(ds, multiscale_group, ...)

checks multiscale attribute of the .zarr or .n5 group

regularize_offset(voxel_size_float, offset_float)

offset is not a multiple of voxel_size. This is often due to someone defining

get_ds_info(path[, mode])

Open a Zarr, N5, or HDF5 dataset as an Array. If the

Module Contents

cellmap_flow.utils.ds.get_scale_info(zarr_grp)
cellmap_flow.utils.ds.find_target_scale(zarr_grp_path, target_resolution)
cellmap_flow.utils.ds.logger
cellmap_flow.utils.ds.ends_with_scale(string)
cellmap_flow.utils.ds.split_dataset_path(dataset_path, scale=None) tuple[str, str]

Split the dataset path into the filename and dataset

Parameters:
  • dataset_path ('str') – Path to the dataset

  • scale ('int') – Scale to use, if present

Returns:

Tuple of filename and dataset

cellmap_flow.utils.ds.apply_norms(data)
class cellmap_flow.utils.ds.LazyNormalization(ts_dataset)
ts_dataset
cellmap_flow.utils.ds.open_ds_tensorstore(dataset_path: str, mode='r', concurrency_limit=None, normalize=True)
cellmap_flow.utils.ds.to_ndarray_tensorstore(dataset, roi=None, voxel_size=None, offset=None, output_voxel_size=None, swap_axes=False, custom_fill_value=None)

Read a region of a tensorstore dataset and return it as a numpy array

Parameters:
  • dataset ('tensorstore.dataset') – Tensorstore dataset

  • roi ('funlib.geometry.Roi') – Region of interest to read

Returns:

Numpy array of the region

cellmap_flow.utils.ds.get_url(node: zarr.Group | zarr.Array) str
cellmap_flow.utils.ds.separate_store_path(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:
  • store (string) – path to store

  • path (string) – path array/group (.n5 or .zarr)

Returns:

returns regularized store and group/array path

Return type:

(string, string)

cellmap_flow.utils.ds.access_parent(node)

Get the parent (zarr.Group) of an input zarr array(ds).

Parameters:

node (zarr.core.Array or zarr.hierarchy.Group) – _description_

Raises:
  • RuntimeError – returned if the node array is in the parent group,

  • or the group itself is the root group

Returns:

parent group that contains input group/array

Return type:

zarr.hierarchy.Group

cellmap_flow.utils.ds.check_for_multiscale(group)

check if multiscale attribute exists in the input group and for any parent level group

Parameters:

group (zarr.hierarchy.Group) – group to check

Returns:

(multiscales attribute body, zarr group where multiscales was found)

Return type:

tuple({}, zarr.hierarchy.Group)

cellmap_flow.utils.ds.check_for_voxel_size(array, order)
checks specific attributes(resolution, scale,

pixelResolution[“dimensions”], transform[“scale”]) for voxel size value in the parent directory of the input array

Parameters:
  • array (zarr.core.Array) – array to check

  • order (string) – colexicographical/lexicographical order

Raises:

ValueError – raises value error if no voxel_size value is found

Returns:

returns physical size of the voxel (unitless)

Return type:

[float]

cellmap_flow.utils.ds.check_for_offset(array, order)
checks specific attributes(offset, transform[“translate”]) for offset

value in the parent directory of the input array

Parameters:
  • array (zarr.core.Array) – array to check

  • order (string) – colexicographical/lexicographical order

Raises:

ValueError – raises value error if no offset value is found

Returns:

returns offset of the voxel (unitless) in respect to

the center of the coordinate system

Return type:

[float]

cellmap_flow.utils.ds.check_for_units(array, order)
checks specific attributes(units, pixelResolution[“unit”] transform[“units”])

for units(nm, cm, etc.) value in the parent directory of the input array

Parameters:
  • array (zarr.core.Array) – array to check

  • order (string) – colexicographical/lexicographical order

Raises:

ValueError – raises value error if no units value is found

Returns:

returns units for the voxel_size

Return type:

[string]

cellmap_flow.utils.ds.check_for_attrs_multiscale(ds, multiscale_group, multiscales)
checks multiscale attribute of the .zarr or .n5 group

for voxel_size(scale), offset(translation) and units values

Parameters:
  • ds (zarr.core.Array) – input zarr Array

  • multiscale_group (zarr.hierarchy.Group) – the group attrs that contains multiscale

  • multiscales ({}) – dictionary that contains all the info necessary to create multiscale resolution pyramid

Returns:

returns (voxel_size, offset, physical units)

Return type:

([float],[float],[string])

cellmap_flow.utils.ds.regularize_offset(voxel_size_float, offset_float)

offset is not a multiple of voxel_size. This is often due to someone defining offset to the point source of each array element i.e. the center of the rendered voxel, vs the offset to the corner of the voxel. apparently this can be a heated discussion. See here for arguments against the convention we are using: http://alvyray.com/Memos/CG/Microsoft/6_pixel.pdf

Parameters:
  • voxel_size_float ([float]) – float voxel size list

  • offset_float ([float]) – float offset list

Returns:

returned offset size that is multiple of voxel size

Return type:

(Coordinate, Coordinate))

cellmap_flow.utils.ds.get_ds_info(path: str, mode: str = 'r')

Open a Zarr, N5, or HDF5 dataset as an Array. If the dataset has attributes resolution and offset, those will be used to determine the meta-information of the returned array.

Parameters:
  • filename – The name of the container “file” (which is a directory for Zarr and N5).

  • ds_name – The name of the dataset to open.

Returns:

A Array pointing to the dataset.