def processAndSaveFFT(self, imgdata, fftpath):
                if os.path.isfile(fftpath):
                        print "FFT file found"
                        if fftpath in self.freqdict.keys():
                                print "Freq found"
                                return False
                        print "Freq not found"
                print "creating FFT file: ", fftpath

                ### downsize and filter leginon image
                if self.params['uncorrected']:
                        imgarray = imagefilter.correctImage(imgdata, params)
                else:
                        imgarray = imgdata['image']

                ### calculate power spectra
                apix = apDatabase.getPixelSize(imgdata)
                fftarray, freq = ctfpower.power(imgarray, apix, mask_radius=0.5, fieldsize=self.params['fieldsize'])
                #fftarray = imagefun.power(fftarray, mask_radius=1)

                fftarray = ndimage.median_filter(fftarray, 2)

                ## preform a rotational average and remove peaks
                rotfftarray = ctftools.rotationalAverage2D(fftarray)
                stdev = rotfftarray.std()
                rotplus = rotfftarray + stdev*4
                fftarray = numpy.where(fftarray > rotplus, rotfftarray, fftarray)

                ### save to jpeg
                self.freqdict[fftpath] = freq
                mrc.write(fftarray, fftpath)

                self.saveFreqFile()

                return True
Example #2
0
    def processAndSaveFFT(self, imgdata, fftpath):
        if os.path.isfile(fftpath):
            print "FFT file found"
            if fftpath in self.freqdict.keys():
                print "Freq found"
                return False
            print "Freq not found"
        print "creating FFT file: ", fftpath

        ### downsize and filter leginon image
        if self.params['uncorrected']:
            imgarray = imagefilter.correctImage(imgdata, params)
        else:
            imgarray = imgdata['image']

        ### calculate power spectra
        apix = apDatabase.getPixelSize(imgdata)
        fftarray, freq = ctfpower.power(imgarray,
                                        apix,
                                        mask_radius=0.5,
                                        fieldsize=self.params['fieldsize'])
        #fftarray = imagefun.power(fftarray, mask_radius=1)

        fftarray = ndimage.median_filter(fftarray, 2)

        ## preform a rotational average and remove peaks
        rotfftarray = ctftools.rotationalAverage2D(fftarray)
        stdev = rotfftarray.std()
        rotplus = rotfftarray + stdev * 4
        fftarray = numpy.where(fftarray > rotplus, rotfftarray, fftarray)

        ### save to jpeg
        self.freqdict[fftpath] = freq
        mrc.write(fftarray, fftpath)

        self.saveFreqFile()

        return True
	def CTFpowerspec(self, imgdata, ctfdata, fftpath=None, fftfreq=None, twod=True):
		"""
		Make a nice looking powerspectra with lines for location of Thon rings

		inputs:
			imgdata - sinedon AcquistionImage table row
			ctfdata - sinedon apCtfData table row
				amplitude constrast - ( a cos + sqrt(1-a^2) sin format)
				defocus1 > defocus2
				angle - in degrees, positive x-axis is zero
			outerbound is now set by self.outerAngstrom1D (in Angstroms)
				outside this radius is trimmed away
		"""
		outerbound = self.outerAngstrom1D * 1e-10
		### setup initial parameters for image
		self.imgname = imgdata['filename']
		if self.debug is True:
			print apDisplay.short(self.imgname)
		self.powerspecfile = apDisplay.short(self.imgname)+"-powerspec.jpg"

		### get peak of CTF
		self.cs = ctfdata['cs']*1e-3
		self.volts = imgdata['scope']['high tension']
		self.ampcontrast = ctfdata['amplitude_contrast']

		### process power spectra
		self.apix = apDatabase.getPixelSize(imgdata)

		if self.debug is True:
			print "Pixelsize (A/pix)", self.apix

		apDisplay.printMsg("Reading image...")
		image = imgdata['image']
		self.initfreq = 1./(self.apix * image.shape[0])
		self.origimageshape = image.shape

		### get correct data
		self.convertDefociToConvention(ctfdata)

		if self.debug is True:
			for key in ctfdata.keys():
				if ctfdata[key] is not None and not isinstance(ctfdata[key], dict):
					print "  ", key, "--", ctfdata[key]

		if fftpath is not None and fftfreq is not None and os.path.isfile(fftpath):
			powerspec = mrc.read(fftpath).astype(numpy.float64)
			self.trimfreq = fftfreq
		else:
			powerspec, self.trimfreq = ctftools.powerSpectraToOuterResolution(image, 
				self.outerAngstrom1D, self.apix)
		self.trimapix = 1.0/(self.trimfreq * powerspec.shape[0])

		#print "Median filter image..."
		#powerspec = ndimage.median_filter(powerspec, 2)
		apDisplay.printMsg("Preform a rotational average and remove spikes...")
		rotfftarray = ctftools.rotationalAverage2D(powerspec)
		stdev = rotfftarray.std()
		rotplus = rotfftarray + stdev*4
		powerspec = numpy.where(powerspec > rotplus, rotfftarray, powerspec)
		#print "Light Gaussian blur image..."
		#powerspec = ndimage.gaussian_filter(powerspec, 3)

		if self.debug is True:
			print "\torig pixel %.3f freq %.3e"%(self.apix, self.initfreq)
			print "\ttrim pixel %.3f freq %.3e"%(self.trimapix, self.trimfreq)

		### more processing
		normpowerspec = self.normalizeCtf(powerspec, twod=twod)
		if normpowerspec is None:
			return None

		if twod is True:
			self.drawPowerSpecImage(normpowerspec)

		ctfdisplaydict = {
			'powerspecfile': self.powerspecfile,
			'plotsfile': self.plotsfile,
			'conf3010': self.conf3010,
			'conf5peak': self.conf5peak,
			'overconf3010': self.overconf3010,
			'overconf5peak': self.overconf5peak,
			'res80': self.res80,
			'res50': self.res50,
			'overres80': self.overres80,
			'overres50': self.overres50,
		}

		return ctfdisplaydict