def FSCSum(volume,reference,numberOfBands,wedgeAngle=-1): """ FSCSum: Determines the sum of the Fourier Shell Correlation coefficient for a volume and reference. @param volume: A volume @type volume: L{pytom_volume.vol} @param reference: A reference of same size as volume @type reference: L{pytom_volume.vol} @param numberOfBands: Number of bands @param wedgeAngle: A optional wedge angle @return: The sum FSC coefficient @rtype: float @author: Thomas Hrabe """ from pytom.basic.correlation import bandCC import pytom_volume from pytom.basic.fourier import fft from math import sqrt import pytom_freqweight result = 0 numberVoxels = 0 #volume.write('vol.em'); #reference.write('ref.em'); fvolume = fft(volume) freference = fft(reference) numelem = volume.numelem() fvolume.shiftscale(0,1/float(numelem)) freference.shiftscale(0,1/float(numelem)) #print '-----' for i in range(numberOfBands): #process bandCorrelation band = [] band[0] = i*volume.sizeX()/numberOfBands band[1] = (i+1)*volume.sizeX()/numberOfBands r = bandCC(fvolume,freference,band) cc = r[0] #print cc result = result + cc #print '-----' return result*(1/float(numberOfBands))
def FSC(volume1,volume2,numberBands,mask=None,verbose=False, filename=None): """ FSC - Calculates the Fourier Shell Correlation for two volumes @param volume1: volume one @type volume1: L{pytom_volume.vol} @param volume2: volume two @type volume2: L{pytom_volume.vol} @param numberBands: number of shells for FSC @type numberBands: int @param filename: write FSC to ascii file if specified @type filename: string @return: Returns a list of cc values @author: Thomas Hrabe @rtype: list[floats] """ from pytom.basic.correlation import bandCC from pytom.tools.macros import volumesSameSize from pytom.basic.structures import Mask import pytom_volume if not volumesSameSize(volume1, volume2): raise RuntimeError('Volumes must have the same size!') if mask: if mask.__class__ == pytom_volume.vol: volume1 = volume1 * mask volume2 = volume2 * mask elif mask.__class__ == Mask: mask = mask.getVolume() volume1 = volume1 * mask volume2 = volume2 * mask elif mask.__class__ == str: mask = pytom_volume.read(mask) volume1 = volume1 * mask volume2 = volume2 * mask else: raise RuntimeError('FSC: Mask must be a volume OR a Mask object OR a string path to a mask!') fscResult = [] band = [-1,-1] increment = int(volume1.sizeX()/2 * 1/numberBands) for i in range(0,volume1.sizeX()//2, increment): band[0] = i band[1] = i + increment if verbose: print('Band : ' ,band) res = bandCC(volume1,volume2,band,verbose) if i == 0 and increment == 1: #force a 1 for correlation of the zero frequency res[0] = 1 if verbose: print('Correlation ' ,res[0]) fscResult.append(res[0]) if filename: f = open(filename,'w') for item in fscResult: f.write("%s\n" % item) f.close() return fscResult
def weightedXCC(volume,reference,numberOfBands,wedgeAngle=-1): """ weightedXCC: Determines the band weighted correlation coefficient for a volume and reference. Notation according Steward/Grigorieff paper @param volume: A volume @type volume: L{pytom_volume.vol} @param reference: A reference of same size as volume @type reference: L{pytom_volume.vol} @param numberOfBands: Number of bands @param wedgeAngle: A optional wedge angle @return: The weighted correlation coefficient @rtype: float @author: Thomas Hrabe """ import pytom_volume from pytom.basic.fourier import fft from math import sqrt import pytom_freqweight result = 0 numberVoxels = 0 #volume.write('vol.em'); #reference.write('ref.em'); fvolume = fft(volume) freference = fft(reference) numelem = volume.numelem() fvolume.shiftscale(0,1/float(numelem)) freference.shiftscale(0,1/float(numelem)) from pytom.basic.structures import WedgeInfo wedge = WedgeInfo(wedgeAngle) wedgeVolume = wedge.returnWedgeVolume(volume.sizeX(),volume.sizeY(),volume.sizeZ()) increment = int(volume.sizeX()/2 * 1/numberOfBands) band = [0,100] for i in range(0,volume.sizeX()/2, increment): band[0] = i band[1] = i + increment r = bandCC(volume,reference,band) cc = r[0] #print cc; filter = r[1] #get bandVolume bandVolume = filter.getWeightVolume(True) filterVolumeReduced = bandVolume * wedgeVolume filterVolume = pytom_volume.reducedToFull(filterVolumeReduced) #determine number of voxels != 0 N = pytom_volume.numberSetVoxels(filterVolume) w = sqrt(1/float(N)) #add to number of total voxels numberVoxels=numberVoxels + N #print 'w',w; #print 'cc',cc; #print 'N',N; cc2 = cc*cc #print 'cc2',cc2; if cc <= 0.0: cc = cc2 else: cc = cc2/(cc+w) #print 'cc',cc; cc = cc *cc *cc; #no abs #print 'cc',cc; #add up result result = result + cc*N return result*(1/float(numberVoxels))