make_tiles_from_spots

make_tiles_from_spots#

squidpy.experimental.im.make_tiles_from_spots(sdata, *, spots_key, image_key=None, tissue_mask_key=None, scale='auto', min_tissue_fraction=1.0, new_shapes_key=None, preview=True)[source]#

Create tiles centered on Visium spots, classify them by tissue coverage, and optionally render a preview.

The function reads spot coordinates from sdata.shapes[spots_key], infers a square tile size from the vertical spacing between spots, and constructs one tile per spot. Tiles are then classified using a tissue mask in the same way as make_tiles().

Parameters:
sdata SpatialData

SpatialData object containing Visium spot shapes, images, and (optionally) label masks.

spots_key str

Key of the spot shapes in sdata.shapes. The geometry must be point-like and in the same coordinate system as the image / tissue mask.

image_key str | None (default: None)

Optional key of the image in sdata.images. If provided, the function will:

  • use it to choose an appropriate label scale for the tissue mask,

  • optionally render the preview with the image as a background, and

  • automatically run detect_tissue() to create f"{image_key}_tissue" if neither tissue_mask_key nor an existing f"{image_key}_tissue" is found.

If None, tiles can still be created and classified using an explicit tissue_mask_key, but the preview will render tiles only (no image background).

tissue_mask_key str | None (default: None)

Key of the tissue mask in sdata.labels used for classification. If None and image_key is provided, the function falls back to f"{image_key}_tissue" and will automatically run detect_tissue() to create it if missing. If both image_key and tissue_mask_key are None, tiles are created but not classified.

scale str (default: 'auto')

Label scale to use when reading the tissue mask. If "auto" and image_key is provided, the function picks the label scale whose shape is closest to the full-resolution image dimensions.

min_tissue_fraction float (default: 1.0)

Minimum fraction of a tile that must be tissue for it to be considered suitable for inference. Tiles below this threshold are classified as "background" (0%) or "partial_tissue" (>0%).

new_shapes_key str | None (default: None)

Key under which to store the spot-centered tiles in sdata.shapes. Defaults to f"{spots_key}_tiles".

preview bool (default: True)

If True, render a preview. When image_key is provided, this uses sdata.pl.render_images(image_key) and overlays the tiles colored by tile_classification. Otherwise only the tiles are rendered.

Returns:

None – None Tiles and their classifications are written in-place to sdata.shapes; spot classifications are copied back to sdata.shapes[spots_key] via the tile_classification column.

See also

make_tiles

Create a regular grid of tiles over an image instead of spot-centered tiles.

detect_tissue

Helper used to derive tissue masks automatically when needed.