sliding_window#

squidpy.tl.sliding_window(adata, *, library_key=None, window_size=None, overlap=0, coord_columns=('globalX', 'globalY'), sliding_window_key='sliding_window_assignment', spatial_key='spatial', drop_partial_windows=False, copy=False, table_key=None)[source]#

Divide a tissue slice into regulary shaped spatially contiguous regions (windows).

Parameters:
adata AnnData | SpatialData

Annotated data object.

table_key str | None (default: None)

Key in spatialdata.SpatialData.tables where the table is stored. Required when adata is a spatialdata.SpatialData object and ignored otherwise.

window_size int | None (default: None)

Size of the sliding window.

library_key str | None (default: None)

If multiple library_id, column in anndata.AnnData.obs which stores mapping between library_id and obs.

coord_columns tuple[str, str] (default: ('globalX', 'globalY'))

Tuple of column names in adata.obs that specify the coordinates (x, y), e.i. (‘globalX’, ‘globalY’)

sliding_window_key str (default: 'sliding_window_assignment')

Base name for sliding window columns.

overlap int (default: 0)

Overlap size between consecutive windows. (0 = no overlap)

spatial_key str (default: 'spatial')

Key in anndata.AnnData.obsm where spatial coordinates are stored.

drop_partial_windows bool (default: False)

If True, drop windows that are smaller than the window size at the borders.

copy bool (default: False)

If True, return the result, otherwise save it to the adata object.

Returns:

DataFrame | None – If copy = True, returns the sliding window annotation(s) as pandas dataframe Otherwise, stores the sliding window annotation(s) in .obs.