squidpy.gr.mask_graph
- squidpy.gr.mask_graph(sdata, table_key, polygon_mask, negative_mask=False, spatial_key='spatial', key_added='mask', copy=False)[source]
Mask the graph based on a polygon mask.
Given a spatial graph stored in
anndata.AnnData.obsp['{{key_added}}_{{spatial_key}}_connectivities']and spatial coordinates stored inanndata.AnnData.obsp['{{spatial_key}}'], it maskes the graph so that only edges fully contained in the polygons are kept.- Parameters:
sdata (
SpatialData) – The spatial data object.table_key (
str) – The key of the table containing the spatial data.polygon_mask (
Polygon|MultiPolygon) – Theshapely.Polygonorshapely.MultiPolygonto be used as mask.negative_mask (
bool) – Whether to keep the edges within the polygon mask or outside. Note that whennegative_mask = True, only the edges fully contained in the polygon are removed. If edges are partially contained in the polygon, they are kept.spatial_key (
str) – Key inanndata.AnnData.obsmwhere spatial coordinates are stored.key_added (
str) – Key which controls where the results are saved ifcopy = False.copy (
bool) – IfTrue, return the result, otherwise save it to theadataobject.
- Return type:
- Returns:
If
copy = True, returns atuplewith the masked spatial connectivities and masked distances matrices.Otherwise, modifies the
adatawith the following keys:anndata.AnnData.obsp['{{key_added}}_{{spatial_key}}_connectivities']- the spatial connectivities.anndata.AnnData.obsp['{{key_added}}_{{spatial_key}}_distances']- the spatial distances.anndata.AnnData.uns['{{key_added}}_{{spatial_key}}']-dictcontaining parameters.
Notes
The polygon_mask must be in the same coordinate_systems of the spatial graph, but no check is performed to assess this.