예제 #1
0
    def breakCubes(key, blosc_data):
      """break the cubes into smaller chunks"""
      
      key_array = [token, channel_name, res, x1, x2, y1, y2, z1, z2, time_stamp] = key.split('_')
      [res, x1, x2, y1, y2, z1, z2] = [int(i) for i in key_array[2:][:-1]]
      if blosc_data is None:
        return
      voxarray = blosc.unpack_array(blosc_data)
      
      br = BlazeRedis(token, channel_name, res)

      ds = Dataset(token)
      ch = ds.getChannelObj(channel_name)
      [zimagesz, yimagesz, ximagesz] = ds.imagesz[res]
      #[xcubedim, ycubedim, zcubedim] = cubedim = ds.cubedim[res]
      [xcubedim, ycubedim, zcubedim] = cubedim = CUBE_DIM
      [xoffset, yoffset, zoffset] = ds.offset[res]
      
      # Calculating the corner and dimension
      corner = [x1, y1, z1]
      dim = voxarray.shape[::-1][:-1]

      # Round to the nearest largest cube in all dimensions
      [xstart, ystart, zstart] = start = map(div, corner, cubedim)

      znumcubes = (corner[2]+dim[2]+zcubedim-1)/zcubedim - zstart
      ynumcubes = (corner[1]+dim[1]+ycubedim-1)/ycubedim - ystart
      xnumcubes = (corner[0]+dim[0]+xcubedim-1)/xcubedim - xstart
      numcubes = [xnumcubes, ynumcubes, znumcubes]
      offset = map(mod, corner, cubedim)

      data_buffer = np.zeros(map(mul, numcubes, cubedim)[::-1], dtype=voxarray.dtype)
      end = map(add, offset, dim)
      data_buffer[offset[2]:end[2], offset[1]:end[1], offset[0]:end[0]] = voxarray

      cube_list = []
      for z in range(znumcubes):
        for y in range(ynumcubes):
          for x in range(xnumcubes):
            zidx = XYZMorton(map(add, start, [x,y,z]))
           
            # Parameters in the cube slab
            index = map(mul, cubedim, [x,y,z])
            end = map(add, index, cubedim)

            cube_data = data_buffer[index[2]:end[2], index[1]:end[1], index[0]:end[0]]
            cube_list.append((br.generateSIKey(zidx), blosc.pack_array(cube_data.reshape((1,)+cube_data.shape))))
      
      return cube_list[:]
예제 #2
0
def postBloscData(webargs, post_data):
  """Accept a posted region of cutout"""
  
  try:
    # arguments of format token/channel/service/resolution/x,x/y,y/z,z/
    m = re.match("(\w+)/(\w+)/(\w+)/(\d+)/(\d+),(\d+)/(\d+),(\d+)/(\d+),(\d+)/", webargs)
    [token, channel_name, service] = [i for i in m.groups()[:3]]
    [res, x1, x2, y1, y2, z1, z2] = [int(i) for i in m.groups()[3:]]
  except Exception, e:
    print "Wrong arguments"
    raise

  # Fetaching the info from nd backend
  ds = Dataset(token)
  ch = ds.getChannelObj(channel_name)
 
  [zimagesz, yimagesz, ximagesz] = ds.imagesz[res]
  #[xcubedim, ycubedim, zcubedim] = cubedim = ds.cubedim[res]
  [xcubedim, ycubedim, zcubedim] = cubedim = [512,512,16]
  [xoffset, yoffset, zoffset] = ds.offset[res]
  
  
  # Calculating the corner and dimension
  corner = [x1, y1, z1]
  dim = [x2-x1,y2-y1,z2-z1]

  # Round to the nearest largest cube in all dimensions
  [xstart, ystart, zstart] = start = map(div, corner, cubedim)

  znumcubes = (corner[2]+dim[2]+zcubedim-1)/zcubedim - zstart