Пример #1
0
  def fetch (self):
    """Retrieve the tile from the cache or load the cache and return"""

    try:

      # open file and return
      f=open(self.filename)
      self.db.touch(self.tkey)
      return f.read()

    except IOError:
      pass

    try:
      self.initForFetch()
    except OOBException:
      logger.warning("OOB request.  Returning black tile.  url={}".format(self.tileurl))
      img = Image.new("L", (512, 512))
      fileobj = cStringIO.StringIO ( )
      img.save ( fileobj, "PNG" )
      fileobj.seek(0)
      return fileobj.read()

    # call the celery process to fetch the url
    from ocptilecache.tasks import fetchurl
    fetchurl.delay ( self.token, self.slicetype, self.channels, self.cuboidurl )
    #fetchurl ( self.token, self.slicetype, self.channels, self.cuboidurl )

    logger.warning("CATMAID tile fetch {}".format(self.tileurl))
    try:
      f = urllib2.urlopen ( self.tileurl )
    except urllib2.URLError, e:
      raise
Пример #2
0
    for z in range(zlow,zhigh,zdim):
      for y in range(ylow,yhigh,ydim):
        for x in range(xlow,xhigh,xdim):

          if zlow >= zhigh or ylow >= yhigh or xlow >= xhigh:
            continue
        
          # Build the URLs
          cutout = '{}/{},{}/{},{}/{},{}'.format(level,x,min(x+xdim,ximagesize),y,min(y+ydim,yimagesize),z,min(z+zdim,zimagesize))
          cuboidurl = "http://{}/ocpca/{}/npz/{}/".format(settings.SERVER,token,cutout)
          print cuboidurl

          # call the celery process to fetch the url
          from ocptilecache.tasks import fetchurl
          fetchurl.delay ( cuboidurl, info )

def main():

  parser = argparse.ArgumentParser(description='Prefetch a volume  ')
  parser.add_argument('token', action="store")
  parser.add_argument('cutout', action="store", help='Cutout arguments of the form resolution/x1,x2/y1,y2/z1,z2.', default=None)

  result = parser.parse_args()

  p = re.compile('^(\d+)/(\d+),(\d+)/(\d+),(\d+)/(\d+),(\d+).*$')
  m = p.match(result.cutout)

  [ res, xmin, xmax, ymin, ymax, zmin, zmax ] = map(int, m.groups())

  prefetch ( result.token, res, xmin, xmax, ymin, ymax, zmin, zmax )