def test_group_elements(): path = OpticalPath(angle=[-5, 5], n=31) raypy2d.elements.plot_blockers = False path.append(Aperture(0.1, [8.0, 0], blocker_diameter=20)) path.append(ParabolicMirror(32, 12., [40., 0], theta=175, flipped=True)) path.append(DiffractionGrating(1.6, 10., interference=-1, theta=-10), distance=20., theta=170.) path.append(Mirror(15., theta=205.8, flipped=False), distance=12, theta=129) path.append(Aperture(13.75, flipped=True, blocker_diameter=15), Lens(22.0, 13.75, [0.01, 0], flipped=False), Lens(6.2, 13.75, [0.02, 0], flipped=False), Mirror(3.68, [3.80, 0], flipped=True), distance=30.) ax = plt.gca() ax.axis('equal') path.plot(ax) plt.show()
def test_path_with_object(): obj = Object(2.0, [-1., 0.], angle=[-10, 10], n=31) path = OpticalPath(obj) raypy2d.elements.plot_blockers = False path.append(Aperture(0.1, [8.0, 0], blocker_diameter=20)) path.append(ParabolicMirror(32, 12., [40., 0], theta=175, flipped=True)) path.append(DiffractionGrating(1.6, 10., interference=-1, theta=-10), distance=20., theta=170.) path.append(Mirror(15., theta=205.8, flipped=False), distance=12, theta=129) path.append(Aperture(13.75, flipped=True, blocker_diameter=15), Lens(22.0, 13.75, [0.01, 0], flipped=False), Lens(6.2, 13.75, [0.02, 0], flipped=False), Sensor(3.68, [3.80, 0], flipped=True), distance=30.) ax = plt.gca() ax.axis('equal') path.plot(ax) cross, _, _ = path.rays.traced_rays().ray_crossings() cross = cross.reshape((-1, 2)) cross = cross[~np.any(np.isnan(cross), axis=1)] ax.scatter(cross[:, 0], cross[:, 1]) plt.show()
def test_diffraction_grating(): path = OpticalPath() path.append(Lens(3, 16., [5., 1.], theta=30.)) path.append(Lens(10, 16., [8., 3.], theta=15.)) path.append(DiffractionGrating(1.6, 16., [10, 3.], theta=15.)) path.propagate(25) ax = plt.gca() ax.axis('equal') path.plot(ax) plt.show()
def test_imaging_path_with_object(): obj = Object(2.0, theta=15.) path = OpticalPath(obj) path.append(Lens(3, 16., [5., 1.], theta=30.)) path.append(Lens(10, 16., [8., 3.], theta=15.)) path.propagate(20) ax = plt.gca() ax.axis('equal') path.plot(ax) plt.show()
def test_imaging_path(): path = OpticalPath() path.append(Lens(5, 16., [5., 1.], theta=30.)) path.append(Aperture(4, [7., 2.])) path.append(ParabolicMirror(5., 8., [15., 3.], theta=155)) path.append(ParabolicMirror(5., 8., [9., 15.], theta=-45)) path.propagate(15) ax = plt.gca() ax.axis('equal') path.plot(ax) plt.show()
def test_imaging_path_with_diffraction_grating(): raypy2d.elements.plot_blockers = False obj = Object(2.0, n=5) path = OpticalPath(obj) path.append(Lens(3, 16., [3., 0])) path.append(DiffractionGrating(1.6, 16., [8, 0.])) # path.append(Lens(5, 16., [10.,0])) path.append(ParabolicMirror(16., 35., [20, 5.5], theta=160., flipped=True)) # path.append(Lens(3, 16., [15, 1.], theta=10.)) path.propagate(-5) ax = plt.gca() ax.axis('equal') path.plot(ax) plt.show()
def test_sensor_image(): path = OpticalPath(Object(2.0, [-8., 0.], angle=-10, n=181)) # raypy2d.elements.plot_blockers = False # path.append(Aperture(1, [6.0, 0], blocker_diameter=20)) path.append(Aperture(0.2, [0.0, 0], blocker_diameter=20)) path.append(ParabolicMirror(40, 20., [32., 0], theta=154.5, flipped=True)) # path.append(Mirror(20., [50., 0], theta=165, flipped=True)) # path.append(DiffractionGrating(1.6, 20., interference=-1, theta=-10), distance=15., theta=130.) path.append(DiffractionGrating(1.0, 20., interference=-1, theta=0), distance=15., theta=126) # path.append(Aperture(13.75, blocker_diameter=15), distance=10., theta=109.5) alpha = -0 vec = np.array( [np.cos(alpha / 180. * np.pi), np.sin(alpha / 180. * np.pi)]) sin_alpha = np.cos(alpha / 180. * np.pi) path.append(Aperture(13.75, theta=alpha, blocker_diameter=28), Lens(12.0, 13.75, vec * 20, theta=alpha, flipped=False), Sensor(5.58, 29.68 * vec, theta=alpha, flipped=True), distance=13., theta=90) # path.propagate(-10) ax = plt.gca() ax.axis('equal') path.plot(ax) # cross = path.rays.traced_rays().ray_crossings() # cross = cross.reshape((-1, 2)) # cross = cross[~np.any(np.isnan(cross), axis=1)] # ax.scatter(cross[:, 0], cross[:, 1]) #plot_sensor_img(path, axs[0], only_wavelength=True) plt.show()
def test_diffraction_prism(): """ test the diffraction of rays on a prism """ path = OpticalPath(Object(1, theta=0)) theta_diff = 0 m_diff = 1 path.append(DiffractionPrism(15, origin=[10., 0], theta=theta_diff)) theta_532 = np.arcsin(np.sin(-theta_diff / 180. * np.pi) - m_diff * 532. / 1000. / 1.0) * 180 / np.pi \ + theta_diff assert np.isclose(theta_532, -31.8337) path.append(Aperture(20.), distance=20., theta=theta_532) ax = plt.gca() ax.axis('equal') path.plot(ax) plt.show()
def test_diffraction_path(): theta_0 = 0 # fiber NA = 0.22 alpha = np.arcsin(NA) / np.pi * 180. path = OpticalPath( Object(0.3, [0., 0.], angle=[alpha + theta_0, -alpha + theta_0], n=21)) path.append(DiffractionPrism(25, glass=Glasses.SF11, theta=-40, flipped=True), distance=5., theta=theta_0) path.append(Aperture(20, flipped=True), distance=100, theta=-20) ax = plt.gca() ax.axis('equal') path.plot(ax) plt.show()