How to use the hub.marray.bbox.Vec 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 map2(fn, a, b):
    assert len(a) == len(b), "Vector lengths do not match: {} (len {}), {} (len {})".format(
        a[:3], len(a), b[:3], len(b))

    result = np.empty(len(a))

    for i in range(len(result)):
        result[i] = fn(a[i], b[i])

    if isinstance(a, Vec) or isinstance(b, Vec):
        return Vec(*result)

    return result
github snarkai / Hub / hub / marray / bbox.py View on Github external
def zeros(cls, shape):
        if isinstance(shape, int):
            shape = range(shape)
        return Vec(*[0 for i in shape])
github snarkai / Hub / hub / marray / bbox.py View on Github external
def size3(self):
        return Vec(*(self.maxpt[:3] - self.minpt[:3]), dtype=self.dtype)
github snarkai / Hub / hub / marray / bbox.py View on Github external
def __init__(self, a, b, dtype=None):
        if dtype is None:
            if floating(a) or floating(b):
                dtype = np.float32
            else:
                dtype = np.int32

        self.minpt = Vec(*[min(ai, bi) for ai, bi in zip(a, b)], dtype=dtype)
        self.maxpt = Vec(*[max(ai, bi) for ai, bi in zip(a, b)], dtype=dtype)

        self._dtype = np.dtype(dtype)
github snarkai / Hub / hub / marray / bbox.py View on Github external
    def round_to_chunk_size(self, chunk_size, offset=Vec(0, 0, 0, dtype=int)):
        """
        Align a potentially non-axis aligned bbox to the grid by rounding it
        to the nearest grid lines.

        Required:
          chunk_size: arraylike (x,y,z), the size of chunks in the 
                        dataset e.g. (64,64,64)
        Optional:
          offset: arraylike (x,y,z), the starting coordinate of the dataset
        """
        chunk_size = np.array(chunk_size, dtype=np.float32)
        result = self.clone()
        result = result - offset
        result.minpt = np.round(result.minpt / chunk_size) * chunk_size
        result.maxpt = np.round(result.maxpt / chunk_size) * chunk_size
        return (result + offset).astype(self.dtype)
github snarkai / Hub / hub / marray / bbox.py View on Github external
def generate_chunks(img, offset, chunk_size):
    shape = Vec(*img.shape)
    offset = Vec(*offset)

    bounds = Bbox(offset, shape + offset)

    alignment_check = bounds.round_to_chunk_size(
        chunk_size, Vec.zeros(*chunk_size))

    if not np.all(alignment_check.minpt == bounds.minpt):
        raise AlignmentError("""
        Only chunk aligned writes are supported by this function. 
  
        Got:             {}
        Volume Offset:   {} 
        Nearest Aligned: {}
      """.format(
            bounds, Vec.zeros(*chunk_size), alignment_check)
        )
github snarkai / Hub / hub / marray / bbox.py View on Github external
def generate_chunks(img, offset, chunk_size):
    shape = Vec(*img.shape)
    offset = Vec(*offset)

    bounds = Bbox(offset, shape + offset)

    alignment_check = bounds.round_to_chunk_size(
        chunk_size, Vec.zeros(*chunk_size))

    if not np.all(alignment_check.minpt == bounds.minpt):
        raise AlignmentError("""
        Only chunk aligned writes are supported by this function. 
  
        Got:             {}
        Volume Offset:   {} 
        Nearest Aligned: {}
      """.format(
            bounds, Vec.zeros(*chunk_size), alignment_check)
github snarkai / Hub / hub / marray / bbox.py View on Github external
def map2(fn, a, b):
    assert len(a) == len(b), "Vector lengths do not match: {} (len {}), {} (len {})".format(
        a[:3], len(a), b[:3], len(b))

    result = np.empty(len(a))

    for i in range(len(result)):
        result[i] = fn(a[i], b[i])

    if isinstance(a, Vec) or isinstance(b, Vec):
        return Vec(*result)

    return result
github snarkai / Hub / hub / marray / bbox.py View on Github external
    def expand_to_chunk_size(self, chunk_size, offset=Vec(0, 0, 0, dtype=int)):
        """
        Align a potentially non-axis aligned bbox to the grid by growing it
        to the nearest grid lines.

        Required:
          chunk_size: arraylike (x,y,z), the size of chunks in the 
                        dataset e.g. (64,64,64)
        Optional:
          offset: arraylike (x,y,z), the starting coordinate of the dataset
        """
        chunk_size = np.array(chunk_size, dtype=np.float32)
        result = self.clone()
        result = result - offset
        result.minpt = np.floor(result.minpt / chunk_size) * chunk_size
        result.maxpt = np.ceil(result.maxpt / chunk_size) * chunk_size
        return (result + offset).astype(self.dtype)
github snarkai / Hub / hub / marray / bbox.py View on Github external
def __truediv__(self, operand):
        tmp = self.clone()

        if isinstance(operand, int):
            operand = float(operand)

        tmp.minpt = Vec(*(tmp.minpt.astype(float) / operand), dtype=float)
        tmp.maxpt = Vec(*(tmp.maxpt.astype(float) / operand), dtype=float)
        return tmp.astype(tmp.minpt.dtype)