sparrow.im.add_grid_labels_layer#
- sparrow.im.add_grid_labels_layer(sdata, shape, size, output_shapes_layer, output_labels_layer, grid_type='hexagon', offset=(0, 0), chunks=None, client=None, transformations=None, scale_factors=None, overwrite=False)#
Adds a grid-based labels layer to the SpatialData object using either a hexagonal or square grid.
The function creates a corresponding shapes layer based on the specified grid type and parameters.
- Parameters:
sdata – The SpatialData object to which the new grid-based labels layer and shapes layer will be added.
shape (
tuple[int,int]) – The (y, x) shape of the resulting labels layer. This defines the grid’s size in terms of height (y) and width (x).size (
int) – The size of the grid cells. For a hexagonal grid, this is the radius of the hexagons; for a square grid, this is the side length of the squares.output_shapes_layer (
str) – The name of the shapes layer that corresponds to the generated grid. This layer will contain the polygons representing the grid’s shapes.output_labels_layer (
str) – The name of the labels layer that corresponds to the generated grid. This layer will contain the labels generated from the shapes.grid_type (
Literal['hexagon','square'] (default:'hexagon')) – The type of grid to create. Can be either"hexagon"for a hexagonal grid or"square"for a square grid. The default is"hexagon".offset (
tuple[int,int] (default:(0, 0))) – An optional translation offset applied to the grid. This is a tuple(y_offset, x_offset)that can shift the grid. Default is(0, 0), but it is recommended to use a zero offset, and specify the offset via passing aspatialdata.transformations.Translationtotransformations.chunks (
int|None(default:None)) – Specifies the chunk size for Dask arrays when calculating the labels layer.client (
Client|None(default:None)) – A DaskClientinstance, which will be passed to ‘sparrow.im.rasterize’ (function which rasterizes the generatedoutput_shapes_layer) if specified. Refer to the ‘sparrow.im.rasterize’ docstring for further details.transformations (
dict[str,BaseTransformation] |None(default:None)) – Transformations that will be added to the resultingoutput_shapes_layerandoutput_labels_layer.scale_factors (
Sequence[dict[str,int] |int] |None(default:None)) – Scale factors to apply for multiscale. Only applies tooutput_labels_layer.overwrite (
bool(default:False)) – If True, overwrites theoutput_shapes_layerandoutput_labels_layerif it already exists insdata.
- Return type:
SpatialData- Returns:
: The updated SpatialData object with the newly added grid-based shapes and labels layers.
- Raises:
ValueError – If an unsupported grid type is specified. The valid options are
"hexagon"or"square".
Notes
The function first generates a grid of shapes (either hexagons or squares) based on the specified grid type and parameters. These shapes are added as a new shapes layer in
sdata. Then, a corresponding labels layer is generated from the shapes layer. The labels layer has the same spatial dimensions as specified inshape.