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['{spatial_key}_connectivities']and spatial coordinates stored inanndata.AnnData.obsm['{spatial_key}'], it masks 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 The
shapely.Polygonorshapely.MultiPolygonto be used as mask.- negative_mask
bool(default:False) Whether to keep the edges within the polygon mask or outside. Note that when
negative_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(default:'spatial') Key in
anndata.AnnData.obsmwhere spatial coordinates are stored.- key_added
str(default:'mask') Key which controls where the results are saved if
copy = False.- copy
bool(default:False) If
True, return the result, otherwise save it to theadataobject.
- sdata
- Returns:
SpatialData– Ifcopy = 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}_neighbors']-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.