예제 #1
0
def load_rg_chunk_affinities(regiongraph_storage: Storage,
                             chunk_path: str) -> np.ndarray:
    """
    Extract weighted supervoxel edges from zstd compressed Region Graph
    file `chunk_path`.
    The unversioned, custom binary file format shall be called RanStruct,
    which, as of 2018-08-03, looks like this:

    struct RanStruct        # Little Endian, not aligned -> 56 Byte
      segA1::UInt64
      segB1::UInt64
      sum_aff1::Float32
      sum_area1::UInt64
      segA2::UInt64         # same as segA1
      segB2::UInt64         # same as segB1
      sum_aff2::Float32     # same as sum_aff1
      sum_area2::UInt64     # same as sum_area1
    end

    The big top level Region Graph chunks get requested almost every time,
    thus the memoization.
    """

    f = regiongraph_storage.get_file(chunk_path)
    if not f:
        Warning("%s doesn't exist" % chunk_path)
        return np.array([], dtype='uint64, uint64, float32, uint64')

    dctx = zstd.ZstdDecompressor()
    decompressed = dctx.decompress(f)

    buf = np.frombuffer(decompressed, dtype='uint64, uint64, float32, uint64')
    return np.lib.stride_tricks.as_strided(buf,
                                           shape=tuple(x // 2
                                                       for x in buf.shape),
                                           strides=tuple(x * 2
                                                         for x in buf.strides),
                                           writeable=False)
예제 #2
0
 def _download_input_chunk(self, bounds):
   storage = Storage(self.layer_path, n_threads=0)
   relpath = 'build/{}'.format(bounds.to_filename())
   return storage.get_file(relpath)