sparrow.io.create_sdata

Contents

sparrow.io.create_sdata#

sparrow.io.create_sdata(input, output_path=None, img_layer='raw_image', chunks=None, dims=None, crd=None, to_coordinate_system='global', scale_factors=None, c_coords=None, z_projection=True)#

Convert input images or arrays into a SpatialData object with the image added as an image layer with name img_layer.

This function allows you to ingest various input formats of images or data arrays, convert them into a unified SpatialData format and write them out to a specified path (zarr store) if needed. It provides flexibility in how you define the source data as well as certain processing options like chunking.

The input parameter can be formatted in four ways:

    1. Path to a single image, either grayscale or multiple channels.

Examples

input=’DAPI_z3.tif’ -> single channel

input=’DAPI_Poly_z3.tif’ -> multi (DAPI, Poly) channel

  • 2. Pattern representing a collection of z-stacks (if this is the case, a z-projection is performed which selects the maximum intensity value across the z-dimension).

Examples

input=’DAPI_z*.tif’ -> z-projection performed

input=’DAPI_Poly_z*.tif’ -> z-projection performed

    1. List of filename patterns (where each list item corresponds to a different channel)

Examples

input=[ ‘DAPI_z3.tif’, ‘Poly_z3.tif’ ] -> multi (DAPI, Poly) channel

input=[ ‘DAPI_z*.tif’, ‘Poly_z*.tif’ ] -> multi (DAPI, Poly) channel, z projection performed

  • 4. Single numpy or dask array. The dims parameter should specify its dimension, e.g. [‘y’,’x’] for a 2D array or [ ‘c’, ‘y’, ‘x’, ‘z’ ] for a 4D array with channels. If a z-dimension >1 is present, a z-projection is performed.

Parameters:
  • input (str | Path | ndarray | Array | list[str] | list[Path] | list[ndarray] | list[Array]) – The filename pattern, path or list of filename patterns to the images that should be loaded. In case of a list, each list item should represent a different channel, and each image corresponding to a filename pattern should represent. a different z-stack. Input can also be a numpy array. In that case the dims parameter should be specified.

  • output_path (Union[str, Path, None] (default: None)) – If specified, the resulting SpatialData object will be written to this path as a zarr.

  • img_layer (str (default: 'raw_image')) – The name of the image layer to be created in the SpatialData object.

  • chunks (Union[str, tuple[int, int, int, int], int, None] (default: None)) – If specified, the underlying dask array will be rechunked to this size. If Tuple, desired chunksize along c,z,y,x should be specified, e.g. (1,1,1024,1024).

  • dims (Optional[list[str]] (default: None)) – The dimensions of the input data if it’s a numpy array. E.g., [‘y’,’x’] or [‘c’,’y’,’x’,’z’]. If input is a str, Path or List[str], List[Path], this parameter is ignored.

  • crd (Optional[tuple[int, int, int, int]] (default: None)) – The coordinates for a region of interest in the format (xmin, xmax, ymin, ymax). If specified, this region is cropped from the image, and added as image layer to the SpatialData object.

  • to_coordinate_system (str (default: 'global')) – Coordinate system to which img_layer will be added.

  • scale_factors (Optional[Sequence[Union[dict[str, int], int]]] (default: None)) – Scale factors to apply for multiscale.

  • c_coords (Union[int, str, Iterable[int | str], None] (default: None)) – Names of the channels in the input image. If None, channel names will be named sequentially as 0,1,…

  • z_projection (bool (default: True)) – Whether to perform a z projection (maximum intensity projection along the z-axis).

Return type:

SpatialData

Returns:

: The constructed SpatialData object containing image layer with name img_layer and dimension (c,(z),y,x)

Notes

If crd is specified and some of its values are None, the function infers the missing values based on the input image’s shape.