How to use the hub.marray.bbox.Bbox function in hub

To help you get started, we’ve selected a few hub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snarkai / Hub / hub / marray / bbox.py View on Github external
def from_filename(cls, filename, dtype=int):
        match = os.path.basename(filename).replace(
            r'(?:\.gz)?$', '').split('_')
        match = [x.split('-') for x in match]
        mins = [int(x[0]) for x in match]
        maxs = [int(x[1]) for x in match]

        return Bbox(mins, maxs, dtype=dtype)
github snarkai / Hub / hub / marray / bbox.py View on Github external
def clone(self):
        return Bbox(self.minpt, self.maxpt, dtype=self.dtype)
github snarkai / Hub / hub / marray / array.py View on Github external
def download_chunk(self, cloudpath):
        chunk = self.storage.get(cloudpath)
        if chunk:
            chunk = self.decode(chunk)
        else:
            chunk = np.zeros(shape=self.chunk_shape,
                             dtype=self.dtype)
                             
        bbox = Bbox.from_filename(cloudpath)
        return chunk, bbox
github snarkai / Hub / hub / marray / bbox.py View on Github external
Returns: void
    """
    if not Bbox.intersects(dest_bbox, src_bbox):
        return

    spt = max2(src_bbox.minpt, dest_bbox.minpt)
    ept = min2(src_bbox.maxpt, dest_bbox.maxpt)
    dbox = Bbox(spt, ept) - dest_bbox.minpt
    ZERO = Vec.zeros(dest_bbox.maxpt)
    istart = max2(spt - src_bbox.minpt, ZERO)

    # FIXME in case some here
    #iend = min2(ept - src_bbox.maxpt, ZERO) + src_img.shape
    iend = istart + (dest_bbox.maxpt - dest_bbox.minpt)
    sbox = Bbox(istart, iend)
    dest_img[dbox.to_slices()] = src_img[sbox.to_slices()]
github snarkai / Hub / hub / marray / bbox.py View on Github external
def from_slices(cls, slices, context=None, bounded=False):
        if context:
            slices = context.reify_slices(slices, bounded=bounded)

        return Bbox(
            [slc.start for slc in slices],
            [slc.stop for slc in slices]
        )
github snarkai / Hub / hub / marray / array.py View on Github external
def generate_cloudpaths(self, slices):
        # Slices -> Bbox
        slices = Bbox(Vec.zeros(self.shape), self.shape).reify_slices(slices)
        requested_bbox = Bbox.from_slices(slices)

        # Make sure chunks fit
        full_bbox = requested_bbox.expand_to_chunk_size(
            self.chunk_shape, offset=Vec.zeros(self.shape)
        )

        # Clamb the border
        full_bbox = Bbox.clamp(full_bbox, Bbox(
            Vec.zeros(self.shape), self.shape))

        # Generate chunknames
        cloudpaths = list(chunknames(
            full_bbox, self.shape,
            self.key, self.chunk_shape,
            protocol=self.protocol
        ))

        return cloudpaths, requested_bbox
github snarkai / Hub / hub / marray / bbox.py View on Github external
def from_vec(cls, vec, dtype=int):
        return Bbox((0, 0, 0), vec, dtype=dtype)
github snarkai / Hub / hub / marray / bbox.py View on Github external
def from_dict(cls, data):
        dtype = data['dtype'] if 'dtype' in data else np.float32
        return Bbox(data['minpt'], data['maxpt'], dtype=dtype)
github snarkai / Hub / hub / marray / bbox.py View on Github external
def intersection(cls, bbx1, bbx2):
        result = Bbox([0] * bbx1.ndim, [0] * bbx2.ndim)

        if not Bbox.intersects(bbx1, bbx2):
            return result

        for i in range(result.ndim):
            result.minpt[i] = max(bbx1.minpt[i], bbx2.minpt[i])
            result.maxpt[i] = min(bbx1.maxpt[i], bbx2.maxpt[i])

        return result