def test_rmsspotsize(): """ TODO """ raybundle = RayBundle(x0=np.array([[1, 0, 0, 1, 2], [0, 1, 0, 1, 2], [0, 0, 1, 1, 2]]), k0=np.zeros((3, 5)), Efield0=np.zeros((3, 5))) rayanalysis = RayBundleAnalysis(raybundle) rmssize = rayanalysis.getRMSspotSize(np.array([0, 0, 0])) assert np.isclose(rmssize, math.sqrt(18.0 / 4.0))
def test_centroid(): """ TODO """ raybundle = RayBundle(x0=np.array([[1, 0, 0, 1, 2], [0, 1, 0, 1, 2], [0, 0, 1, 1, 2]]), k0=np.zeros((3, 5)), Efield0=np.zeros((3, 5))) rayanalysis = RayBundleAnalysis(raybundle) centroid = rayanalysis.getCentroidPosition() assert np.allclose(centroid, 4. / 5.)
def bundle_step1(nrays=100, rpup=7.5): """ Creates an on-axis collimated RayBundle for step 1. """ (px, py) = RectGrid().getGrid(nrays) o = np.vstack((rpup * px, rpup * py, np.zeros_like(px))) k = np.zeros_like(o) k[2, :] = 1. #2.*math.pi/wavelength E0 = np.cross(k, canonical_ex, axisa=0, axisb=0).T return RayBundle(o, k, E0, wave=dline)
def meritfunctionrms(s): initialbundle_local = RayBundle(x0=o, k0=k, Efield0=E0, wave=wavelength) rpaths = s.seqtrace(initialbundle_local, sysseq) # other constructions lead to fill up of initial bundle with intersection values # for glassy asphere only one path necessary x = rpaths[0].raybundles[-1].x[-1, 0, :] y = rpaths[0].raybundles[-1].x[-1, 1, :] res = np.sum(x**2 + y**2) return res
def test_direction_centroid(): """ TODO """ k0 = np.zeros((3, 5)) k0[2, :] = 1 E0 = np.zeros((3, 5)) E0[1, :] = 1. raybundle = RayBundle(x0=np.array([[1, 0, 0, 1, 2], [0, 1, 0, 1, 2], [0, 0, 1, 1, 2]]), k0=k0, Efield0=E0) rayanalysis = RayBundleAnalysis(raybundle) centroiddir = rayanalysis.getCentroidDirection() assert np.allclose(centroiddir, np.array([0, 0, 1]))
def bundles_step3(nrays=100, rpup=7.5, maxfield_deg=2.): """ Creates an array of collimated RayBundle objects for step 3. """ bundles = [] fields_rad = np.array([0, .5 * np.sqrt(2), 1]) * maxfield_deg * pi / 180. (px, py) = RectGrid().getGrid(nrays) for field in fields_rad: starty = -30 * np.tan( field ) # TODO: this step explicitly sets the pupil, so the stop position is ignored. Better get Aimy to run ... o = np.vstack((rpup * px, rpup * py + starty, np.zeros_like(px))) k = np.zeros_like(o) k[1, :] = np.sin(field) k[2, :] = np.cos(field) E0 = np.cross(k, canonical_ex, axisa=0, axisb=0).T bundles += [RayBundle(o, k, E0, wave=Fline)] bundles += [RayBundle(o, k, E0, wave=dline)] bundles += [RayBundle(o, k, E0, wave=Cline)] return bundles
def final_meritfunction(s, rpup, fno, maxfield_deg): """ Merit function (=function to be minimized) for step 3 and following. """ merit = 0 initialbundles = bundles_step3(rpup=rpup, maxfield_deg=maxfield_deg) for (ind, b) in enumerate(initialbundles): rpaths = s.seqtrace(b, seq) x = rpaths[0].raybundles[-1].x[-1, 0, :] #y = rpaths[0].raybundles[-1].x[-1, 1, :] #x = x - np.sum(x) / ( float(len(x)) + 1E-200 ) #y = y - np.sum(y) / ( float(len(y)) + 1E-200 ) rba.raybundle = rpaths[0].raybundles[-1] merit += rba.getRMSspotSizeCentroid() #np.sum(x**2 + y**2) # FIXME: somehow this former calculation leads not to a useful rms spot calculation and therefore # the decz variable is not changed; the rba.getRMS... function is slower but leads to a change in thickness merit += 1. / (len(x) + 1e-18) #10000.*math.exp(-len(x)) # biconvex lens with same radii merit += 10000* ( s.elements["stdelem"].surfaces["lens4front"].shape.curvature() \ + s.elements["stdelem"].surfaces["lens4rear"].shape.curvature() )**2 # outer radii of both doulets should be symmetric merit += 10000* ( s.elements["stdelem"].surfaces["elem2front"].shape.curvature() \ + s.elements["stdelem"].surfaces["elem3rear"].shape.curvature() )**2 # inner radii of both doulets should be symmetric merit += 10000* ( s.elements["stdelem"].surfaces["elem2rear"].shape.curvature() \ + s.elements["stdelem"].surfaces["elem3front"].shape.curvature() )**2 # f number o = np.array([[0], [7.5], [0]]) k = np.zeros_like(o) k[2, :] = 1 E0 = np.cross(k, canonical_ex, axisa=0, axisb=0).T initial_marginal = RayBundle(o, k, E0, wave=dline) marginal_path = s.seqtrace(initial_marginal, seq) kyim = marginal_path[0].raybundles[-1].k[-1, 1, :] kzim = marginal_path[0].raybundles[-1].k[-1, 2, :] merit += 10 * sum(fno + .5 * np.real(kzim) / np.real(kyim))**2 return merit
def generatebundle(openangle=0.01, numrays=11): o = np.zeros((3, numrays)) k = np.zeros_like(o) angles = np.linspace(-openangle, openangle, num=numrays) k0 = 1. #2.*math.pi/wavelength k[1, :] = k0 * np.sin(angles) k[2, :] = k0 * np.cos(angles) ey = np.zeros_like(o) ey[1, :] = 1. E0 = np.cross(k, ey, axisa=0, axisb=0).T return RayBundle(x0=o, k0=k, Efield0=E0, wave=wavelength)
def test_rms_angularsize(): """ TODO """ k0 = np.zeros((3, 5)) k0[2, :] = 1 E0 = np.zeros((3, 5)) E0[1, :] = 1. raybundle = RayBundle(x0=np.array([[1, 0, 0, 1, 2], [0, 1, 0, 1, 2], [0, 0, 1, 1, 2]]), k0=k0, Efield0=E0) rayanalysis = RayBundleAnalysis(raybundle) angularsize = rayanalysis.getRMSangluarSize( np.array([ math.sin(1. * math.pi / 180.0), 0, math.cos(1. * math.pi / 180.0) ])) assert np.isclose(angularsize, (1. * math.pi / 180.0))
def test_arc_length(): """ TODO """ k0 = np.zeros((3, 2)) E0 = np.zeros((3, 2)) raybundle = RayBundle(x0=np.array([[0, 0], [0, 0], [0, 0]]), k0=k0, Efield0=E0) x1 = np.array([[1, 0], [0, 0], [0, 0]]) x2 = np.array([[1, 1], [1, 1], [0, 0]]) x3 = np.array([[0, 2], [1, 2], [0, 0]]) x4 = np.array([[0, 3], [0, 3], [0, 0]]) valid = np.ones_like([1, 1]) raybundle.append(x1, k0, E0, valid) raybundle.append(x2, k0, E0, valid) raybundle.append(x3, k0, E0, valid) raybundle.append(x4, k0, E0, valid) arclen = RayBundleAnalysis(raybundle).getArcLength() assert np.allclose(arclen, np.array([4., 3 * np.sqrt(2)]))
("m2", False, {}), ("m1", False, {}), ("m2", False, {}), ("m1", False, {}), ("m2", False, {}) ]) ] phi = 5.*math.pi/180.0 obj_dx = 0.1 obj_dphi = 1.*math.pi/180.0 kwave = 2.*math.pi/wavelength initialbundle = RayBundle(x0=o, k0=k, Efield0=E0, wave=wavelength) r2 = s.seqtrace(initialbundle, sysseq) #pilotbundle = RayBundle( # x0 = np.array([[0], [0], [0]]), # k0 = np.array([[0], [kwave*math.sin(phi)], [kwave*math.cos(phi)]]), # Efield0 = np.array([[1], [0], [0]]), wave=wavelength # ) #pilotray = s.seqtrace(pilotbundle, sysseq_pilot) pilotbundles = core.helpers.build_pilotbundle(objectsurf, air, (obj_dx, obj_dx), (obj_dphi, obj_dphi), num_sampling_points=3) rays_pilot = [s.seqtrace(p, sysseq) for p in pilotbundles] (pilotray2, r3) = s.para_seqtrace(pilotbundles[-1], initialbundle, sysseq, use6x6=False)
sysseq = [("droplet", [("stop", { "is_stop": True }), ("surf1", {}), ("surf2", { "is_mirror": True }), ("surf3", {}), ("image", {})])] sysseq2nd = [("droplet", [("stop", { "is_stop": True }), ("surf1", {}), ("surf2", { "is_mirror": True }), ("surf3", {}), ("image", {})])] phi = 5. * math.pi / 180.0 initialbundle_red = RayBundle(x0=o, k0=k_red, Efield0=E0_red, wave=wave_red) initialbundle_blue = RayBundle(x0=o, k0=k_blue, Efield0=E0_blue, wave=wave_blue) r_red = s.seqtrace(initialbundle_red, sysseq) r_blue = s.seqtrace(initialbundle_blue, sysseq) #r_red2nd = s.seqtrace(initialbundle_red, sysseq2nd) #r_blue2nd = s.seqtrace(initialbundle_blue, sysseq2nd) fig = plt.figure(1) ax = fig.add_subplot(111) ax.axis('equal') if StrictVersion(matplotlib.__version__) < StrictVersion('2.0.0'):
# benchmark # definition of rays #nray = 1E5 # number of rays #aimy = aim.aimFiniteByMakingASurfaceTheStop(s, pupilType=pupil.ObjectSpaceNA, #.StopDiameter, # pupilSizeParameter=0.2,#3.0, # fieldType= field.ObjectHeight, # rasterType= raster.RectGrid, # nray=nray, wavelength=wavelength, stopPosition=5) #initialBundle = aimy.getInitialRayBundle(s, fieldXY=np.array([0, 0]), wavelength=wavelength) #nray = len(initialBundle.o[0, :]) (x0, k0, E0) = collimated_bundle(nrays, -5., 0., 1., raster.RectGrid()) t0 = time.clock() initialraybundle = RayBundle(x0=x0, k0=k0, Efield0=E0) raypath = s.seqtrace(initialraybundle, seq) logging.info("benchmark : " + str(time.clock() - t0) + "s for tracing " + str(nrays) + " rays through " + str(len(s.elements["stdelem"].surfaces) - 1) + " surfaces.") logging.info(" That is " + str(int(round(nrays * (len(s.elements["stdelem"].surfaces) - 1) / (time.clock() - t0)))) + "ray-surface-operations per second") # plot (x0_draw, k0_draw, E0_draw)= collimated_bundle(nrays_draw, -5., 0., 1., raster.MeridionalFan()) initialraybundle_draw = RayBundle(x0=x0_draw, k0=k0_draw, Efield0=E0_draw) raypath_draw = s.seqtrace(initialraybundle_draw, seq) fig = plt.figure(1) ax = fig.add_subplot(111) ax.axis('equal') if StrictVersion(matplotlib.__version__) < StrictVersion('2.0.0'):
E2 = np.cross(k2, ey, axisa=0, axisb=0).T k3 = np.zeros_like(o) k3[1, :] = math.sin(-15 * degree) k3[2, :] = math.cos(-15 * degree) E3 = np.cross(k3, ey, axisa=0, axisb=0).T sysseq = [("HUD", [("object", { "is_stop": True }), ("d1", {}), ("s1", {}), ("d1p", {}), ("d2", {}), ("s2", { "is_mirror": True }), ("d2p", {}), ("d3", {}), ("s3", { "is_mirror": True }), ("d3p", {}), ("d4", {}), ("s4", {}), ("d4p", {}), ("image", {})])] initialbundle1 = RayBundle(x0=o, k0=k1, Efield0=E1, wave=standard_wavelength) initialbundle2 = RayBundle(x0=o, k0=k2, Efield0=E2, wave=standard_wavelength) initialbundle3 = RayBundle(x0=o, k0=k3, Efield0=E3, wave=standard_wavelength) r1 = s.seqtrace(initialbundle1, sysseq) r2 = s.seqtrace(initialbundle2, sysseq) r3 = s.seqtrace(initialbundle3, sysseq) obj_dx = 0.1 obj_dphi = 5 * degree pilotbundles = core.helpers.build_pilotbundle(objsurf, air, (obj_dx, obj_dx), (obj_dphi, obj_dphi), num_sampling_points=3) rays_pilot = [s.seqtrace(p, sysseq) for p in pilotbundles[2:]] # only last two bundles hit the next surface