def test_focus_scans_correctly(): focus_position = array([0.1, 0.2, 3], dtype=dtype(float)) focus_velocity = array([0, 0, 0], dtype=dtype(float)) time = 1e-4 ray1 = RayParaxial([0, 0, 0], [0, 0, 1], op_wavelength) aol1 = AolSimple.create_aol(4, order, op_wavelength, ac_velocity, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity) aol1.propagate_to_distance_past_aol(ray1, time, focus_position[2]) ray2 = RayParaxial([0, 0, 0], [0, 0, 1], op_wavelength) aol2 = AolSimple.create_aol(4, -order, op_wavelength, ac_velocity, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity) # opposite order! aol2.propagate_to_distance_past_aol(ray2, time, focus_position[2]) expected_position1 = focus_position + offset + time * focus_velocity expected_position2 = focus_position + [ -base_angle * aod_spacing[0:2].sum(), -base_angle * aod_spacing[1:3].sum(), aod_spacing.sum() ] + time * focus_velocity assert allclose(ray1.position, expected_position1, atol=tol, rtol=0) and allclose( ray2.position, expected_position2, atol=tol, rtol=0)
def test_find_base_ray_positions(): aol_const = AolSimple.create_aol_from_drive(num_aods, order, spacing, [1e6] * 4, [0] * 4, wavelength) aol_chirp = AolSimple.create_aol_from_drive(num_aods, order, spacing, [1e6] * 4, [1e6] * 4, wavelength) assert allclose(aol_const.base_ray_positions, aol_chirp.base_ray_positions, atol=0) and not aol_chirp.acoustic_drives[0].linear == 0
def test_no_chirp_at_tzero(): aol = AolSimple.create_aol_from_drive(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_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_constant_freq_for_zero_chirp(): aol = AolSimple.create_aol_from_drive(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_focus_scans_correctly(): focus_position = array([0.1,0.2,3], dtype=dtype(float)) focus_velocity = array([0,0,0], dtype=dtype(float)) time = 1e-4 ray1 = RayParaxial([0,0,0], [0,0,1], op_wavelength) aol1 = AolSimple.create_aol(order, op_wavelength, ac_velocity, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity) aol1.propagate_to_distance_past_aol(ray1, time, focus_position[2]) ray2 = RayParaxial([0,0,0], [0,0,1], op_wavelength) aol2 = AolSimple.create_aol(-order, op_wavelength, ac_velocity, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity)# opposite order! aol2.propagate_to_distance_past_aol(ray2, time, focus_position[2]) expected_position1 = focus_position + offset + time * focus_velocity expected_position2 = focus_position + [-base_angle*aod_spacing[0:2].sum(),-base_angle*aod_spacing[1:3].sum(),aod_spacing.sum()] + time * focus_velocity assert allclose(ray1.position, expected_position1, atol=tol, rtol=0) and allclose(ray2.position, expected_position2, atol=tol, rtol=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_plot(): import matplotlib.pyplot as plt aol = AolSimple.create_aol_from_drive(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_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_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_passes_through_focus(): focus_position = array([1e-3,2e-3,3], dtype=dtype(float)) focus_velocity = array([0,0,0], dtype=dtype(float)) aol = AolSimple.create_aol(order, op_wavelength, ac_velocity, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity) ray1 = RayParaxial([0,0,0], [0,0,1], op_wavelength) aol.propagate_to_distance_past_aol(ray1, 0, focus_position[2]) # t = 0 ray2 = RayParaxial([0,0,0], [0,0,1], op_wavelength) aol.propagate_to_distance_past_aol(ray2, 1e-6, focus_position[2]) # t != 0 ray3 = RayParaxial([1e-2,0,0], [0,0,1], op_wavelength) # position not origin aol.propagate_to_distance_past_aol(ray3, 0, focus_position[2]) # t = 0 expected_position = focus_position + offset assert allclose(ray1.position, expected_position, atol=tol, rtol=0) and allclose(ray2.position, expected_position, atol=tol, rtol=0) and allclose(ray3.position, expected_position, atol=tol, rtol=0)
def test_ray_passes_through_base_point(): focus_position = array([0, 0, 10], dtype=dtype(float)) focus_velocity = array([0, 0, 0], dtype=dtype(float)) aol = AolSimple.create_aol(4, order, op_wavelength, ac_velocity, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity) ray1 = RayParaxial([0, 0, 0], [0, 0, 1], op_wavelength) aol.propagate_to_distance_past_aol(ray1, 0, focus_position[2]) # t = 0 ray2 = RayParaxial([0, 0, 0], [0, 0, 1], op_wavelength) aol.propagate_to_distance_past_aol(ray2, 1e-3, focus_position[2]) # t != 0 ray3 = RayParaxial([1, 0, 0], [0, 0, 1], op_wavelength) # position not origin aol.propagate_to_distance_past_aol(ray3, 0, focus_position[2]) # t = 0 expected_position = focus_position + offset assert allclose(ray1.position, expected_position, atol=tol, rtol=0) and \ allclose(ray2.position, expected_position, atol=tol, rtol=0) and \ allclose(ray3.position, expected_position, atol=tol, rtol=0)
def test_non_unit_direction(): with pytest.raises(ValueError): AolSimple(num_aods, 1, [1, 1, 1], [0] * 4, [0] * 4, aod_directions=[[1, 0, 0.1], [0, 1, 0], [-1, 0, 0], [0, -1, 0]])
focus_velocity = [1, 1, 0] aod_spacing = array([5e-2] * 3) aods = [0] * 4 aods[0] = Aod(normalise([0, 1, 40]), [1, 0, 0], 25e-3, 3.2e-3, crystal_thickness) aods[1] = Aod(normalise([1, -1, 40]), [0, 1, 0], 25e-3, 3.2e-3, crystal_thickness) aods[2] = Aod([0, 0, 1], [-1, 0, 0], 25e-3, 1.6e-3, crystal_thickness) aods[3] = Aod([0, 0, 1], [0, -1, 0], 25e-3, 1.6e-3, crystal_thickness) aol = AolFull.create_aol(aods, aod_spacing, order, op_wavelength, base_freq, pair_deflection_ratio, focus_position, focus_velocity) aol_simple = AolSimple.create_aol(len(aods), order, op_wavelength, teo2_ac_vel, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity, [crystal_thickness] * 4) def test_aol_drives_same(): const_full = [a.const for a in aol.acoustic_drives] const_simple = [a.const for a in aol_simple.acoustic_drives] linear_full = [a.linear for a in aol.acoustic_drives] linear_simple = [a.linear for a in aol_simple.acoustic_drives] quad_full = [a.quad for a in aol.acoustic_drives] quad_simple = [a.quad for a in aol_simple.acoustic_drives] assert allclose(const_full, const_simple) and allclose( linear_full, linear_simple) and allclose(quad_full, quad_simple) def test_plot():
def test_deflect_right_way(): aol = AolSimple.create_aol_from_drive(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_find_base_ray_positions(): aol_const = AolSimple.create_aol_from_drive(order, spacing, [1e6]*4, [0]*4, wavelength) aol_chirp = AolSimple.create_aol_from_drive(order, spacing, [1e6]*4, [1e6]*4, wavelength) assert allclose(aol_const.base_ray_positions, aol_chirp.base_ray_positions, atol=0) and not aol_chirp.acoustic_drives[0].linear == 0
crystal_thickness = 8e-3 focal_length = 1 focus_position = array([-.01,-.01,focal_length]) focus_velocity = [1,1,0] aod_spacing = array([5e-2] * 3) aods = [0]*4 aods[0] = Aod(normalise([0,1,40]), [ 1, 0,0], 25e-3, 3.2e-3, crystal_thickness) aods[1] = Aod(normalise([1,-1,40]), [ 0, 1,0], 25e-3, 3.2e-3, crystal_thickness) aods[2] = Aod([0,0,1], [-1, 0,0], 25e-3, 1.6e-3, crystal_thickness) aods[3] = Aod([0,0,1], [ 0,-1,0], 25e-3, 1.6e-3, crystal_thickness) aol = AolFull.create_aol(aods, aod_spacing, order, op_wavelength, base_freq, pair_deflection_ratio, focus_position, focus_velocity) aol_simple = AolSimple.create_aol(order, op_wavelength, teo2_ac_vel, aod_spacing, base_freq, pair_deflection_ratio, focus_position, focus_velocity, [crystal_thickness]*4) def test_aol_drives_same(): const_full = [a.const for a in aol.acoustic_drives] const_simple = [a.const for a in aol_simple.acoustic_drives] linear_full = [a.linear for a in aol.acoustic_drives] linear_simple = [a.linear for a in aol_simple.acoustic_drives] quad_full = [a.quad for a in aol.acoustic_drives] quad_simple = [a.quad for a in aol_simple.acoustic_drives] assert allclose(const_full, const_simple) and allclose(linear_full, linear_simple) and allclose(quad_full, quad_simple) 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]