def initialize_as_kirkpatrick_baez(cls, p, q, separation, theta, bound1, bound2): p1 = p - 0.5 * separation q1 = p - p1 q2 = q - 0.5 * separation p2 = q - q2 f1p = p1 f1q = p+ q - p1 f2q = q2 f2p = p + q - q2 oe1 = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances(p= f1p, q= f1q, theta= theta, alpha=0., cylindrical=1) #oe1.bound = bound1 oe1.set_bound(bound1) oe1.p = p1 oe1.q = q1 oe2 = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances(p= f2p, q= f2q, theta= theta, alpha=90.*np.pi/180, cylindrical=1) #oe2.bound = bound2 oe2.set_bound(bound2) oe2.p = p2 oe2.q = q2 return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Kirkpatrick Baez")
def test_my_hyperbolic_mirror(): beam = Beam() beam.set_flat_divergence(0.005, 0.0005) p1 = 130. q1 = 0. spherical_mirror = Optical_element.initialize_as_spherical_mirror(p1, q1, theta=0, alpha=0, R=130.) beam = spherical_mirror.trace_optical_element(beam) p = 15 q = p1 - p theta = 0 * np.pi / 180 hyp_mirror = Optical_element.initialize_my_hyperboloid(p, q, theta) beam = hyp_mirror.trace_optical_element(beam) beam.plot_xz() assert_almost_equal(beam.x, 0., 10) assert_almost_equal(beam.y, 0., 10) assert_almost_equal(beam.z, 0., 10) if do_plot: plt.show()
def wolter_for_japanese(cls,p,q,d,q1,theta1,theta2): ############## ellipse #################################################################################### ae = (p+q1)/2 be = np.sqrt(p*q1)*np.cos(theta1) f = np.sqrt(ae**2-be**2) beta = np.arccos((p**2+4*f**2-q1**2)/(4*p*f)) ccc1 = np.array([1. / be ** 2, 1. / be ** 2, 1 / ae ** 2, 0., 0., 0., 0., 0., 0., -1]) y = - p * np.sin(beta) z = f - p * np.cos(beta) oe1 = Optical_element.initialize_as_surface_conic_from_coefficients(ccc1) oe1.set_parameters(p=p, q=q1, theta=theta1) ############## hyperbola #################################################################################### p1 = q1 - d ah = (p1 - q)/2 bh = np.sqrt(p1*q)*np.cos(theta2) z0 = np.sqrt(ae**2-be**2) - np.sqrt(ah**2+bh**2) print("z0 = %f" %z0) ccc2 = np.array([-1. / ah ** 2, -1. / ah ** 2, 1 / bh ** 2, 0., 0., 0., 0., 0., 2 * z0 / bh ** 2, z0 ** 2 / bh ** 2 - 1]) oe2 = Optical_element.initialize_as_surface_conic_from_coefficients(ccc2) oe2.set_parameters(p=p1, q=q, theta=theta2) return CompoundOpticalElement(oe_list=[oe1, oe2], oe_name="Wolter for japanese")
def initialiaze_as_wolter_2(cls,p1,q1,z0): #q1 = - q1 focal = q1+2*z0 print("focal=%f" %(focal)) theta1 = 0. alpha1 = 0. oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p1,0.,theta1,alpha1,"p", focal) oe2 = Optical_element.initialize_my_hyperboloid(p=0. ,q=-(focal-2*z0), theta=90*np.pi/180, alpha=0, wolter=2, z0=z0, distance_of_focalization=focal) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 2")
def test_boundary_condition(): #beam1 = Beam(10000) #beam1.set_point(0, 0, 0) #beam1.set_flat_divergence(5e-3, 5e-2) shadow_beam = run_shadow_source() beam1 = Beam(10000) beam1.initialize_from_arrays( shadow_beam.getshonecol(1), shadow_beam.getshonecol(2), shadow_beam.getshonecol(3), shadow_beam.getshonecol(4), shadow_beam.getshonecol(5), shadow_beam.getshonecol(6), shadow_beam.getshonecol(10), 0 ) bound1=BoundaryRectangle(xmax=0.005,xmin=-0.005,ymax=0.05,ymin=-0.05) bound2=BoundaryRectangle(xmax=0.01,xmin=-0.01,ymax=0.1,ymin=-0.1) plane_mirror=Optical_element.initialize_as_plane_mirror(2,1,65*np.pi/180,0) parabolic_mirror=Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(5,2,28*np.pi/180,90*np.pi/180) plane_mirror.rectangular_bound(bound1) parabolic_mirror.rectangular_bound(bound2) beam1=plane_mirror.trace_optical_element(beam1) beam1=parabolic_mirror.trace_optical_element(beam1) beam1.plot_xz() plt.title("Total points plot") beam1.plot_good_xz() plt.title("Good points plot") print(beam1.flag) indices=np.where(beam1.flag>0) print("The good number of ray are: %f" %(beam1.flag[indices].size)) plt.show() shadow_beam=trace_shadow(shadow_beam) assert_almost_equal(beam1.x, shadow_beam.getshonecol(1), 8) assert_almost_equal(beam1.y, shadow_beam.getshonecol(2), 8) assert_almost_equal(beam1.z, shadow_beam.getshonecol(3), 8)
def initialiaze_as_wolter_1(cls,p1,q1,z0): theta1 = 0. alpha1 = 0. print(q1) print(2*z0) print("dof=%f" %(2*z0-q1)) #oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p1,0.,theta1,alpha1,"p",2*z0-q1) oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p1, 0., theta1, alpha1, "p", 2*z0-q1) #oe2 = Optical_element.initialize_my_hyperboloid(p=0.,q=q1,theta=90*np.pi/180,alpha=0,wolter=1, z0=z0, distance_of_focalization=2*z0-q1) oe2 = Optical_element.initialize_my_hyperboloid(p=0., q=q1, theta=90 * np.pi / 180, alpha=0, wolter=1, z0=z0,distance_of_focalization=2*z0-q1) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 1")
def test_spherical_mirror(): print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_spherical_mirror") beam1 = Beam(5000) beam1.set_point(0, 0, 0) beam1.set_flat_divergence(5e-3, 5e-2) p = 2. q = 1. theta = 30 theta = theta * np.pi / 180 alpha = 0 * np.pi / 180 spherical_mirror = Optical_element.initialize_as_spherical_mirror( p, q, theta, alpha) #spherical_mirror.set_spherical_mirror_radius_from_focal_distances() print(spherical_mirror.R) beam1 = spherical_mirror.trace_optical_element(beam1) beam1.plot_xz() beam1.plot_xpzp() print(np.mean(beam1.flag)) if do_plot: plt.show() assert_almost_equal(np.abs(beam1.x).mean(), 0.0, 2) assert_almost_equal(np.abs(beam1.y).mean(), 0.0, 2) assert_almost_equal(np.abs(beam1.z).mean(), 0.0, 2)
def test_plane_mirror(): print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_plane_mirror") beam1 = Beam(5000) beam1.set_point(0, 0, 0) beam1.set_flat_divergence(5e-3, 5e-2) p = 1. q = 1. theta = np.pi / 4 alpha = 0 plane_mirror = Optical_element.initialize_as_plane_mirror( p, q, theta, alpha) xmin = -10**5 xmax = 10**5 ymin = 10**5 ymax = -10**5 bound = BoundaryRectangle(xmax, xmin, ymax, ymin) plane_mirror.rectangular_bound(bound) beam1 = plane_mirror.trace_optical_element(beam1) beam1.plot_xz() beam1.plot_xpzp() if do_plot: plt.show()
def initialize_as_wolter_3(cls, p, q, distance_between_the_foci): f=-q oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p=p, q=f, theta=0., alpha=0., infinity_location="p") #c = z0+np.abs(f) c = distance_between_the_foci/2 z0 = np.abs(c)-np.abs(f) b = c+100 a = np.sqrt((b**2-c**2)) ccc = np.array([1/a**2, 1/a**2, 1/b**2, 0., 0., 0., 0., 0., -2*z0/b**2, z0**2/b**2-1]) oe2 = Optical_element.initialize_as_surface_conic_from_coefficients(ccc) oe2.set_parameters(p=0., q=z0+z0+np.abs(q), theta=90*np.pi/180) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 3")
def initialiaze_as_wolter_1_with_two_parameters(cls,p1, R, theta): cp1 = -2 * R / np.tan(theta) cp2 = 2 * R * np.tan(theta) cp = max(cp1, cp2) f = cp / 4 print("focal=%f" % (f)) oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p=p1, q=f, theta=0., alpha=0.,infinity_location="p") s1 = R / np.tan(2 * theta) s2 = R / np.tan(4 * theta) c = (s1 - s2) / 2 z0 = f + c b1 = np.sqrt( 0.5 * c ** 2 + 0.5 * R ** 2 + 0.5 * R ** 4 / cp ** 2 - R ** 2 * z0 / cp + 0.5 * z0 ** 2 - 0.5 / cp ** 2 * np.sqrt( ( -c ** 2 * cp ** 2 - cp ** 2 * R ** 2 - R ** 4 + 2 * cp * R ** 2 * z0 - cp ** 2 * z0 ** 2) ** 2 - 4 * cp ** 2 * ( c ** 2 * R ** 4 - 2 * c ** 2 * cp * R ** 2 * z0 + c ** 2 * cp ** 2 * z0 ** 2))) b2 = np.sqrt( 0.5 * c ** 2 + 0.5 * R ** 2 + 0.5 * R ** 4 / cp ** 2 - R ** 2 * z0 / cp + 0.5 * z0 ** 2 + 0.5 / cp ** 2 * np.sqrt( ( -c ** 2 * cp ** 2 - cp ** 2 * R ** 2 - R ** 4 + 2 * cp * R ** 2 * z0 - cp ** 2 * z0 ** 2) ** 2 - 4 * cp ** 2 * ( c ** 2 * R ** 4 - 2 * c ** 2 * cp * R ** 2 * z0 + c ** 2 * cp ** 2 * z0 ** 2))) b = min(b1, b2) a = np.sqrt(c ** 2 - b ** 2) ccc = np.array( [-1 / a ** 2, -1 / a ** 2, 1 / b ** 2, 0., 0., 0., 0., 0., -2 * z0 / b ** 2, z0 ** 2 / b ** 2 - 1]) oe2 = Optical_element.initialize_as_surface_conic_from_coefficients(ccc) oe2.set_parameters(p=0., q=z0+c, theta=90*np.pi/180, alpha=0., type="My hyperbolic mirror") #oe2.type = "My hyperbolic mirror" #oe2.p = 0. #oe2.q = z0 + c #oe2.theta = 90 * np.pi / 180 #oe2.alpha = 0. return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 1")
def initialize_as_montel_parabolic(cls, p, q, theta, bound1, bound2, distance_of_the_screen=None, angle_of_mismatch=0.): beta = (90. - angle_of_mismatch)*np.pi/180 #### angle beetween the two mirror, if angle_of_mismatch is >0 the two mirror are closer oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p=p, q=q, theta=theta, alpha=0., infinity_location='p', focal=q, cylindrical=1) oe1.set_bound(bound1) oe2 = oe1.duplicate() oe2.rotation_surface_conic(beta, 'y') oe2.set_bound(bound2) if distance_of_the_screen == None: distance_of_the_screen = q ccc = np.array([0., 0., 0., 0., 0., 0., 0., 1., 0., -distance_of_the_screen]) screen = Optical_element.initialize_as_surface_conic_from_coefficients(ccc) screen.set_parameters(p, q, 0., 0., "Surface conical mirror") return CompoundOpticalElement(oe_list=[oe1, oe2, screen], oe_name="Montel parabolic")
def initialiaze_as_wolter_12(cls,p1,q1,focal_parabola,Rmin): focal = focal_parabola d = q1 - focal_parabola z0 = focal_parabola + d/2 print("focal=%f" %(focal)) theta1 = 0. alpha1 = 0. oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p1,0.,theta1,alpha1,"p", focal) ccc = oe1.ccc_object.get_coefficients() cp = -ccc[8] print("R=%f, d=%f, cp=%f, z0=%f" %(Rmin,d,cp,z0)) #b1 = np.sqrt(0.125*d**2+Rmin+2*Rmin**4/cp**2-2*Rmin**2*z0/cp+0.5*z0**2-0.125/cp**2*np.sqrt((-cp**2*d**2-8*cp**2*Rmin-16*Rmin**4+16*cp*Rmin**2*z0-4*cp*z0**2)**2-16*cp**2*(4*d**2*Rmin**4-4*cp*d**2*Rmin**2*z0+cp**2*d**2*z0**2))) #b2 = np.sqrt(0.125*d**2+Rmin+2*Rmin**4/cp**2-2*Rmin**2*z0/cp+0.5*z0**2+0.125/cp**2*np.sqrt((-cp**2*d**2-8*cp**2*Rmin-16*Rmin**4+16*cp*Rmin**2*z0-4*cp*z0**2)**2-16*cp**2*(4*d**2*Rmin**4-4*cp*d**2*Rmin**2*z0+cp**2*d**2*z0**2))) p1 = -cp ** 2 * d ** 2 - 8 * cp ** 2 * Rmin - 16 * Rmin ** 4 + 16 * cp * Rmin ** 2 * z0 - 4 * cp ** 2 * z0 ** 2 p1 = p1**2 p2 = 16 * cp ** 2 * (4 * d ** 2 * Rmin ** 4 - 4 * cp * d ** 2 * Rmin ** 2 * z0 + cp ** 2 * d ** 2 * z0 ** 2) sp = 0.125/cp**2*np.sqrt(p1-p2) sp0 = 0.125*d**2+Rmin+2*Rmin**4/cp**2-2*Rmin**2*z0/cp+0.5*z0**2 b = np.sqrt(sp0-sp) a = np.sqrt(d**2/4-b**2) print("a=%f, b=%f" %(a,b)) #oe2 = Optical_element.initialize_my_hyperboloid(p=0. ,q=-(focal-2*z0), theta=90*np.pi/180, alpha=0, wolter=1.1, z0=z0, distance_of_focalization=focal) cc = np.array([-1/a**2, -1/a**2, 1/b**2, 0., 0., 0., 0., 0., -2*z0/b**2, (z0/b)**2-1]) oe2 = Optical_element.initialize_as_surface_conic_from_coefficients(cc) oe2.type = "My hyperbolic mirror" oe2.set_parameters(p=0., q=q1, theta=90.*np.pi/180, alpha=0.) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 1.2")
def test_ideal_lens_with_trace_optical_element(): print( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_ideal_lens_with_trace_optical_element" ) beam = Beam() beam.set_flat_divergence(0.05, 0.005) p = 1. q = 5. lens = Optical_element.ideal_lens(p, q) beam = lens.trace_optical_element(beam) beam.plot_xz() if do_plot: plt.show() assert_almost_equal(np.abs(beam.x).mean(), 0.0, 4) assert_almost_equal(np.abs(beam.z).mean(), 0.0, 4)
def test_spherical_mirror(self): print(">>>>>>>>>>>>>>> test_spherical_mirror") shadow_beam = run_shadow_source() beam1 = Beam() beam1.initialize_from_arrays( shadow_beam.getshonecol(1), shadow_beam.getshonecol(2), shadow_beam.getshonecol(3), shadow_beam.getshonecol(4), shadow_beam.getshonecol(5), shadow_beam.getshonecol(6), shadow_beam.getshonecol(10), ) #beam1 = Beam(5000) #beam1.set_point(0, 0, 0) #beam1.set_flat_divergence(5e-3, 5e-2) p = 2. q = 1. theta = 41 * np.pi / 180 shadow_beam = run_shadow_source() spherical_mirror = Optical_element.initialize_as_surface_conic_sphere_from_focal_distances( p, q, theta) beam1 = spherical_mirror.trace_optical_element(beam1) if do_plot: beam1.plot_xz() beam1.plot_xpzp() plt.title("Spherical mirror with p=2, q=1, theta=41") plt.show() shadow_beam = run_shadow_spherical_mirror(shadow_beam) assert_almost_equal(beam1.x, shadow_beam.getshonecol(1), 8) assert_almost_equal(beam1.y, shadow_beam.getshonecol(2), 8) assert_almost_equal(beam1.z, shadow_beam.getshonecol(3), 8)
def test_ellipsoidal_mirror(self): print(">>>>>>>>>>>>>>> test_ellipsoidal_mirror") #beam1=Beam(5000) #beam1.set_point(0,0,0) #beam1.set_flat_divergence(5e-3,5e-2) shadow_beam = run_shadow_source() beam1 = Beam() beam1.initialize_from_arrays( shadow_beam.getshonecol(1), shadow_beam.getshonecol(2), shadow_beam.getshonecol(3), shadow_beam.getshonecol(4), shadow_beam.getshonecol(5), shadow_beam.getshonecol(6), shadow_beam.getshonecol(10), ) p = 20. q = 10. theta = 50 * np.pi / 180 spherical_mirror = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances( p, q, theta) beam1 = spherical_mirror.trace_optical_element(beam1) if do_plot: beam1.plot_xz() beam1.plot_xpzp() plt.title("Ellipsoidal mirror with p=20, q=10, theta=50") plt.show() shadow_beam = run_shadow_elliptical_mirror(beam1) assert_almost_equal(beam1.vx, shadow_beam.getshonecol(4), 1) assert_almost_equal(beam1.vy, shadow_beam.getshonecol(5), 1) assert_almost_equal(beam1.vz, shadow_beam.getshonecol(6), 1)
def test_ideal_lens_collimated_beam(): print( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_ideal_lens_collimated_beam") beam = Beam() beam.set_circular_spot(20 * 1e-9) beam.set_divergences_collimated() beam.plot_xz() p = 1. q = 5. lens = Optical_element.ideal_lens(p, q, q, q) beam = lens.trace_optical_element(beam) beam.plot_xz() if do_plot: plt.show() assert_almost_equal(np.abs(beam.x).mean(), 0.0, 4) assert_almost_equal(np.abs(beam.z).mean(), 0.0, 4)
def test_rectangular_shape(self): beam = Beam(round(1e5)) plane_mirror = Optical_element.initialize_as_surface_conic_plane( p=10., q=0., theta=0.) beam.set_flat_divergence(0.02, 0.1) xmax = 0.01 xmin = -0.0008 ymax = 1. ymin = -0.29 bound = BoundaryRectangle(xmax=xmax, xmin=xmin, ymax=ymax, ymin=ymin) plane_mirror.set_bound(bound) beam = plane_mirror.trace_optical_element(beam) beam.plot_xz() beam.plot_good_xz() indices = np.where(beam.flag > 0) assert_almost_equal(max(beam.x[indices]) - xmax, 0., 2) assert_almost_equal(-min(beam.x[indices]) + xmin, 0., 2) assert_almost_equal(max(beam.z[indices]) + ymin, 0., 2) assert_almost_equal(-min(beam.z[indices]) - ymax, 0., 2) print(max(beam.x[indices]), min(beam.x[indices]), max(beam.y[indices]), min(beam.y[indices])) if do_plot is True: plt.show() ######### BoundaryCircle has to be implemented in the code of intersection_with_optical_element ####################
import numpy as np import matplotlib.pyplot as plt from numpy.testing import assert_almost_equal from Vector import Vector fx = 0.5 fz = 0.5 beam = Beam(5000) #beam.set_divergences_collimated() #beam.set_rectangular_spot(1.,-1.,1.,-1.) beam.set_flat_divergence(0.05, 0.05) beam.plot_xz() beam.plot_xpzp() lens = Optical_element() lens.set_parameters(p=2., q=5.) beam = lens.trace_ideal_lens(beam) beam.plot_xz() hyp = Optical_element.initialize_my_hyperboloid(p=5 - np.sqrt(2), q=np.sqrt(2), theta=0) beam = hyp.trace_optical_element(beam) beam.plot_xz() plt.show()
beam=beam1.merge(beam2) beam3=Beam() beam3.set_divergences_collimated() beam3.set_point(0.+100,0.,0.+100) beam3.set_rectangular_spot(5.,-5.,10.,-40.) beam=beam.merge(beam3) beamd=beam.duplicate() p = 10. q = 25. theta = 44 * np.pi / 180 alpha = 90 * np.pi / 180 prova = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p,q,theta,alpha,"p") beamd=prova.trace_optical_element(beamd) print(prova.ccc_object.get_coefficients()) t = (100-beam.y)/beam.vy beamd.x = beamd.x + beamd.vx * t beamd.y = beamd.y + beamd.vy * t beamd.z = beamd.z + beamd.vz * t beamd.plot_xz() beam.plot_xz() beam.plot_xpzp()
def test_wolter_1_microscope(): p = 0. beam1 = Beam.initialize_as_person() beam1.set_flat_divergence_with_different_optical_axis(0.005, 0.005) beam1.set_point(p, 0., p) op_ax = Beam (1) op_ax.set_point(p, 0., p) beam = op_ax.merge(beam1) beam.x = beam.x beam.z = beam.z #beam.set_divergences_collimated() beam.plot_xz() distance_of_focalization = 5. hyp = Optical_element.initialize_my_hyperboloid(p=distance_of_focalization, q=0., theta=0., alpha=0., wolter=1.1, z0=0., distance_of_focalization=distance_of_focalization) ah = distance_of_focalization/np.sqrt(2) q = 20. z0 = 0.5*(q - np.sqrt(2)*ah) c = z0 + np.sqrt(2)*ah #b = c + 0.1 #a=np.sqrt(b**2-c**2) b = c*1.5 a = np.sqrt(b**2-c**2) ccc = np.array ([1/a**2, 1/a**2, 1/b**2, 0., 0., 0., 0., 0., -2*z0/b**2, z0**2/b**2-1]) ellips = Optical_element.initialize_as_surface_conic_from_coefficients(ccc) hyp.effect_of_optical_element(beam) beam.plot_yx(0) plt.title("footprint %s" % (hyp.type)) ellips.p = 0. ellips.theta = 90*np.pi/180 ellips.effect_of_optical_element(beam) beam.plot_yx(0) plt.title("footprint %s" % (ellips.type)) t = -beam.y/beam.vy beam.x = beam.x + beam.vx * t beam.y = beam.y + beam.vy * t beam.z = beam.z + beam.vz * t beam.plot_yx(0) beam.plot_xz() print("a of ellips is: %f" %(a)) print("b of ellips is: %f" %(b)) print("c of ellips is: %f" %(c)) print(np.mean(beam.z)) beam.histogram() plt.show()
beta = (90. + 0.) * np.pi / 180 alpha = 87. * np.pi / 180 xmax = 0. xmin = -0.4 ymax = 0.4 ymin = -0.4 zmax = 0.4 # print("zmax = %f" %(zmax)) # zmax = 0.4 zmin = 0. oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances( p=p, q=q, theta=theta, alpha=0., infinity_location="p", focal=q, cylindrical=1) ccc1 = oe1.ccc_object.get_coefficients() print(ccc1) c1 = ccc1[1] c2 = ccc1[2] c4 = ccc1[4] c8 = ccc1[8] ####### rotation of the oe around y ############################################################################# a = np.cos(beta) b = np.sin(beta)
from Shape import BoundaryRectangle import numpy as np import matplotlib.pyplot as plt from numpy.testing import assert_almost_equal beam = Beam(1) #beam.set_flat_divergence(0.000005,0.001) beam.set_point(0., 0., 100.) beam.plot_xz() p = 2000. q = 2 * np.sqrt(2) theta = 0 * np.pi / 180 hyp_mirror = Optical_element.initialize_my_hyperboloid(p, q, theta) beam = hyp_mirror.trace_optical_element(beam) beam.plot_xz() beam.plot_xy() #print (hyp_mirror.ccc_object.get_coefficients()) print(np.mean(beam.z)) plt.show() # #beam=Beam() #beam.set_flat_divergence(0.005,0.0005) #p=20.
p = 5. q = 15. theta = 89.5 * np.pi / 180 beta = (90. + 0.) * np.pi / 180 alpha = 87. * np.pi / 180 xmax = 0. xmin = -0.9 ymax = 0.9 ymin = -0.9 zmax = 0.9 # print("zmax = %f" %(zmax)) # zmax = 0.4 zmin = 0. oe1 = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances( p=p, q=q, theta=theta, alpha=0., cylindrical=1) ccc1 = oe1.ccc_object.get_coefficients() c1 = ccc1[1] c2 = ccc1[2] c4 = ccc1[4] c8 = ccc1[8] ####### rotation of the oe around y ############################################################################# a = np.cos(beta) b = np.sin(beta) ccc2 = np.array([ c2 * b**2, c1, c2 * a**2, -c4 * b, c4 * a, -2 * c1 * a * b, -c8 * b, 0., c8 * a, 0. ])
beam1 = Beam() # beam1.set_point(0,0,0) # beam1.set_flat_divergence(5e-3,5e-2) beam1.initialize_from_arrays( beam_shadow.getshonecol(1), beam_shadow.getshonecol(2), beam_shadow.getshonecol(3), beam_shadow.getshonecol(4), beam_shadow.getshonecol(5), beam_shadow.getshonecol(6), beam_shadow.getshonecol(10), ) #### Data of the plane mirron p = 1. q = 1. theta = 45 alpha = 90 R = 2 * p * q / (q + p) / np.cos(theta) spherical_mirror = Optical_element.initialize_as_spherical_mirror( p, q, theta, alpha, R) beam1 = spherical_mirror.trace_optical_element(beam1) beam1.plot_xz() plt.title("xz diagram on the image plane") beam1.plot_xpzp() plt.title("xpzp diagram on the image plane") plt.show()
def test_paraboloid_mirror(self): print(">>>>>>>>>>>>>>> test_paraboloid_mirror") #beam1=Beam(5000) #beam1.set_point(0,0,0) #beam1.set_flat_divergence(5e-3,5e-2) shadow_beam = run_shadow_source() beam1 = Beam() beam1.initialize_from_arrays( shadow_beam.getshonecol(1), shadow_beam.getshonecol(2), shadow_beam.getshonecol(3), shadow_beam.getshonecol(4), shadow_beam.getshonecol(5), shadow_beam.getshonecol(6), shadow_beam.getshonecol(10), ) p = 10. q = 20. theta = 72 * np.pi / 180 alpha = 0 * np.pi / 180 spherical_mirror = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances( p, q, theta, alpha) beam1 = spherical_mirror.trace_optical_element(beam1) if do_plot: beam1.plot_xz() beam1.plot_xpzp() plt.title("Paraboloid mirror with p=10, q=20, theta=72") print(spherical_mirror.ccc_object.get_coefficients()) plt.show() shadow_beam = run_shadow_parabolic_mirror(shadow_beam) assert_almost_equal(beam1.x, shadow_beam.getshonecol(1), 7) assert_almost_equal(beam1.y, shadow_beam.getshonecol(2), 7) assert_almost_equal(beam1.z, shadow_beam.getshonecol(3), 7) ######## This is problematic ####################################################################################### # #def test_hyperboloid_mirror(): # #beam1=Beam(5000) # #beam1.set_point(0,0,0) # #beam1.set_flat_divergence(5e-3,5e-2) # # shadow_beam=run_shadow_source() # # beam1=Beam(5000) # beam1.initialize_from_arrays( # shadow_beam.getshonecol(1), # shadow_beam.getshonecol(2), # shadow_beam.getshonecol(3), # shadow_beam.getshonecol(4), # shadow_beam.getshonecol(5), # shadow_beam.getshonecol(6), # shadow_beam.getshonecol(10), # 0 # ) # # p=1. # q=2. # theta = 76*np.pi/180 # spherical_mirror=Optical_element.initialize_as_hyperboloid_from_focal_distances(p,q,theta) # beam1=spherical_mirror.trace_surface_conic(beam1) # beam1.plot_xz() # beam1.plot_xpzp() # plt.show() # # shadow_beam=run_shadow_hyperbolic_mirror(shadow_beam) # # ########################################################################################################################