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.tablesvia a bounding box query.- Parameters:
sdata (
SpatialData) – The SpatialData object to query.labels_layer (
str|Iterable[str]) – The labels layer(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 usefull if you want to filter elments in tables layers that are annotated by specific labels layers. E.g. settinglabels_layer=layer_1andcrd=None, will result in AnnData objects insdata.tablescontaining only instances annotated bylayer_1.copy_img_layer (
bool(default:True)) – Whether to copy all image layers to the new SpatialData object. If set toFalse, 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 toFalse, 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 toFalse, points layers 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 layers.
- Raises:
AssertionError – If the number of provided
labels_layer,crdandto_coordinate_systemis not equal.