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 asmake_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 createf"{image_key}_tissue"if neithertissue_mask_keynor an existingf"{image_key}_tissue"is found.
If
None, tiles can still be created and classified using an explicittissue_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.labelsused for classification. IfNoneandimage_keyis provided, the function falls back tof"{image_key}_tissue"and will automatically rundetect_tissue()to create it if missing. If bothimage_keyandtissue_mask_keyareNone, tiles are created but not classified.- scale
str(default:'auto') Label scale to use when reading the tissue mask. If
"auto"andimage_keyis 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 tof"{spots_key}_tiles".- preview
bool(default:True) If
True, render a preview. Whenimage_keyis provided, this usessdata.pl.render_images(image_key)and overlays the tiles colored bytile_classification. Otherwise only the tiles are rendered.
- sdata
- Returns:
None– None Tiles and their classifications are written in-place tosdata.shapes; spot classifications are copied back tosdata.shapes[spots_key]via thetile_classificationcolumn.
See also
make_tilesCreate a regular grid of tiles over an image instead of spot-centered tiles.
detect_tissueHelper used to derive tissue masks automatically when needed.