def binAndAddCTFlabel(self, image, ht, rpixelsize, binning=1, defocus=None): pow = imagefun.power(image) binned = imagefun.bin(pow, binning) # No ctf estimation until it works better so that this node does not # depend on coma beam-tilt calibration s = None ctfdata = None ''' try: ctfdata = fftfun.fitFirstCTFNode(pow,rpixelsize['x'], defocus, ht) except Exception, e: self.logger.error("ctf fitting failed: %s" % e) ctfdata = None if ctfdata: self.logger.info('z0 %.3f um, zast %.3f um (%.0f ), angle= %.1f deg' % (ctfdata[0]*1e6,ctfdata[1]*1e6,ctfdata[2]*100, ctfdata[3]*180.0/math.pi)) s = '%d' % int(ctfdata[0]*1e9) #elif self.ace2exe: elif False: ctfdata = self.estimateCTF(imagedata) z0 = (ctfdata['defocus1'] + ctfdata['defocus2']) / 2 s = '%d' % (int(z0*1e9),) ''' if s: t = numpil.textArray(s) t = ndimage.zoom(t, (min(binned.shape)-40.0)*0.08/(t.shape)[0]) minvalue = arraystats.min(binned) maxvalue = arraystats.max(binned) t = minvalue + t * (maxvalue-minvalue) imagefun.pasteInto(t, binned, (20,20)) return binned, ctfdata
def render(self): rowmin = 0 rowmax = 0 colmin = 0 colmax = 0 for image in self.images: extents = self.imageExtents(image) if extents['row'][0] < rowmin: rowmin = extents['row'][0] if extents['row'][1] > rowmax: rowmax = extents['row'][1] if extents['column'][0] < colmin: colmin = extents['column'][0] if extents['column'][1] > colmax: colmax = extents['column'][1] totalshape = 2*max(rowmax,-rowmin), 2*max(colmax,-colmin) background = self.images[0]['image'][(0,0)] finalimage = numpy.ones(totalshape, self.images[0]['image'].dtype) finalimage = background * finalimage center = finalimage.shape[0]/2, finalimage.shape[1]/2 for image in self.images: extents = self.imageExtents(image) pos = center[0]+extents['row'][0], center[1]+extents['column'][0] imagefun.pasteInto(image['image'], finalimage, pos) if len(self.images) > 1: extents = self.imageExtents(self.images[1]) scalerow = (extents['row'][0]+extents['row'][1])/2 scalecol = (extents['column'][0]+extents['column'][1])/2 scale = math.sqrt(scalerow**2+scalecol**2) else: scale = None return finalimage, scale
def render(self): rowmin = 0 rowmax = 0 colmin = 0 colmax = 0 for image in self.images: extents = self.imageExtents(image) if extents['row'][0] < rowmin: rowmin = extents['row'][0] if extents['row'][1] > rowmax: rowmax = extents['row'][1] if extents['column'][0] < colmin: colmin = extents['column'][0] if extents['column'][1] > colmax: colmax = extents['column'][1] # odd number total shape allows center on the pixel and reduce truncation error totalshape = 2*(max(rowmax,-rowmin))+1, 2*(max(colmax,-colmin))+1 background = self.images[0]['image'][(0,0)] finalimage = numpy.ones(totalshape, self.images[0]['image'].dtype) finalimage = background * finalimage center = finalimage.shape[0]/2, finalimage.shape[1]/2 for image in self.images: extents = self.imageExtents(image) pos = center[0]+extents['row'][0], center[1]+extents['column'][0] imagefun.pasteInto(image['image'], finalimage, pos) if len(self.images) > 1: extents = self.imageExtents(self.images[1]) scalerow = (extents['row'][0]+extents['row'][1])/2 scalecol = (extents['column'][0]+extents['column'][1])/2 scale = math.sqrt(scalerow**2+scalecol**2) else: scale = None return finalimage, scale
def binAndAddCTFlabel(self, image, ht, cs, rpixelsize, binning=1, defocus=None): pow = imagefun.power(image) binned = imagefun.bin(pow, binning) # No ctf estimation until it works better so that this node does not # depend on coma beam-tilt calibration s = None ctfdata = None ''' try: ctfdata = fftfun.fitFirstCTFNode(pow,rpixelsize['x'], defocus, ht, cs) except Exception, e: self.logger.error("ctf fitting failed: %s" % e) ctfdata = None if ctfdata: self.logger.info('z0 %.3f um, zast %.3f um (%.0f ), angle= %.1f deg' % (ctfdata[0]*1e6,ctfdata[1]*1e6,ctfdata[2]*100, ctfdata[3]*180.0/math.pi)) s = '%d' % int(ctfdata[0]*1e9) #elif self.ace2exe: elif False: ctfdata = self.estimateCTF(imagedata) z0 = (ctfdata['defocus1'] + ctfdata['defocus2']) / 2 s = '%d' % (int(z0*1e9),) ''' if s: t = numpil.textArray(s) t = ndimage.zoom(t, (min(binned.shape) - 40.0) * 0.08 / (t.shape)[0]) minvalue = arraystats.min(binned) maxvalue = arraystats.max(binned) t = minvalue + t * (maxvalue - minvalue) imagefun.pasteInto(t, binned, (20, 20)) return binned, ctfdata
ctfdata = None if ctfdata: self.logger.info('z0 %.3f um, zast %.3f um (%.0f ), angle= %.1f deg' % (ctfdata[0]*1e6,ctfdata[1]*1e6,ctfdata[2]*100, ctfdata[3]*180.0/math.pi)) s = '%d' % int(ctfdata[0]*1e9) #elif self.ace2exe: elif False: ctfdata = self.estimateCTF(imagedata) z0 = (ctfdata['defocus1'] + ctfdata['defocus2']) / 2 s = '%d' % (int(z0*1e9),) if s: t = numpil.textArray(s) t = ndimage.zoom(t, (min(binned.shape)-40.0)*0.08/(t.shape)[0]) minvalue = arraystats.min(binned) maxvalue = arraystats.max(binned) t = minvalue + t * (maxvalue-minvalue) imagefun.pasteInto(t, binned, (20,20)) return binned, ctfdata def estimateCTF(self, imagedata): mag = imagedata['scope']['magnification'] tem = imagedata['scope']['tem'] cam = imagedata['camera']['ccdcamera'] pixelsize = self.btcalclient.getPixelSize(mag, tem, cam) inputparams = { 'input': os.path.join(imagedata['session']['image path'],imagedata['filename']+".mrc"), 'cs': 2.0, 'kv': imagedata['scope']['high tension']/1000.0, 'apix': pixelsize*1e10, 'binby': 1, }