liana.pp.query_bandwidth

liana.pp.query_bandwidth#

liana.pp.query_bandwidth(coordinates, start=0, end=500, interval_n=50, reference=None, figure_size=(6, 4))#

Query the bandwidth (maximum distance) at which the average number of neighbors is maximized.

Parameters:
coordinates ndarray

Spatial coordinates of spots.

start int (default: 0)

Starting bandwidth.

end int (default: 500)

Ending bandwidth.

interval_n int (default: 50)

Number of bandwidths to query. Used to generate a linearly spaced interval between start and end. Default is 50.

reference ndarray | None (default: None)

Reference coordinates to query the neighbors from. Default is None, which will use coordinates.

figure_size tuple[float, float] (default: (6, 4))

Size of the returned figure as a (width, height) tuple.

Return type:

tuple[plotnine.ggplot, DataFrame]

Returns:

A plotnine plot and a pandas DataFrame with the following columns: - bandwith: the bandwidth (maximum distance) at which the average number of neighbors is maximized. - neighbours: the average number of neighbors at the specified bandwidth.

Examples

Helps choose the bandwidth for liana.pp.spatial_neighbors() by showing how many neighbours each candidate value admits:

>>> import liana as li
>>> adata = li.ds.generate_toy_spatial()
>>> fig, df = li.pp.query_bandwidth(adata.obsm["spatial"], start=0, end=1000)