API Reference#

class stack_to_chunk.MultiScaleGroup(path: PathLike[str], *, name: str, voxel_size: tuple[float, float, float], spatial_unit: Literal['angstrom', 'attometer', 'centimeter', 'decimeter', 'exameter', 'femtometer', 'foot', 'gigameter', 'hectometer', 'inch', 'kilometer', 'megameter', 'meter', 'micrometer', 'mile', 'millimeter', 'nanometer', 'parsec', 'petameter', 'picometer', 'terameter', 'yard', 'yoctometer', 'yottameter', 'zeptometer', 'zettameter'], array_spec: ArraySpec | None = None)#

A class for creating and interacting with a OME-Zarr multi-scale group.

Parameters#

path :

Path to zarr group on disk.

name :

Name to save to zarr group.

voxel_size :

Size of a single voxel, in units of spatial_units.

spatial_units :

Units of the voxel size.

array_spec :

Specification for initial dataset array. If opening an existing group does not need to be provided. Must not have dimension names set (they are set automatically by stack-to-chunk).

Warnings#

stack-to-chunk adds sharding to the output, so it’s recommended that the array specification passed here does not already include a sharding codec (if it does, there will be nested shards!)

add_downsample_level(level: int, *, n_processes: int = 1, downsample_func: ~collections.abc.Callable[[~numpy._typing.ArrayLike], ~numpy.ndarray[tuple[~typing.Any, ...], ~numpy.dtype[~numpy._typing._array_like._ScalarT]]] = <function mean>, overwrite: bool = False) None#

Add a level of downsampling.

Parameters#

level :

Level of downsampling. Level i corresponds to a downsampling factor of 2**i.

n_processes :

Number of parallel processes to use to read/write data. See the joblib.Parallel documentation for more info of allowed values. Running with one process (the default) will use about 5/8 the amount of memory of a single slab/shard.

downsample_func :

Function used to downsample data. It can be helpful to set this to stack_to_chunk.mode for label data to calculate the most common label when downsampling.

overwrite :

Set to True to not error if the Zarr group already exists, and overwrite any data and metadata in any existing Zarr group.

Notes#

To add level i to the zarr group, level i - 1 must first have been added.

Running this with one process will use about 5/8 the amount of memory of a single slab/shard.

add_full_res_data(data: Array, *, n_processes: int, start_z_idx: int = 0) None#

Add the ‘original’ full resolution data to this group.

Parameters#

data :

Input data. Must be 3D, and have a chunksize of (nx, ny, 1), where (nx, ny) is the shape of the input 2D slices.

n_processes :

Number of parallel processes to use to read/write data.

start_z_idx :

z-index at which this stack of input data starts. Can be useful to write multiple slabs in parallel using a compute cluster where the job wants to be split into many small individual Python processes.

property chunk_size_z: int#

Get the chunk size along the z-axis.

property levels: list[int]#

List of downsample levels currently stored.

Level 0 corresponds to full resolution data, and level i to data downsampled by a factor of 2**i.

stack_to_chunk.open_multiscale_group(path: Path) MultiScaleGroup#

Open a previously created multiscale zarr group.

Parameters#

path :

Path to existing group.

stack_to_chunk.SPATIAL_UNIT#

alias of Literal[‘angstrom’, ‘attometer’, ‘centimeter’, ‘decimeter’, ‘exameter’, ‘femtometer’, ‘foot’, ‘gigameter’, ‘hectometer’, ‘inch’, ‘kilometer’, ‘megameter’, ‘meter’, ‘micrometer’, ‘mile’, ‘millimeter’, ‘nanometer’, ‘parsec’, ‘petameter’, ‘picometer’, ‘terameter’, ‘yard’, ‘yoctometer’, ‘yottameter’, ‘zeptometer’, ‘zettameter’]