def get(self, bounding_box: BoundingBox) -> Data: indexes = self._queryBoundingBox(bounding_box) data = [] stack_volumes = [volume for i, volume in self.stack if i in indexes] stack_disjoint = list(set(indexes) - set([i for i, v in self.stack])) for volume in stack_volumes: sub_bbox = bounding_box.intersect(volume.getBoundingBox()) data.append(volume.get(sub_bbox)) for index in stack_disjoint: volume = self.volumes[index] i = self._pushStack(index, volume) sub_bbox = bounding_box.intersect(volume.getBoundingBox()) data.append(volume.get(sub_bbox)) shape = bounding_box.getNumpyDim() array = Array(np.zeros(shape).astype(np.uint16), bounding_box=bounding_box, iteration_size=BoundingBox(Vector(0, 0, 0), bounding_box.getSize()), stride=bounding_box.getSize()) [array.set(item) for item in data] return Data(array.getArray(), bounding_box)
def get(self, bounding_box: BoundingBox) -> Data: """ Requests a data sample from the volume. If the bounding box does not exist, then the method raises a ValueError. :param bounding_box: The bounding box of the request data sample :return: The data sample requested """ if bounding_box.isDisjoint(self.getBoundingBox()): error_string = ("Bounding box must be inside dataset " + "dimensions instead bounding box is {} while " + "the dataset dimensions are {}") error_string = error_string.format(bounding_box, self.getBoundingBox()) raise ValueError(error_string) sub_bounding_box = bounding_box.intersect(self.getBoundingBox()) array = self.getArray(sub_bounding_box) before_pad = bounding_box.getEdges()[0] - sub_bounding_box.getEdges( )[0] after_pad = bounding_box.getEdges()[1] - sub_bounding_box.getEdges()[1] if before_pad != Vector(0, 0, 0) or after_pad != Vector(0, 0, 0): pad_size = tuple( zip(before_pad.getNumpyDim(), after_pad.getNumpyDim())) array = np.pad(array, pad_width=pad_size, mode="constant") return Data(array, bounding_box)