sparrow.utils.bounding_box_query

sparrow.utils.bounding_box_query#

sparrow.utils.bounding_box_query(sdata, labels_layer, to_coordinate_system, crd, copy_img_layer=True, copy_shapes_layer=True, copy_points_layer=True, output=None)#

Query the labels layers of a SpatialData object and the corresponding instances it annotates in sdata.tables via a bounding box query.

Parameters:
  • sdata (SpatialData) – The SpatialData object to query.

  • labels_layer (Union[str, Iterable[str]]) – The labels layer(s) to query, which can be a single string or an iterable of strings.

  • to_coordinate_system (Union[str, Iterable[str], None]) – The coordinate system(s) to which the query provided via crd is defined. If None, will use ‘global’.

  • crd (Union[tuple[int, int, int, int], Iterable[tuple[int, int, int, int] | None], None]) – Coordinates defining the bounding box, specified as a tuple of four integers (x_min, y_min, x_max, y_max), or an iterable of such tuples. Setting crd to None can be usefull if you want to filter elments in tables layers that are annotated by specific labels layers. E.g. setting labels_layer=layer_1 and crd=None, will result in AnnData objects in sdata.tables containing only instances annotated by layer_1.

  • copy_img_layer (bool (default: True)) – Whether to copy all image layers to the new SpatialData object. If set to False, image layers will not be included in the result.

  • copy_shapes_layer (bool (default: True)) – Whether to copy all shapes layers to the new SpatialData object. If set to False, shapes layers will not be included in the result.

  • copy_points_layer (bool (default: True)) – Whether to copy all points layers to the new SpatialData object. If set to False, points layers will not be included in the result.

  • output (Union[str, Path, None] (default: None)) – Path to the zarr store where the resulting SpatialData object will be backed. If None, the new resulting SpatialData object will be persisted in memory.

Return type:

SpatialData

Returns:

: A new SpatialData object containing the extracted bounding box region and associated data layers.

Raises:

AssertionError – If the number of provided labels_layer, crd and to_coordinate_system is not equal.