def get_ids_in_region(
self, cutout_fcn, resource, resolution, corner, extent,
t_range=[0, 1], version=0):
"""
Method to get all the ids within a defined region.
Args:
cutout_fcn (function): SpatialDB's cutout method. Provided for naive search of ids in sub-regions
resource (project.BossResource): Data model info based on the request or target resource
resolution (int): the resolution level
corner ((int, int, int)): xyz location of the corner of the region
extent ((int, int, int)): xyz extents of the region
t_range (optional[list[int]]): time range, defaults to [0, 1]
version (optional[int]): Reserved for future use. Defaults to 0
Returns:
(dict): { 'ids': ['1', '4', '8'] }
"""
# Identify sub-region entirely contained by cuboids.
cuboids = Region.get_cuboid_aligned_sub_region(
resolution, corner, extent)
# Get all non-cuboid aligned sub-regions.
non_cuboid_list = Region.get_all_partial_sub_regions(
resolution, corner, extent)
# Do cutouts on each partial region and build id set.
id_set = np.array([], dtype='uint64')
for partial_region in non_cuboid_list:
extent = partial_region.extent
if extent[0] == 0 or extent[1] == 0 or extent[2] == 0:
continue
id_arr = self._get_ids_from_cutout(
cutout_fcn, resource, resolution,
partial_region.corner, partial_region.extent,
t_range, version)
# TODO: do a unique first? perf test
id_set = np.union1d(id_set, id_arr)
# Get ids from dynamo for sub-region that's 100% cuboid aligned.
obj_key_list = self._get_object_keys(
resource, resolution, cuboids, t_range)
cuboid_ids = self.obj_ind.get_ids_in_cuboids(obj_key_list, version)
cuboid_ids_arr = np.asarray([int(id) for id in cuboid_ids], dtype='uint64')
# Union ids from cuboid aligned sub-region.
id_set = np.union1d(id_set, cuboid_ids_arr)
# Convert ids back to strings for transmission via HTTP.
ids_as_str = ['%d' % n for n in id_set]
return { 'ids': ids_as_str }
评论列表
文章目录