spateo.digitization.grid#

Written by @Jinerhal, adapted by @Xiaojieqiu.

Module Contents#

Functions#

digitize(→ None)

Calculate the "heat" for a closed area of interests by solving a PDE, partial differential equation, the heat

gridit(→ None)

Segment the area of interests into specific layer/column number, according to precomputed digitization heat

spateo.digitization.grid.digitize(adata: spateo.digitization.utils.AnnData, ctrs: spateo.digitization.utils.Tuple, ctr_idx: int, pnt_xy: spateo.digitization.utils.Tuple[int, int], pnt_Xy: spateo.digitization.utils.Tuple[int, int], pnt_xY: spateo.digitization.utils.Tuple[int, int], pnt_XY: spateo.digitization.utils.Tuple[int, int], spatial_key: str = 'spatial', dgl_layer_key: str = 'digital_layer', dgl_column_key: str = 'digital_column', max_itr: int = 100000.0, lh: float = 1, hh: float = 100) None[source]#
Calculate the “heat” for a closed area of interests by solving a PDE, partial differential equation, the heat

equation. Boundary conditions are defined upon four user provided coordinates that set the direction of heat diffusion. The value of “heat” will be used for define different spatial layers, domains and grids.

Parameters:
adata

The adata object to digitize.

ctrs

Contours generated by cv2.findContours.

ctr_idx

The index of the contour of interests.

pnt_xy

Corner point to define an area of interest. pnt_xy corresponds to the point with minimal layer and minimal column value.

pnt_Xy

Corner point corresponds to the point with maximal column value but minimal layer value.

pnt_xY

Corner point corresponds to the point with minimal column value but maximal layer value.

pnt_XY

Corner point corresponds to the point with maximal layer and maximal columns value.

spatial_key

The key name in adata.obsm of the spatial coordinates. Default to “spatial”.

dgl_layer_key

The key name in adata.obs to store layer digital-heat (temperature). Default to “digital_layer”.

dgl_column_key

The key name to store column digital-heat (temperature).

max_itr

Maximum number of iterations dedicated to solving the heat equation.

lh

lowest digital-heat (temperature). Defaults to 1.

hh

highest digital-heat (temperature). Defaults to 100.

Returns:

  1. dgl_layer_key: The key in adata.obs points to the values of layer digital-heat (temperature).

  2. dgl_column_key: The key in adata.obs points to the values of column digital-heat (temperature).

Return type:

Nothing but update the adata object with the following keys in .obs

spateo.digitization.grid.gridit(adata: spateo.digitization.utils.AnnData, layer_num: int, column_num: int, lh: float = 1, hh: float = 100, dgl_layer_key: str = 'digital_layer', dgl_column_key: str = 'digital_column', layer_border_width: int = 2, column_border_width: int = 2, layer_label_key: str = 'layer_label', column_label_key: str = 'column_label', grid_label_key: str = 'grid_label') None[source]#

Segment the area of interests into specific layer/column number, according to precomputed digitization heat value.

Parameters:
adata

The adata object to do layer/column/grid segmentation.

layer_num

Number of layers to segment.

column_num

Number of columns to segment.

lh

lowest digital-heat. Default to 1.

hh

highest digi-heat. Default to 100.

layer_border_width

Layer boundary width. Only affect grid_label.

column_border_width

Column boundary width. Only affect grid_label.

dgl_layer_key

The key name of layer digitization heat in adata.obs. Default to “digital_layer”, precomputed.

dgl_column_key

The key name of column digitization heat in adata.obs. Default to “digital_column”, precomputed.

layer_label_key

The key name to store layer labels in adata.obs. Default to “layer_label”, will be added.

column_label_key

The key name to store column labels in adata.obs. Default to “column_label”, will be added.

grid_label_key

The key name to store grid labels in adata.obs. Default to “grid_label”, will be added.

Returns:

  1. layer_label_key: this key points to layer labels.

  2. column_label_key: this key points to column labels.

  3. grid_label_key: this key points to grid labels.

Return type:

Nothing but update the adata object with the following keys in .obs