def cacheMissXZ ( self, res, xtile, yslice, ztile ): """On a miss. Cutout, return the image and load the cache in a background thread""" # figure out the cutout (limit to max image size) xstart = xtile * self.tilesz xend = min ((xtile+1) * self.tilesz, self.proj.datasetcfg.imageSize(res)[0][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.getScale()[res]['xz'] zoffset = self.proj.datasetcfg.getOffset()[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.imageSize(res)[0][2] ) # call the mcfc interface imageargs = '{}/{},{}/{},{}/{},{}/'.format(res, xstart, xend, yslice, yslice+1, zstart, zend) tiledata = None for index,channel_name in enumerate(self.channel_list): ch = self.proj.getChannelObj(channel_name) cutout = ocpcarest.cutout(imageargs, ch, self.proj, self.db) # initialize the tiledata by type if tiledata == None: tiledata = np.zeros((len(self.channel_list), zend-zstart, cutout.data.shape[1], self.tilesz), dtype=cutout.data.dtype) tiledata[index, 0:zend-zstart, 0, 0:((xend-1)%self.tilesz+1)] = cutout.data[:, 0, :] tiledata = ocpcarest.window(tiledata, ch) # We have an compound array. Now color it. img = mcfc.mcfcPNG (tiledata.reshape((tiledata.shape[0],tiledata.shape[1],tiledata.shape[3])), self.colors) return img.resize ((self.tilesz,self.tilesz))
def cacheMissXY ( self, res, xtile, ytile, zslice ): """On a miss. Cutout, return the image and load the cache in a background thread""" # 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.imageSize(res)[0][0]) yend = min ((ytile+1)*self.tilesz,self.proj.datasetcfg.imageSize(res)[0][1]) # call the mcfc interface imageargs = '{}/{},{}/{},{}/{},{}/'.format(res, xstart, xend, ystart, yend, zslice, zslice+1) tiledata = None for index, channel_name in enumerate(self.channel_list): ch = self.proj.getChannelObj(channel_name) cutout = ocpcarest.cutout(imageargs, ch, self.proj, self.db) # initialize the tiledata by type if tiledata == None: tiledata = np.zeros((len(self.channel_list), cutout.data.shape[0], self.tilesz, self.tilesz), dtype=cutout.data.dtype) tiledata[index, 0, 0:((yend-1)%self.tilesz+1), 0:((xend-1)%self.tilesz+1)] = cutout.data[0, :, :] tiledata[index,:] = ocpcarest.window(tiledata[index,:], ch) # We have an compound array. Now color it. return mcfc.mcfcPNG (tiledata.reshape((tiledata.shape[0],tiledata.shape[2],tiledata.shape[3])), self.colors)
def cacheMissXY(self, res, xtile, ytile, zslice): """On a miss. Cutout, return the image and load the cache in a background thread""" # 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.imageSize(res)[0][0]) yend = min((ytile + 1) * self.tilesz, self.proj.datasetcfg.imageSize(res)[0][1]) # call the mcfc interface imageargs = '{}/{},{}/{},{}/{},{}/'.format(res, xstart, xend, ystart, yend, zslice, zslice + 1) tiledata = None for index, channel_name in enumerate(self.channel_list): ch = self.proj.getChannelObj(channel_name) cutout = ocpcarest.cutout(imageargs, ch, self.proj, self.db) # initialize the tiledata by type if tiledata == None: tiledata = np.zeros( (len(self.channel_list), cutout.data.shape[0], self.tilesz, self.tilesz), dtype=cutout.data.dtype) tiledata[index, 0, 0:((yend - 1) % self.tilesz + 1), 0:((xend - 1) % self.tilesz + 1)] = cutout.data[0, :, :] tiledata[index, :] = ocpcarest.window(tiledata[index, :], ch) # We have an compound array. Now color it. return mcfc.mcfcPNG( tiledata.reshape( (tiledata.shape[0], tiledata.shape[2], tiledata.shape[3])), self.colors)
def cacheMissXY ( self, resolution, xtile, ytile, zslice ): """On a miss. Cutout, return the image and load the cache in a background thread""" # 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[resolution][0]) yend = min ((ytile+1)*self.tilesz,self.proj.datasetcfg.imagesz[resolution][1]) # call the mcfc interface imageargs = '{}/{},{}/{},{}/{},{}/'.format(resolution,xstart,xend,ystart,yend,zslice,zslice+1) tiledata = None for i in range(len(self.channels)): cutout = ocpcarest.cutout ( imageargs, self.proj, self.db, self.channels[i] ) # initialize the tiledata by type if tiledata == None: tiledata = np.zeros((len(self.channels), cutout.data.shape[0],self.tilesz,self.tilesz), dtype=cutout.data.dtype) tiledata[i,0,0:((yend-1)%self.tilesz+1),0:((xend-1)%self.tilesz+1)] = cutout.data[0,:,:] # reduction factor. How to scale data. 16 bit->8bit, or windowed (startwindow,endwindow) = self.proj.datasetcfg.windowrange if self.proj.getDBType() == ocpcaproj.CHANNELS_16bit and ( startwindow == endwindow == 0): tiledata = np.uint8(tiledata * 1.0/256) elif self.proj.getDBType() == ocpcaproj.CHANNELS_16bit and ( endwindow!=0 ): from windowcutout import windowCutout windowCutout ( tiledata, (startwindow, endwindow) ) # We have an compound array. Now color it. colors = ('C','M','Y','R','G','B') return mcfc.mcfcPNG ( tiledata.reshape((tiledata.shape[0],tiledata.shape[2],tiledata.shape[3])), colors )
def cacheMissYZ(self, res, xtile, ytile, ztile): """On a miss. Cutout, return the image and load the cache in a background thread""" # figure out the cutout (limit to max image size) ystart = ytile * self.tilesz yend = min((ytile + 1) * self.tilesz, self.proj.datasetcfg.imageSize(res)[0][1]) # 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.getScale()[res]['yz'] zoffset = self.proj.datasetcfg.getOffset()[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.imageSize(res)[0][2]) # call the mcfc interface imageargs = '{}/{},{}/{},{}/{},{}/'.format(res, xtile, xtile + 1, ystart, yend, zstart, zend) tiledata = None for index, channel_name in enumerate(self.channel_list): ch = self.proj.getChannelObj(channel_name) cutout = ocpcarest.cutout(imageargs, ch, self.proj, self.db) # initialize the tiledata by type if tiledata == None: tiledata = np.zeros( (len(self.channel_list), ztileend - ztilestart, self.tilesz, cutout.data.shape[2]), dtype=cutout.data.dtype) tiledata[index, 0:zend - zstart, 0:((yend - 1) % self.tilesz + 1), 0] = cutout.data[:, :, 0] tiledata = ocpcarest.window(tiledata, ch) # We have an compound array. Now color it. img = mcfc.mcfcPNG( tiledata.reshape( (tiledata.shape[0], tiledata.shape[1], tiledata.shape[2])), self.colors) return img.resize((self.tilesz, self.tilesz))
def cacheMissXZ ( self, resolution, xtile, yslice, ztile ): """On a miss. Cutout, return the image and load the cache in a background thread""" # 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] ) # call the mcfc interface imageargs = '{}/{},{}/{},{}/{},{}/'.format(resolution,xstart,xend,yslice,yslice+1,zstart,zend) tiledata = None for i in range(len(self.channels)): cutout = ocpcarest.cutout ( imageargs, self.proj, self.db, self.channels[i] ) # initialize the tiledata by type if tiledata == None: tiledata = np.zeros((len(self.channels), zend-zstart, cutout.data.shape[1],self.tilesz), dtype=cutout.data.dtype) tiledata[i,0:zend-zstart,0,0:((xend-1)%self.tilesz+1)] = cutout.data[:,0,:] # reduction factor. How to scale data. 16 bit->8bit, or windowed (startwindow,endwindow) = self.proj.datasetcfg.windowrange if self.proj.getDBType() == ocpcaproj.CHANNELS_16bit and ( startwindow == endwindow == 0): tiledata = np.uint8(tiledata * 1.0/256) elif self.proj.getDBType() == ocpcaproj.CHANNELS_16bit and ( endwindow!=0 ): from windowcutout import windowCutout windowCutout ( tiledata, (startwindow, endwindow) ) # We have an compound array. Now color it. colors = ('C','M','Y','R','G','B') img = mcfc.mcfcPNG ( tiledata.reshape((tiledata.shape[0],tiledata.shape[1],tiledata.shape[3])), colors ) return img.resize ((self.tilesz,self.tilesz))