harpy.im.rasterize#
- harpy.im.rasterize(sdata, shapes_name, output_labels_name, out_shape=None, chunks=None, client=None, scale_factors=None, overwrite=False)#
Given a shapes element in a SpatialData object, corresponding masks are created, and added as a labels element to the SpatialData object.
The index of the shapes element will be used as the label in the resulting labels element (
output_labels_name).- Parameters:
sdata (
SpatialData) – The SpatialData object.shapes_name (
str) – The shapes element to be converted to a labels element.output_labels_name (
str) – Name of the resulting labels element that will be added tosdata.out_shape (
tuple[int,int] |None(default:None)) – Output shape of the resulting labels element(y,x). Will be automatically calculated if set to None viasdata[shapes_name].geometry.total_bounds. Ifout_shapeis notNone, withx_min, y_min, x_max, y_max = sdata[shapes_name].geometry.total_bounds, andout_shape[1]<x_maxorout_shape[0]<y_max, then shapes with coordinates outsideout_shapeswill not be in resultingoutput_labels_name. Forshapes_namewith large offset(y_min, x_min), we recommend translating the shapes to the origin, and add the offset via a translation (spatialdata.transformations.Translation).chunks (
int|None(default:None)) – If provided, creation of the labels element will be done in a chunked manner, with data divided into chunks for efficient computation.client (
Client|None(default:None)) – ADaskclient. If specified, a copy ofsdata[shapes_name]will be scattered across the workers, reducing the size of the task graph. If not specified,Daskwill use the default scheduler as configured on your system.client – A Dask
Clientinstance. If specified, a copy of the GeoDataFrame (sdata[shapes_name]) will be scattered across the workers. This reduces the size of the task graph and can improve performance by minimizing data transfer overhead during computation. If not specified, Dask will use the default scheduler as configured on your system (e.g., single-threaded, multithreaded, or a global client if one is running).scale_factors (
Sequence[dict[str,int] |int] |None(default:None)) – Scale factors to apply for multiscale.overwrite (
bool(default:False)) – If True, overwrites theoutput_labels_nameif it already exists insdata.
- Return type:
- Returns:
: An updated SpatialData object with the added labels element.
- Raises:
ValueError – If the provided
shapes_namecontains 3D polygons.ValueError – If the provided
shapes_namecontains Points.ValueError – If 0 is in the index of the
shapes_name. As 0 is used as background in theoutput_labels_name.TypeError – If
chunksis notNoneand not an instance ofint.