harpy.utils.bounding_box_query

harpy.utils.bounding_box_query#

harpy.utils.bounding_box_query(sdata, labels_name, to_coordinate_system, crd, copy_image=True, copy_shapes=True, copy_points=True, output=None)#

Query the labels elements 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_name (str | Iterable[str]) – The labels element(s) to query, which can be a single string or an iterable of strings.

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

  • crd (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 useful if you want to filter elements in table elements that are annotated by specific labels elements. E.g. setting labels_name="labels_a" and crd=None will result in AnnData objects in sdata.tables containing only instances annotated by "labels_a".

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

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

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

  • output (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 elements.

Raises:

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