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.tablesvia 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 viacrdis defined. IfNone, 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. SettingcrdtoNonecan be useful if you want to filter elements in table elements that are annotated by specific labels elements. E.g. settinglabels_name="labels_a"andcrd=Nonewill result in AnnData objects insdata.tablescontaining only instances annotated by"labels_a".copy_image (
bool(default:True)) – Whether to copy all image elements to the new SpatialData object. If set toFalse, 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 toFalse, 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 toFalse, 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:
- Returns:
: A new SpatialData object containing the extracted bounding box region and associated data elements.
- Raises:
AssertionError – If the number of provided
labels_name,crdandto_coordinate_systemis not equal.