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 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
NA = .3 lam = .5 w = .8 dn0 = 0.1 x = dx*(np.arange(-Nx/2, Nx/2)+.5) y = dx*(np.arange(-Nx/2, Nx/2)+.5) z = dx*(np.arange(-Nz/2, Nz/2)+.5) Z,Y,X = np.meshgrid(z,y,x,indexing="ij") Z,X = np.cos(w)*Z-np.sin(w)*X, np.cos(w)*X+np.sin(w)*Z dn = dn0*(Z>0) u0 = psf_u0((Nx,Nx), units = (dx,)*2,zfoc = dx*(Nz-1.)/2.,lam = lam, NA= NA) u = bpm_3d((Nx,Nx,Nz), units=(dx,)*3, lam=lam, dn =dn, u0=u0) u1 = np.abs(u[:Nz/2,...])[::-1,...]**2 u2 = gputools.rotate(abs(u[Nz/2:,...])**2, center = (0,Nx/2,Nx/2), axis = (0.,1.,0), angle = phi(dn0,w), mode = "linear") pylab.figure(1) pylab.clf() pylab.plot(u1[Nz/10,Nx/2,:]) pylab.plot(u2[Nz/10,Nx/2,:])
from six.moves import range if __name__ == '__main__': Nx, Nz = 256,512 dx = .5 #n = 0.05*dx*np.random.uniform(0,1.,(Nz,Nx,Nx)) #n = .05*gputools.perlin3((Nx,Nx,Nz),(4.,)*3) n = np.zeros((Nz,Nx,Nx)) m = Bpm3d((Nx,Nx,Nz),(dx,)*3) u = ones((Nz,Nx,Nx),complex64) u[0] = bpm.psf_u0((Nx,Nx),(dx,dx),dx*Nz/2.,NA=.1) u[0] *= 1./np.sqrt(np.mean(abs(u[0])**2)) t = time() x = np.linspace(-Nx,Nx,Nx+1)[:Nx] Y,X = np.meshgrid(x,x,indexing = "ij") h0 = np.exp(-.1*(X**2+Y**2)) h0 *= 1./sum(h0) h0_f = np.fft.fftn(h0) for i in range(Nz-1): _u = u[i] _u = fft.fftn(_u) _u *= m._H _u = fft.ifftn(_u) #_u *= exp(-dx*1.j*m.k0*n[i+1])
#dn[Nz/2:,...] = 0.0 m = Bpm3d((Nx,Nx,Nz),(dx,)*3) def prop(n0): H0 = np.sqrt(n0**2*m.k0**2-m._KX**2-m._KY**2) outsideInds = np.isnan(H0) H = np.exp(-1.j*dx*H0) H[outsideInds] = 0. return H u0 = bpm.psf_u0((Nx,Nx),(dx,dx),dx*Nz/2.,NA=.3) u0 *= 1./np.sqrt(np.mean(abs(u0)**2)) #u0 = ones((Nx,Nx),complex64) u1 = ones((Nz,Nx,Nx),complex64) u1[0] = u0 H1 = prop(1.) t = time() n0 = 1. for i in range(Nz-1): _u = u1[i] _u = fft.fftn(_u) _u *= H1 _u = fft.ifftn(_u) _u *= exp(-dx*1.j*m.k0*(n[i+1]-n0))
from six.moves import range if __name__ == '__main__': Nx, Nz = 256, 512 dx = .5 #n = 0.05*dx*np.random.uniform(0,1.,(Nz,Nx,Nx)) #n = .05*gputools.perlin3((Nx,Nx,Nz),(4.,)*3) n = np.zeros((Nz, Nx, Nx)) m = Bpm3d((Nx, Nx, Nz), (dx, ) * 3) u = ones((Nz, Nx, Nx), complex64) u[0] = bpm.psf_u0((Nx, Nx), (dx, dx), dx * Nz / 2., NA=.1) u[0] *= 1. / np.sqrt(np.mean(abs(u[0])**2)) t = time() x = np.linspace(-Nx, Nx, Nx + 1)[:Nx] Y, X = np.meshgrid(x, x, indexing="ij") h0 = np.exp(-.1 * (X**2 + Y**2)) h0 *= 1. / sum(h0) h0_f = np.fft.fftn(h0) for i in range(Nz - 1): _u = u[i] _u = fft.fftn(_u) _u *= m._H _u = fft.ifftn(_u) #_u *= exp(-dx*1.j*m.k0*n[i+1])
w = .8 dn0 = 0.1 x = dx * (np.arange(-Nx / 2, Nx / 2) + .5) y = dx * (np.arange(-Nx / 2, Nx / 2) + .5) z = dx * (np.arange(-Nz / 2, Nz / 2) + .5) Z, Y, X = np.meshgrid(z, y, x, indexing="ij") Z, X = np.cos(w) * Z - np.sin(w) * X, np.cos(w) * X + np.sin(w) * Z dn = dn0 * (Z > 0) u0 = psf_u0((Nx, Nx), units=(dx, ) * 2, zfoc=dx * (Nz - 1.) / 2., lam=lam, NA=NA) u = bpm_3d((Nx, Nx, Nz), units=(dx, ) * 3, lam=lam, dn=dn, u0=u0) u1 = np.abs(u[:Nz / 2, ...])[::-1, ...]**2 u2 = gputools.rotate(abs(u[Nz / 2:, ...])**2, center=(0, Nx / 2, Nx / 2), axis=(0., 1., 0), angle=phi(dn0, w), mode="linear") pylab.figure(1) pylab.clf() pylab.plot(u1[Nz / 10, Nx / 2, :])
subsample = 1, n_volumes = 1, return_scattering = True ) u2, dn2, p2 = bpm_3d_old((Nx,Nx,Nz),units= units, lam = lam, dn = dn, return_scattering = True ) return u1, u2 if __name__ == '__main__': # test_speed() #u = test_sphere() N = 256 dx = .05 from bpm import psf_u0 if not "dn" in locals(): dn = np.zeros((N,)*3,np.float32) dn[:40,...] += .2 u0 = psf_u0((N,)*2,(dx,)*2,zfoc = N/2.*dx,NA = .4) u1 = bpm_3d(dn.shape[::-1],(dx,)*3, u0=u0,dn = dn, n_volumes=1) #u2 = _bpm_3d2(dn.shape[::-1],(dx,)*3, u0=u0,dn = dn)