squidpy.tl.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) – 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) – Size of the sliding window.

  • library_key (str | None) – If multiple library_id, column in anndata.AnnData.obs which stores mapping between library_id and obs.

  • coord_columns (tuple[str, str]) – Tuple of column names in adata.obs that specify the coordinates (x, y), e.i. (‘globalX’, ‘globalY’)

  • sliding_window_key (str) – Base name for sliding window columns.

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

  • spatial_key (str) – Key in anndata.AnnData.obsm where spatial coordinates are stored.

  • drop_partial_windows (bool) – If True, drop windows that are smaller than the window size at the borders.

  • copy (bool) – If True, return the result, otherwise save it to the adata object.

Return type:

DataFrame | None

Returns:

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