def test_focus(size, units, NA = .3, n0 = 1.): """ propagates a focused wave freely to the center """ Nx, Ny, Nz = size dx, dy , dz = .1, .1, .1 lam = .5 _, u_debye, _, _ = psf(size, units, n0= n0, lam=lam, NA=NA, return_field = True) u0 = u_debye[0] u0 = psf_u0(size[:2],units[:2], zfoc = .5*units[-1]*(size[-1]-1), n0 = n0, lam = lam, NA = NA) u = bpm_3d(size,units= units, lam = lam, n0 = n0, u0 = u0, absorbing_width = 0) return u, u_debye
def compare_with_file(fname, dx, NA, lam, n): u1 = read3dTiff(fname) Nz, Ny, Nx = u1.shape u2 = psf((Nx, Ny, Nz), (dx, ) * 3, lam, NA, n0=n) u1 *= 1. / np.amax(u1) u2 *= 1. / np.amax(u2) x = dx * (np.arange(Nx) - Nx / 2) z = dx * (np.arange(Nz) - Nz / 2) pylab.clf() pylab.subplot(2, 1, 1) pylab.title("NA = %s n = %s" % (NA, n)) pylab.plot(x, u1[Nz / 2, Ny / 2, :], label="file_x") pylab.plot(x, u2[Nz / 2, Ny / 2, :], label="u_x") pylab.plot(x, theory_x(x, lam, NA, n), color="k", label="theor_x") pylab.legend() pylab.subplot(2, 1, 2) pylab.plot(z, u1[:, Ny / 2, Nx / 2], label="file_z") pylab.plot(z, u2[:, Ny / 2, Nx / 2], label="u_z") pylab.plot(z, theory_z(z, lam, NA, n), color="k", label="theor_z") #pylab.plot(z,theory_debye_z(z,lam,NA,n),"o",color="r",label="debye_z") pylab.legend() pylab.show() return u1, u2
def compare_with_theory(shape, dx, NA, lam, n): Nz, Ny, Nx = shape u2 = psf((Nx, Ny, Nz), (dx, ) * 3, lam, NA, n0=n) u2 *= 1. / np.amax(u2) x = dx * (np.arange(Nx) - Nx / 2) z = dx * (np.arange(Nz) - Nz / 2) # pylab.plot(x,u2[Nz/2,Ny/2,:],label="u2_x") # pylab.plot(x,theory_x(x,lam,NA,n),color="k",label="theor_x") #pylab.figure() pylab.clf() pylab.subplot(2, 1, 1) pylab.plot(x, u2[Nz / 2, Ny / 2, :], label="u2_x") pylab.plot(x, theory_x(x, lam, NA, n), label="theor_x") #pylab.plot(x,theory_debye_x(x,lam,NA,n),label="debye_x") pylab.title("NA = %s n = %s" % (NA, n)) pylab.legend() pylab.subplot(2, 1, 2) pylab.plot(z, u2[:, Ny / 2, Nx / 2], label="u2_z") pylab.plot(z, theory_z(z, lam, NA, n), label="theor_z") pylab.plot(z, theory_debye_z(z, lam, NA, n), label="debye_z") pylab.legend() pylab.show() return u2
def test_focus(size, units, NA=.3, n0=1.): """ propagates a focused wave freely to the center """ Nx, Ny, Nz = size dx, dy, dz = .1, .1, .1 lam = .5 _, u_debye, _, _ = psf(size, units, n0=n0, lam=lam, NA=NA, return_field=True) u0 = u_debye[0] u0 = psf_u0(size[:2], units[:2], zfoc=.5 * units[-1] * (size[-1] - 1), n0=n0, lam=lam, NA=NA) u = bpm_3d(size, units=units, lam=lam, n0=n0, u0=u0, absorbing_width=0) return u, u_debye
def compare_with_theory(shape, dx, NA,lam,n): Nz,Ny,Nx = shape u2 = psf((Nx, Ny, Nz), (dx,) * 3, lam, NA, n0=n) u2 *= 1./np.amax(u2) x = dx*(np.arange(Nx)-Nx/2) z = dx*(np.arange(Nz)-Nz/2) # pylab.plot(x,u2[Nz/2,Ny/2,:],label="u2_x") # pylab.plot(x,theory_x(x,lam,NA,n),color="k",label="theor_x") #pylab.figure() pylab.clf() pylab.subplot(2,1,1) pylab.plot(x,u2[Nz/2,Ny/2,:],label="u2_x") pylab.plot(x,theory_x(x,lam,NA,n),label="theor_x") #pylab.plot(x,theory_debye_x(x,lam,NA,n),label="debye_x") pylab.title("NA = %s n = %s"%(NA,n)) pylab.legend() pylab.subplot(2,1,2) pylab.plot(z,u2[:,Ny/2,Nx/2],label="u2_z") pylab.plot(z,theory_z(z,lam,NA,n),label="theor_z") pylab.plot(z,theory_debye_z(z,lam,NA,n),label="debye_z") pylab.legend() pylab.show() return u2
def compare_with_file(fname,dx, NA,lam,n): u1 = read3dTiff(fname) Nz,Ny,Nx = u1.shape u2 = psf((Nx, Ny, Nz), (dx,) * 3, lam, NA, n0=n) u1 *= 1./np.amax(u1) u2 *= 1./np.amax(u2) x = dx*(np.arange(Nx)-Nx/2) z = dx*(np.arange(Nz)-Nz/2) pylab.clf() pylab.subplot(2,1,1) pylab.title("NA = %s n = %s"%(NA,n)) pylab.plot(x,u1[Nz/2,Ny/2,:],label="file_x") pylab.plot(x,u2[Nz/2,Ny/2,:],label="u_x") pylab.plot(x,theory_x(x,lam,NA,n),color="k",label="theor_x") pylab.legend() pylab.subplot(2,1,2) pylab.plot(z,u1[:,Ny/2,Nx/2],label="file_z") pylab.plot(z,u2[:,Ny/2,Nx/2],label="u_z") pylab.plot(z,theory_z(z,lam,NA,n),color="k",label="theor_z") #pylab.plot(z,theory_debye_z(z,lam,NA,n),"o",color="r",label="debye_z") pylab.legend() pylab.show() return u1, u2
def _get_error(shape, dx, NA,lam,n): Nz,Ny,Nx = shape u2 = psf((Nx, Ny, Nz), (dx,) * 3, lam, NA, n0=n) u2 *= 1./np.amax(u2) x = dx*(np.arange(Nx)-Nx/2) z = dx*(np.arange(Nz)-Nz/2) u2_z = u2[:,Ny/2,Nx/2] u_z = theory_z(z,lam,NA,n) u2_x = u2[Nz/2,Ny/2,:] u_x = theory_x(x,lam,NA,n) return np.sqrt(np.mean((u_x-u2_x)**2))+np.sqrt(np.mean((u_z-u2_z)**2))
def _get_error(shape, dx, NA, lam, n): Nz, Ny, Nx = shape u2 = psf((Nx, Ny, Nz), (dx, ) * 3, lam, NA, n0=n) u2 *= 1. / np.amax(u2) x = dx * (np.arange(Nx) - Nx / 2) z = dx * (np.arange(Nz) - Nz / 2) u2_z = u2[:, Ny / 2, Nx / 2] u_z = theory_z(z, lam, NA, n) u2_x = u2[Nz / 2, Ny / 2, :] u_x = theory_x(x, lam, NA, n) return np.sqrt(np.mean((u_x - u2_x)**2)) + np.sqrt(np.mean( (u_z - u2_z)**2))
u = abs(ex)**2+abs(ey)**2+abs(ez)**2 return u,ex,ey,ez if __name__ == '__main__': NA = .95 lam = .5 Nx = 256 Ny = 164 Nz = 100 dx = 0.008 u, ex,ey,ez = psf((Nx,Ny,Nz),(dx,)*3,lam=lam, NA = NA, return_field=True) # x = dx*(np.arange(Nx)-Nx/2.) y = dx*(np.arange(Ny)-Ny/2.) ex0 = np.array([debye_integral_at_point(_x,.5*dx,.5*dx, 2*np.pi/lam,NA, n_int = 1000)[1] for _x in x]) ex1 = np.array([debye_integral_at_point(.5*dx,_x,.5*dx, 2*np.pi/lam,NA, n_int = 1000)[1] for _x in x]) #ex1 = ex[Nz/2,Ny/2,:]
u = abs(ex)**2 + abs(ey)**2 + abs(ez)**2 return u, ex, ey, ez if __name__ == '__main__': NA = .95 lam = .5 Nx = 256 Ny = 164 Nz = 100 dx = 0.008 u, ex, ey, ez = psf((Nx, Ny, Nz), (dx, ) * 3, lam=lam, NA=NA, return_field=True) # x = dx * (np.arange(Nx) - Nx / 2.) y = dx * (np.arange(Ny) - Ny / 2.) ex0 = np.array([ debye_integral_at_point(_x, .5 * dx, .5 * dx, 2 * np.pi / lam, NA, n_int=1000)[1] for _x in x ]) ex1 = np.array([