def eff_fun(): v = normalise([random(),random(),10]) rays_in = [Ray([0,0,0],v,wavelen,1)] rays_out = [Ray([0,0,0],v,wavelen,1)] wavevecs_in_mag = [r.wavevector_vac_mag for r in rays_in] wavevecs_in_unit = [r.wavevector_unit for r in rays_in] wavevecs_out_mag = [r.wavevector_vac_mag for r in rays_out] wavevecs_out_unit = [r.wavevector_unit for r in rays_out] return get_efficiency(aod, random(), wavevecs_in_mag, wavevecs_in_unit, wavevecs_out_mag, wavevecs_out_unit, [acoustics], (0,1))
def test_order_sym(): r1 = Ray([0,0,0],[-17./145,0,144./145],wavelen) r2 = Ray([0,0,0],[ 17./145,0,144./145],wavelen) diffract_acousto_optically(aod, [r1], [acoustics], -1) diffract_acousto_optically(aod, [r2], [acoustics], 1) opposite_xcomps = allclose(r1.wavevector_unit[0], -r2.wavevector_unit[0]) assert allclose(r1.energy, r2.energy) and opposite_xcomps
def test_constant_freq_for_zero_chirp(): aol = AolSimple.create_aol_from_drive(num_aods, order, spacing, [10] * 4, [0] * 4, wavelength) wavevec = [0, 3. / 5, 4. / 5] ray1 = Ray([0, 0, 0], wavevec, wavelength) aol.propagate_to_distance_past_aol(ray1, 0) ray2 = Ray([0, 0, 0], wavevec, wavelength) aol.propagate_to_distance_past_aol(ray2, 1e-3) assert allclose(ray1.wavevector_unit, ray2.wavevector_unit, atol=0)
def test_propagating_normal_to_plane(): r1 = Ray(position, wavevector_unit, wavelength, energy) r1.propagate_free_space(10) r2 = Ray(position, wavevector_unit, wavelength, energy) r2.propagate_to_plane([10,10,10], wavevector_unit) assert allclose(r1.position, r2.position)
def test_deflect_right_way(): aol = AolSimple.create_aol_from_drive(num_aods, order, spacing, [1, 0, 0, 0], [0] * 4, wavelength) wavevec = [0, 3. / 5, 4. / 5] ray = Ray([0, 0, 0], wavevec, wavelength) aol.propagate_to_distance_past_aol(ray, 0) assert ray.wavevector_unit[0] < 0
def test_no_chirp_at_tzero(): aol = AolSimple.create_aol_from_drive(num_aods, order, spacing, [0] * 4, array([1e6] * 4), wavelength) aol.set_base_ray_positions(wavelength) wavevec = [0, 0, 1] ray = Ray([0, 0, 0], wavevec, wavelength) aol.propagate_to_distance_past_aol(ray, 0, 10) assert allclose(ray.wavevector_unit, wavevec, atol=0)
def test_ray_passes_through_focus(): location = [0] * 100 for t in arange(100): ray = Ray([r() * 5e-2, r() * 5e-2, 0], [0, 0, 1], op_wavelength) aol.propagate_to_distance_past_aol([ray], 0, focal_length) location[t] = ray.position focus_theory = focus_position + concatenate( (aol_simple.base_ray_positions[3], [aod_spacing.sum()])) assert allclose(mean(location, axis=0), focus_theory, rtol=0, atol=1e-3) \ and all(std(location, axis=0) < 5e-5)
def test_plot(): import matplotlib.pyplot as plt x, y = meshgrid(linspace(-1, 1, 5) * 1e-2, linspace(-1, 1, 5) * 1e-2) list_of_positions = zip(x.ravel(), y.ravel()) rays = [ Ray([xy[0], xy[1], 0], [0, 0, 1], op_wavelength) for xy in list_of_positions ] plt.ion() aol.plot_ray_through_aol(rays, 0, focus_position[2]) plt.close()
def test_angles_on_aods(): x, y = meshgrid(linspace(-1, 1, 5) * 1e-2, linspace(-1, 1, 5) * 1e-2) list_of_positions = zip(x.ravel(), y.ravel()) rays = [ Ray([xy[0], xy[1], 0], [0, 0, 1], op_wavelength) for xy in list_of_positions ] paths, _ = aol.propagate_to_distance_past_aol(rays, 3e-6) for m in range(8): dot_prods = dot(paths[:, m, :], aol.aods[m / 2].normal) assert allclose(dot_prods, dot_prods[0]) assert allclose([p[2] for p in paths[:, 8, :]], aod_spacing.sum())
def get_ray_bundle(op_wavelength, width=15e-3): """Create a grid of rays. Useful for passing into an Aol instance.""" r_array = width / 4 * linspace(-1, 1, 5) angle_array = linspace(0, pi, 5)[:-1] r_mesh, angle_mesh = meshgrid(r_array, angle_array) rays = [] for r, ang in zip(r_mesh.ravel(), angle_mesh.ravel()): x = r * cos(ang) y = r * sin(ang) rays.append(Ray([x, y, 0], [0, 0, 1], op_wavelength)) return rays
def test_plot(): import matplotlib.pyplot as plt aol = AolSimple.create_aol_from_drive(num_aods, order, spacing, array([1] * 4) * 1e6, [1] * 4, wavelength) wavevec = [0, 3. / 5, 4. / 5] ray = Ray([0, 0, 0], wavevec, wavelength) plt.ion() aol.plot_ray_through_aol(ray, 1, aol.aod_spacing.sum()) plt.close() assert allclose(ray.position, [0, 0, 0], atol=0) and allclose( ray.wavevector_unit, wavevec, atol=0)
def test_ray_scans_correctly(): t_step = 1e-6 num_rays = 100 location = [0] * num_rays for t in arange(num_rays): ray = Ray([r() * 5e-2, r() * 5e-2, 0], [0, 0, 1], op_wavelength) aol.propagate_to_distance_past_aol([ray], t * t_step, focal_length) location[t] = ray.position focus_theory = focus_position + concatenate( (aol_simple.base_ray_positions[3], [aod_spacing.sum()])) + outer( arange(num_rays) * t_step, focus_velocity) assert allclose(location, focus_theory, rtol=0, atol=2e-3)
def func(mhz, op_wavelength_vac): deg_range = np.linspace(0.9, 3, 70) rad_range = deg_range * pi / 180 rays = [ Ray([0, 0, 0], [np.sin(ang), 0, np.cos(ang)], op_wavelength_vac) for ang in rad_range ] acoustics = Acoustics(mhz * 1e6, ac_power * acc_eff) aod.propagate_ray(rays, [acoustics] * len(rays), order) idx = np.argmax([r.energy for r in rays]) r = rays[idx] return (r.energy, r.resc)
def test_propagating_angle_to_plane(): r = Ray(position, [3./5,4./5,0], wavelength, energy) r.propagate_to_plane([12,0,0], [1,0,0]) assert allclose(r.position, position + array([12,16,0]))
def test_efficiency_low_at_angle(): ray = Ray([0, 0, 0], [3. / 5, 0, 4. / 5], op_wavelength) aol.propagate_to_distance_past_aol([ray], 0, focal_length) assert ray.energy < 1e-9
def test_setting_wavevector_property(): r = Ray(position, [3./5,4./5,0], wavelength, energy) r.wavevector_vac = [144,0,17] mag_correct = allclose(r.wavevector_vac_mag, 145) dir_correct = allclose(r.wavevector_unit, [144./145, 0, 17./145]) assert mag_correct and dir_correct
def test_align_to_plane(): r = Ray([1,0,0], [0,0,1], wavelength, energy) r.propagate_from_plane_to_plane(0, array([0,0,1]), normalise([-1,0,1])) assert allclose(r.position, [1,0,1])
def test_propagate_from_plane_to_plane_reverse(): r = Ray([1,0,0], [0,0,1], wavelength, energy) r.propagate_from_plane_to_plane( 10, normalise([ 1,2,1]), normalise([-1,3,1])) r.propagate_from_plane_to_plane(-10, normalise([-1,3,1]), normalise([ 1,2,1])) assert allclose(r.position, [1,0,0])
def test_setting_invalid_mode(): with pytest.raises(ValueError): ray = Ray([0,0,0,], [0,0,1], wavelen) diffract_acousto_optically(aod, [ray], [acoustics], 2)
def test_wavevectors(): r = Ray(position, wavevector_unit, wavelength, energy) assert allclose(r.wavevector_unit * r.wavevector_vac_mag, r.wavevector_vac)
def get_single_ray(op_wavelength, width=15e-3): return [Ray([0, 0, 0], [0, 0, 1], op_wavelength)]
def test_setting_non_unit_vector(): with pytest.raises(ValueError): Ray(position, [1,0,0.1], wavelength, energy)