def welch_pw2(img, win_size=512, overlp_x=50, overlp_y=50, edge_x=0, edge_y=0): """ Calculate the power spectrum using Welch periodograms (overlapped periodogram) """ from fundamentals import window2d, ramp from EMAN2 import periodogram nx = img.get_xsize() ny = img.get_ysize() nx_fft = smallprime(nx) ny_fft = smallprime(ny) img1 = window2d(img,nx_fft,ny_fft,"l") x_gaussian_hi = 1./win_size del img from filter import filt_gaussh from utilities import info, drop_image e_fil = filt_gaussh(img1, x_gaussian_hi) x38 = 100/(100-overlp_x) # normalization of % of the overlap in x x39 = 100/(100-overlp_y) # normalization of % of the overlap in y x26 = int(x38*((nx-2*edge_x)/win_size-1)+1) # number of pieces horizontal dim.(X) x29 = int(x39*((ny-2*edge_y)/win_size-1)+1) # number of pieces vertical dim.(Y) iz = 0 pw2 = EMData() for iy in xrange(1, x29+1): x21 = (win_size/x39)*(iy-1) + edge_y # y-direction it should start from 0 if edge_y=0 for ix in xrange(1, x26+1): x22 = (win_size/x38)*(ix-1) + edge_x # x-direction it should start from 0 if edge_x =0 wi = window2d(e_fil, win_size, win_size, "l", x22, x21) ra = ramp(wi) iz = iz+1 if (iz == 1): pw2 = periodogram(ra) else: pw2 += periodogram(ra) return pw2/float(iz)
def welch_pw2(img, win_size=512, overlp_x=50, overlp_y=50, edge_x=0, edge_y=0): """ Calculate the power spectrum using Welch periodograms (overlapped periodogram) """ from fundamentals import window2d, ramp from EMAN2 import periodogram nx = img.get_xsize() ny = img.get_ysize() nx_fft = smallprime(nx) ny_fft = smallprime(ny) x_gaussian_hi = 1./win_size from filter import filt_gaussh e_fil = filt_gaussh(window2d(img,nx_fft,ny_fft,"l"), x_gaussian_hi) x38 = 100/(100-overlp_x) # normalization of % of the overlap in x x39 = 100/(100-overlp_y) # normalization of % of the overlap in y x26 = int(x38*((nx-2*edge_x)/win_size-1)+1) # number of pieces horizontal dim.(X) x29 = int(x39*((ny-2*edge_y)/win_size-1)+1) # number of pieces vertical dim.(Y) iz = 0 pw2 = EMData() for iy in xrange(1, x29+1): x21 = (win_size/x39)*(iy-1) + edge_y # y-direction it should start from 0 if edge_y=0 for ix in xrange(1, x26+1): x22 = (win_size/x38)*(ix-1) + edge_x # x-direction it should start from 0 if edge_x =0 wi = window2d(e_fil, win_size, win_size, "l", x22, x21) iz = iz+1 if (iz == 1): pw2 = periodogram(ramp(wi)) else: pw2 += periodogram(ramp(wi)) return pw2/float(iz)
def tilemic(img, win_size=512, overlp_x=50, overlp_y=50, edge_x=0, edge_y=0): """ Calculate the power spectrum using Welch periodograms (overlapped periodogram) """ from fundamentals import window2d, ramp from EMAN2 import periodogram nx = img.get_xsize() ny = img.get_ysize() nx_fft = smallprime(nx) ny_fft = smallprime(ny) x_gaussian_hi = 1./win_size from filter import filt_gaussh e_fil = filt_gaussh(window2d(img,nx_fft,ny_fft,"l"), x_gaussian_hi) x38 = 100/(100-overlp_x) # normalization of % of the overlap in x x39 = 100/(100-overlp_y) # normalization of % of the overlap in y x26 = int(x38*((nx-2*edge_x)/win_size-1)+1) # number of pieces horizontal dim.(X) x29 = int(x39*((ny-2*edge_y)/win_size-1)+1) # number of pieces vertical dim.(Y) pw2 = [] for iy in xrange(1, x29+1): x21 = (win_size/x39)*(iy-1) + edge_y # y-direction it should start from 0 if edge_y=0 for ix in xrange(1, x26+1): x22 = (win_size/x38)*(ix-1) + edge_x # x-direction it should start from 0 if edge_x =0 wi = ramp( window2d(e_fil, win_size, win_size, "l", x22, x21) ) st = Util.infomask(wi, None, True) wi = (wi - st[0])/st[1]*win_size pw2.append(periodogram(wi)) return pw2
def welch_pw2_tilt_band(img, theta, num_bnd=-1, overlp_y=50, edge_x=0, edge_y=0, win_s=256): """ 1. Calculate the power spectra of tilt bands 2. The tilt micrograph is rotated such that the tilt axis is vertical (along Y axis) 3. edge_x and edge_y are removed from the micrograph """ from EMAN2 import periodogram nx = img.get_xsize() ny = img.get_ysize() num1 = int(nx - 2 * edge_x) num2 = int(ny - 2 * edge_y) nx_fft = smallprime(num1) ny_fft = smallprime(num2) img1 = window2d(img, nx_fft, ny_fft, "l", edge_x, edge_y) if (num_bnd == -1): num_bnd = int(nx_fft / win_s) win_x = int(win_s) else: win_x = int(nx_fft / num_bnd) win_x = int(smallprime(win_x)) win_y = win_x x_gaussian_hi = 1. / win_x del img from filter import filt_gaussh from utilities import drop_image, rot_image # The input img is rotated such that tilt axis is vertical img2 = rot_image(img1, theta, 0, 0, 1.0, 1.0) e_fil = filt_gaussh(img2, x_gaussian_hi) del img1 del img2 x39 = 100 / (100 - overlp_y) # normalization of % of the overlap in y x29 = int(x39 * ((ny) / win_y - 1) + 1) # number of pieces vertical dim.(Y) pw2 = EMData() pw2_band = [] for ix in xrange(1, num_bnd + 1): x22 = (win_x) * (ix - 1 ) # x-direction it should start from 0 if edge_x =0 iz = 0 for iy in xrange(1, x29 + 1): x21 = (win_y / x39) * ( iy - 1) # y-direction it should start from 0 if edge_y=0 wi = window2d(e_fil, win_x, win_y, "l", x22, x21) iz = iz + 1 if (iz == 1): pw2 = periodogram(ramp(wi)) else: pw2 += periodogram(ramp(wi)) pw2 /= float(iz) # drop_image(pw2,"band%03d"%(ix)) pw2_band.append(pw2) return pw2_band
def welch_pw2_tilt_band(img,theta,num_bnd=-1,overlp_y=50,edge_x=0,edge_y=0,win_s=256): """ 1. Calculate the power spectra of tilt bands 2. The tilt micrograph is rotated such that the tilt axis is vertical (along Y axis) 3. edge_x and edge_y are removed from the micrograph """ from EMAN2 import periodogram nx = img.get_xsize() ny = img.get_ysize() num1 = int(nx-2*edge_x) num2 = int(ny-2*edge_y) nx_fft = smallprime(num1) ny_fft = smallprime(num2) img1 = window2d(img,nx_fft,ny_fft,"l",edge_x,edge_y) if(num_bnd == -1): num_bnd = int(nx_fft/win_s) win_x = int(win_s) else: win_x = int(nx_fft/num_bnd) win_x = int(smallprime(win_x)) win_y = win_x x_gaussian_hi = 1./win_x del img from filter import filt_gaussh from utilities import drop_image, rot_image # The input img is rotated such that tilt axis is vertical img2 = rot_image(img1,theta, 0, 0, 1.0,1.0) e_fil = filt_gaussh(img2, x_gaussian_hi) del img1 del img2 x39 = 100/(100-overlp_y) # normalization of % of the overlap in y x29 = int(x39*((ny)/win_y-1)+1) # number of pieces vertical dim.(Y) pw2 = EMData() pw2_band = [] for ix in xrange(1, num_bnd+1): x22 = (win_x)*(ix-1)# x-direction it should start from 0 if edge_x =0 iz=0 for iy in xrange(1, x29+1): x21 = (win_y/x39)*(iy-1) # y-direction it should start from 0 if edge_y=0 wi = window2d(e_fil,win_x, win_y,"l",x22, x21) ra = ramp(wi) iz = iz+1 if (iz == 1): pw2 = periodogram(ra) else: pw2 += periodogram(ra) pw2/=float(iz) # drop_image(pw2,"band%03d"%(ix)) pw2_band.append(pw2) return pw2_band