Exemplo n.º 1
0
  def cacheMissXY (self, res, xtile, ytile, ztile, timetile=None):
    """On a miss. Cutout, return the image and load the cache in a background thread"""

    # make sure that the tile size is aligned with the cubedim
    if self.tilesz % self.proj.datasetcfg.cubedim[res][0] != 0 or self.tilesz % self.proj.datasetcfg.cubedim[res][1]:
      raise("Illegal tile size.  Not aligned")

    # figure out the cutout (limit to max image size)
    xstart = xtile*self.tilesz
    ystart = ytile*self.tilesz
    xend = min ((xtile+1)*self.tilesz,self.proj.datasetcfg.imagesz[res][0])
    yend = min ((ytile+1)*self.tilesz,self.proj.datasetcfg.imagesz[res][1])

    # get an xy image slice
    if timetile is None:
      imageargs = '{}/{}/{}/{},{}/{},{}/{}/'.format(self.channel, 'xy', res, xstart, xend, ystart, yend, ztile)
    else:
      imageargs = '{}/{}/{}/{},{}/{},{}/{}/{}/'.format(self.channel, 'xy', res, xstart, xend, ystart, yend, ztile, timetile)
    cb = ocpcarest.imgSlice(imageargs, self.proj, self.db)
    if cb.data.shape != (1, self.tilesz, self.tilesz) and cb.data.shape != (1, 1, self.tilesz, self.tilesz):
      if timetile is None:
        tiledata = np.zeros((1, self.tilesz, self.tilesz), cb.data.dtype )
        tiledata[0, 0:((yend-1)%self.tilesz+1), 0:((xend-1)%self.tilesz+1)] = cb.data[0,:,:]
      else:
        tiledata = np.zeros((1, 1, self.tilesz, self.tilesz), cb.data.dtype )
        tiledata[0, 0, 0:((yend-1)%self.tilesz+1), 0:((xend-1)%self.tilesz+1)] = cb.data[0, 0, :, :]
      cb.data = tiledata

    return cb.xyImage()
Exemplo n.º 2
0
  def cacheMissXZ ( self, resolution, xtile, yslice, ztile ):
    """ On a miss. Cutout, return the image and load the cache in a background thread """

    # make sure that the tile size is aligned with the cubedim
    if self.tilesz % self.proj.datasetcfg.cubedim[resolution][1] != 0 or self.tilesz % self.proj.datasetcfg.cubedim[resolution][2]:
      raise("Illegal tile size.  Not aligned")

    # figure out the cutout (limit to max image size)
    xstart = xtile*self.tilesz
    xend = min ((xtile+1)*self.tilesz,self.proj.datasetcfg.imagesz[resolution][0])

    # z cutouts need to get rescaled
    #  we'll map to the closest pixel range and tolerate one pixel error at the boundary
    scalefactor = self.proj.datasetcfg.zscale[resolution]
    zoffset = self.proj.datasetcfg.slicerange[0]
    ztilestart = int((ztile*self.tilesz)/scalefactor) + zoffset
    zstart = max ( ztilestart, zoffset ) 
    ztileend = int(math.ceil((ztile+1)*self.tilesz/scalefactor)) + zoffset
    zend = min ( ztileend, self.proj.datasetcfg.slicerange[1]+1 )
   
    # get an xz image slice
    imageargs = '{}/{},{}/{}/{},{}/'.format(resolution,xstart,xend,yslice,zstart,zend) 
    cb = ocpcarest.imgSlice ( "xz", imageargs, self.proj, self.db )

    # scale by the appropriate amount

    if cb.data.shape != (ztileend-ztilestart,1,self.tilesz):
      tiledata = np.zeros((ztileend-ztilestart,1,self.tilesz), cb.data.dtype )
      tiledata[0:zend-zstart,0,0:((xend-1)%self.tilesz+1)] = cb.data[:,0,:]
      cb.data = tiledata

    return cb.xzImage( scalefactor )
Exemplo n.º 3
0
    def cacheMissXZ(self, res, xtile, ytile, ztile, timetile=None):
        """On a miss. Cutout, return the image and load the cache in a background thread"""

        # make sure that the tile size is aligned with the cubedim
        if self.tilesz % self.proj.datasetcfg.cubedim[res][
                1] != 0 or self.tilesz % self.proj.datasetcfg.cubedim[res][2]:
            raise ("Illegal tile size.  Not aligned")

        # figure out the cutout (limit to max image size)
        xstart = xtile * self.tilesz
        xend = min((xtile + 1) * self.tilesz,
                   self.proj.datasetcfg.imagesz[res][0])

        # z cutouts need to get rescaled
        # we'll map to the closest pixel range and tolerate one pixel error at the boundary
        # Scalefactor = zvoxel / yvoxel
        scalefactor = self.proj.datasetcfg.voxelres[res][
            2] / self.proj.datasetcfg.voxelres[res][1]
        zoffset = self.proj.datasetcfg.offset[res][2]
        ztilestart = int((ztile * self.tilesz) / scalefactor) + zoffset
        zstart = max(ztilestart, zoffset)
        ztileend = int(math.ceil(
            (ztile + 1) * self.tilesz / scalefactor)) + zoffset
        zend = min(ztileend, self.proj.datasetcfg.imagesz[res][2] + 1)

        # get an xz image slice
        if timetile is None:
            imageargs = '{}/{}/{}/{},{}/{}/{},{}/'.format(
                self.channel, 'xz', res, xstart, xend, ytile, zstart, zend)
        else:
            imageargs = '{}/{}/{}/{},{}/{}/{},{}/{}/'.format(
                self.channel, 'xz', res, xstart, xend, ytile, zstart, zend,
                timetile)
        cb = ocpcarest.imgSlice(imageargs, self.proj, self.db)

        # scale by the appropriate amount

        if cb.data.shape != (ztileend - ztilestart, 1,
                             self.tilesz) and cb.data.shape != (
                                 1, ztileend - ztilestart, 1, self.tilesz):
            if timetile is None:
                tiledata = np.zeros((ztileend - ztilestart, 1, self.tilesz),
                                    cb.data.dtype)
                tiledata[0:zend - zstart, 0,
                         0:((xend - 1) % self.tilesz + 1)] = cb.data[:, 0, :]
            else:
                tiledata = np.zeros((1, ztileend - ztilestart, 1, self.tilesz),
                                    cb.data.dtype)
                tiledata[0, 0:zend - zstart, 0,
                         0:((xend - 1) % self.tilesz + 1)] = cb.data[0, :,
                                                                     0, :]
            cb.data = tiledata

        return cb.xzImage(scalefactor)
Exemplo n.º 4
0
    def cacheMissXY(self, res, xtile, ytile, ztile, timetile=None):
        """On a miss. Cutout, return the image and load the cache in a background thread"""

        # make sure that the tile size is aligned with the cubedim
        if self.tilesz % self.proj.datasetcfg.cubedim[res][
                0] != 0 or self.tilesz % self.proj.datasetcfg.cubedim[res][1]:
            raise ("Illegal tile size.  Not aligned")

        # figure out the cutout (limit to max image size)
        xstart = xtile * self.tilesz
        ystart = ytile * self.tilesz
        xend = min((xtile + 1) * self.tilesz,
                   self.proj.datasetcfg.imagesz[res][0])
        yend = min((ytile + 1) * self.tilesz,
                   self.proj.datasetcfg.imagesz[res][1])

        # get an xy image slice
        if timetile is None:
            imageargs = '{}/{}/{}/{},{}/{},{}/{}/'.format(
                self.channel, 'xy', res, xstart, xend, ystart, yend, ztile)
        else:
            imageargs = '{}/{}/{}/{},{}/{},{}/{}/{}/'.format(
                self.channel, 'xy', res, xstart, xend, ystart, yend, ztile,
                timetile)
        cb = ocpcarest.imgSlice(imageargs, self.proj, self.db)
        if cb.data.shape != (1, self.tilesz,
                             self.tilesz) and cb.data.shape != (
                                 1, 1, self.tilesz, self.tilesz):
            if timetile is None:
                tiledata = np.zeros((1, self.tilesz, self.tilesz),
                                    cb.data.dtype)
                tiledata[0, 0:((yend - 1) % self.tilesz + 1),
                         0:((xend - 1) % self.tilesz + 1)] = cb.data[0, :, :]
            else:
                tiledata = np.zeros((1, 1, self.tilesz, self.tilesz),
                                    cb.data.dtype)
                tiledata[0, 0, 0:((yend - 1) % self.tilesz + 1),
                         0:((xend - 1) % self.tilesz + 1)] = cb.data[0,
                                                                     0, :, :]
            cb.data = tiledata

        return cb.xyImage()
Exemplo n.º 5
0
  def cacheMissYZ (self, res, xtile, ytile, ztile, timetile=None):
    """ On a miss. Cutout, return the image and load the cache in a background thread """

    # make sure that the tile size is aligned with the cubedim
    if self.tilesz % self.proj.datasetcfg.cubedim[res][1] != 0 or self.tilesz % self.proj.datasetcfg.cubedim[res][2]:
      raise("Illegal tile size.  Not aligned")

    # figure out the cutout (limit to max image size)
    ystart = ytile*self.tilesz
    yend = min ((ytile+1)*self.tilesz,self.proj.datasetcfg.imagesz[res][1])

    # z cutouts need to get rescaled
    # we'll map to the closest pixel range and tolerate one pixel error at the boundary
    # Scalefactor = zvoxel / xvoxel
    scalefactor = self.proj.datasetcfg.voxelres[res][2] / self.proj.datasetcfg.voxelres[res][0]
    zoffset = self.proj.datasetcfg.offset[res][2]
    ztilestart = int((ztile*self.tilesz)/scalefactor) + zoffset
    zstart = max ( ztilestart, zoffset ) 
    ztileend = int(math.ceil((ztile+1)*self.tilesz/scalefactor)) + zoffset
    zend = min ( ztileend, self.proj.datasetcfg.imagesz[res][2]+1 )

    # get an yz image slice
    if timetile is None:
      imageargs = '{}/{}/{}/{}/{},{}/{},{}/'.format(self.channel, 'yz', res, xtile, ystart, yend, zstart, zend)
    else:
      imageargs = '{}/{}/{}/{}/{},{}/{},{}/{}/'.format(self.channel, 'yz', res, xtile, ystart, yend, zstart, zend, timetile)
    cb = ocpcarest.imgSlice (imageargs, self.proj, self.db)

    # scale by the appropriate amount
   
    if cb.data.shape != (ztileend-ztilestart,self.tilesz,1) and cb.data.shape != (1,ztileend-ztilestart,self.tilesz,1):
      if timetile is None:
        tiledata = np.zeros((ztileend-ztilestart,self.tilesz,1), cb.data.dtype )
        tiledata[0:zend-zstart,0:((yend-1)%self.tilesz+1),0] = cb.data[:,:,0]
      else:
        tiledata = np.zeros((1,ztileend-ztilestart,self.tilesz,1), cb.data.dtype )
        tiledata[0, 0:zend-zstart,0:((yend-1)%self.tilesz+1),0] = cb.data[0,:,:,0]
      cb.data = tiledata

    return cb.yzImage( scalefactor )