Пример #1
0
  def addXZCuboid ( self, cuboid, res, xtile, ztile, ymin, ydim ):
    """ Add the cutout to the cache """

    # will create the dataset if it doesn't exist
    self.checkDirHier(res)

    # get the dataset id for this token
    (dsidstr,ximagesz,yimagesz,zoffset,zmaxslice,zscale) = self.db.getDataset ( self.datasetname )
    dsid = int(dsidstr)

    # counter of how many new tiles we get
    newtiles = 0

    # number of tiles
    if self.channels == None:
      numtiles = cuboid.shape[1]
    else:
      numtiles = cuboid.shape[2]

    # get the dataset window range
    startwindow, endwindow = self.info['dataset']['windowrange']

    # windodcutout function if window is non-zero
    if endwindow !=0:
        windowCutout ( cuboid, (startwindow,endwindow) )

    # need to make channels take shape arguments

    # add each image slice to memcache
    for y in range(numtiles):

      self.checkSliceDir(res,y+ymin)
      tilefname = '{}/{}/r{}/sl{}/z{}x{}.png'.format(settings.CACHE_DIR,self.datasetname,res,y+ymin,ztile,xtile)
      if self.channels == None:
        img = self.tile2WebPNG ( cuboid.shape[2], cuboid.shape[0], cuboid[:,y,:] )
      else:
        # looks good to here
        img = self.channels2WebPNG ( cuboid.shape[3], cuboid.shape[1], cuboid[:,:,y,:] )

      # convert into a catmaid perspective tile.
      img = img.resize ( [settings.TILESIZE,settings.TILESIZE] )

      fobj = open ( tilefname, "w" )
      img.save ( fobj, "PNG" )
      try:
        self.db.insert ( tilekey.tileKey(dsid,res,xtile,y+ymin,ztile), tilefname ) 
        newtiles += 1 
      except MySQLdb.Error, e: # ignore duplicate entries
        if e.args[0] != 1062:  
          raise
Пример #2
0
  def __init__(self, token, slice_type, res, xvalue, yvalue, zvalue, tvalue, channels, colors=None):

    # load a cache
    self.db = CacheDB()
    # cutout a a tilesize region
    self.tilesize = settings.TILESIZE
    # setting the server name
    self.server = settings.SERVER
    # take the arguments
    self.token = token
    self.slice_type = slice_type
    self.res = res
    self.xvalue = xvalue
    self.yvalue = yvalue
    self.zvalue = zvalue
    self.tvalue = tvalue
    self.channels = channels
    self.colors = colors
    # set the datasetname and load the data set. If it does not exist in the database then one is fetched and created.
    self.ds = NDDataset(getDatasetName(self.token, self.channels, self.colors, self.slice_type))
    self.getFileName() 
    self.tkey = tilekey.tileKey(self.ds.getDatasetId(), self.res, self.xvalue, self.yvalue, self.zvalue, self.tvalue)
Пример #3
0
      # add each image slice to memcache
      for value in range(numtiles):

        self.checkSliceDir(res, value+mini)
        tilefname = '{}/{}/r{}/sl{}/{}{}{}{}.png'.format(settings.CACHE_DIR, self.dataset_name, res, value+mini,self.slice_type[1], tile2, self.slice_type[0], tile1)
        if self.slice_type == 'xy':
          img = self.tile2WebPNG ( settings.TILESIZE, settings.TILESIZE, cuboid[:,value,:,:] )
        elif self.slice_type == 'xz':
          img = self.tile2WebPNG ( cuboid.shape[3], cuboid.shape[1], cuboid[:,:,value,:] )
        elif self.slice_type == 'yz':
          img = self.tile2WebPNG ( cuboid.shape[2], cuboid.shape[1], cuboid[:,:,:,value] )

        fobj = open(tilefname, "w")
        img.save(fobj, "PNG")
        try:
          self.ds.db.insert(tilekey.tileKey(self.ds.getDatasetId(), res, tile1, tile2, value+mini), tilefname) 
          newtiles += 1 
        except MySQLdb.Error, e: 
          # ignore duplicate entries
          if e.args[0] != 1062:  
            raise
    
    else: 
      # number of tiles
      numtiles = cuboid.shape[2]
      
      for index, channel_name in enumerate(self.channels):
        ch = self.ds.getChannelObj(channel_name)
        cuboid[index,:] = window(cuboid[index,:], ch)

      # add each image slice to memcache