コード例 #1
0
def test_propagate_plane_to_curved_flat_inclined():
    lamb = 860e-9
    theta = np.pi / 6
    waist = 100e-6
    num_points = 64
    k = 2 * np.pi / lamb
    z_R = np.pi * waist**2 / lamb
    r_support = waist * 12
    z0 = -z_R * 0.5
    z1m = z_R * 0.5

    # When the central k vector is in the xz or yz planes then in local_xy mode, the kz expansion is exact to second
    # order. Otherwise it is only approximate to second order since it ignores the crossed second derivatives.
    for phi, atol_frac in ((0, 2e-3), (np.pi / 2, 2e-3), (np.pi / 4, 1e-1)):
        vector = np.asarray(mathx.polar_to_cart(1, theta, phi))
        r0_centers = vector[:2] / vector[2] * z0
        qs_center = vector[:2] * k
        x0, y0 = asbp.calc_xy(r_support, num_points, r0_centers)
        matrix = otk.h4t.make_frame(vector, (0, 1, 0))
        x0l, y0l, z0l, _ = matseq.mult_mat_vec(np.linalg.inv(matrix),
                                               (x0, y0, z0, 1))
        Er0 = asbp.calc_gaussian(k, x0l, y0l, waist, z0l)
        r1_centers = vector[:2] / vector[2] * z1m
        x1, y1 = asbp.calc_xy(r_support, num_points, r1_centers)
        z1 = z1m + 0 * (x1 - r1_centers[0]) + 0 * (y1 - r1_centers[1])
        x1l, y1l, z1l, _ = matseq.mult_mat_vec(np.linalg.inv(matrix),
                                               (x1, y1, z1, 1))
        Er1_theory, gradxyEr1_theory = asbp.calc_gaussian(k,
                                                          x1l,
                                                          y1l,
                                                          waist,
                                                          z1l,
                                                          gradr=True)
        Er1, gradxyEr1 = asbp.propagate_plane_to_curved_flat(
            k, r_support, Er0, z1 - z0, qs_center, 'local_xy')
        assert mathx.allclose(Er1, Er1_theory, atol_frac)
        # We don't expect the derivatives to agree because they are along the inclined surface.

    if 0:
        ##
        plot0 = asbp.plot_r_q_polar(r_support, Er0, r0_centers, qs_center)
        plot0[0].setWindowTitle('Er0')
        plot1 = asbp.plot_r_q_polar(r_support, Er1, r1_centers, qs_center)
        plot1[0].setWindowTitle('Er1')
        plot1_theory = asbp.plot_r_q_polar(r_support, Er1_theory, r1_centers,
                                           qs_center)
        plot1_theory[0].setWindowTitle('Er1_theory')
        plot_diff = asbp.plot_r_q_polar(r_support, Er1 - Er1_theory,
                                        r1_centers, qs_center)
        plot_diff[0].setWindowTitle('diff')

        plot_diff_abs = asbp.plot_r_q_polar(r_support,
                                            abs(Er1) - abs(Er1_theory),
                                            r1_centers, qs_center)
        plot_diff_abs[0].setWindowTitle('diff_abs')
コード例 #2
0
def test_curved_interface_collimate_offset():
    lamb = 587.6e-9
    waist0 = 30e-6
    num_points = 2**7
    k = 2 * np.pi / lamb
    r0_support = (np.pi * num_points)**0.5 * waist0
    # Define x lateral offset of beam.
    r_offsets = np.asarray((4e-3, -2e-3))
    # We center the numerical window on the beam.
    rs_center = r_offsets
    x0, y0 = asbp.calc_xy(r0_support, num_points, rs_center)
    # Create input beam.
    Er0 = asbp.calc_gaussian(k, x0, y0, waist0, r0s=r_offsets)
    # We will propagate it a distance f.
    f = 100e-3
    z_R = np.pi * waist0**2 / lamb
    m = (1 + (f / z_R)**2)**0.5
    # We collimate it with a spherical interface.
    n = 1.5
    roc = f * (n - 1)
    # At the interface,  support is expanded by the curved wavefront propagation.
    r1_support = m * r0_support
    x1, y1 = asbp.calc_xy(r1_support, num_points, rs_center)
    # Calculate and plot interface sag.
    sag = functions.calc_sphere_sag_xy(roc, x1, y1)
    xu, yu, sagu = asbp.unroll_r(r1_support, sag)
    # Propagate to curved surface.
    Er1, _ = asbp.propagate_plane_to_curved_spherical(k, r0_support, Er0,
                                                      f + sag, m, rs_center)
    xu, yu, Er1u = asbp.unroll_r(r1_support, Er1)
    #
    # x2, y2=asbp.calc_xy(r1_support, num_points)
    qs_centers2 = -r_offsets / f * k
    Er2, propagator = asbp.invert_plane_to_curved_spherical(
        k * n,
        r1_support,
        Er1,
        -f * n + sag,
        1, (0, 0),
        qs_centers2,
        max_iterations=10)  # -x_offset/f*k
    xu, yu, Er2u = asbp.unroll_r(r1_support, Er2)
    tilt_factor = mathx.expj(-(xu * r_offsets[0] + yu * r_offsets[1]) / f * k)
    ##
    waist2 = f * lamb / (np.pi * waist0)
    Er2_theory = asbp.calc_gaussian(k, x1, y1, waist2) * tilt_factor
    Er2_theory *= mathx.expj(np.angle(Er2[0, 0] / Er2_theory[0, 0]))
    assert mathx.allclose(abs(Er2), abs(Er2_theory), 2e-2)
    if 0:
        ##
        Er2_fig = asbp.plot_r_q_polar(r1_support, Er2, qs_center=qs_centers2)
        Er2_theory_fig = asbp.plot_r_q_polar(r1_support,
                                             Er2_theory,
                                             qs_center=qs_centers2)
コード例 #3
0
def test_propagate_plane_to_plane_flat_inclined():
    """Propagate an inclined Gaussian beam between two planes."""
    lamb = 860e-9
    theta = np.pi / 6
    phi = np.pi / 4
    waist = 100e-6
    num_points = 64
    k = 2 * np.pi / lamb
    z_R = np.pi * waist**2 / lamb
    r_support = waist * 12
    vector = np.asarray(mathx.polar_to_cart(1, theta, phi))
    z0 = -z_R * 0.5
    z1 = z_R * 0.5
    r0_centers = vector[:2] / vector[2] * z0
    qs_center = vector[:2] * k
    x0, y0 = asbp.calc_xy(r_support, num_points, r0_centers)
    matrix = otk.h4t.make_frame(vector, (0, 1, 0))
    x0l, y0l, z0l, _ = matseq.mult_mat_vec(np.linalg.inv(matrix),
                                           (x0, y0, z0, 1))
    Er0 = asbp.calc_gaussian(k, x0l, y0l, waist, z0l)
    r1_centers = vector[:2] / vector[2] * z1
    x1, y1 = asbp.calc_xy(r_support, num_points, r1_centers)
    x1l, y1l, z1l, _ = matseq.mult_mat_vec(np.linalg.inv(matrix),
                                           (x1, y1, z1, 1))
    Er1_theory = asbp.calc_gaussian(k, x1l, y1l, waist, z1l)
    for kz_mode, atol_frac in (('local_xy', 1e-1), ('local', 1e-2), ('exact',
                                                                     1e-5)):
        ##
        Er1 = asbp.propagate_plane_to_plane_flat(k, r_support, Er0, z1 - z0,
                                                 qs_center, kz_mode)
        assert mathx.allclose(Er1, Er1_theory, atol_frac)
    if 0:
        ##
        plot0 = asbp.plot_r_q_polar(r_support, Er0, r0_centers, qs_center)
        plot0[0].setWindowTitle('Er0')
        plot1 = asbp.plot_r_q_polar(r_support, Er1, r1_centers, qs_center)
        plot1[0].setWindowTitle('Er1')
        plot1_theory = asbp.plot_r_q_polar(r_support, Er1_theory, r1_centers,
                                           qs_center)
        plot1_theory[0].setWindowTitle('Er1_theory')
        plot_diff = asbp.plot_r_q_polar(r_support, Er1 - Er1_theory,
                                        r1_centers, qs_center)
        plot_diff[0].setWindowTitle('diff')

        plot_diff_abs = asbp.plot_r_q_polar(r_support,
                                            abs(Er1) - abs(Er1_theory),
                                            r1_centers, qs_center)
        plot_diff_abs[0].setWindowTitle('diff_abs')
コード例 #4
0
def test_propagate_plane_to_curved_spherical_inclined():
    lamb = 860e-9
    theta = np.pi / 6
    waist = 100e-6
    num_points = 64
    k = 2 * np.pi / lamb
    z_R = np.pi * waist**2 / lamb
    r0_support = waist * 12
    z0 = -z_R * 0.5
    z1m = z_R * 2
    m = 2
    for phi, apod_frac in ((0, 1e-2), (np.pi / 2, 1e-2), (np.pi / 4, 2e-1)):
        vector = np.asarray(mathx.polar_to_cart(1, theta, phi))
        r0_centers = vector[:2] / vector[2] * z0
        qs_center = vector[:2] * k
        x0, y0 = asbp.calc_xy(r0_support, num_points, r0_centers)
        matrix = otk.h4t.make_frame(vector, (0, 1, 0))
        x0l, y0l, z0l, _ = matseq.mult_mat_vec(np.linalg.inv(matrix),
                                               (x0, y0, z0, 1))
        Er0 = asbp.calc_gaussian(k, x0l, y0l, waist, z0l)
        r1_centers = vector[:2] / vector[2] * z1m
        r1_support = r0_support * m
        x1, y1 = asbp.calc_xy(r1_support, num_points, r1_centers)
        z1 = z1m + 1e0 * (x1 - r1_centers[0]) + 1e2 * (y1 - r1_centers[1])**2
        x1l, y1l, z1l, _ = matseq.mult_mat_vec(np.linalg.inv(matrix),
                                               (x1, y1, z1, 1))
        Er1_theory = asbp.calc_gaussian(k, x1l, y1l, waist, z1l)
        Er1, gradxyEr1 = asbp.propagate_plane_to_curved_spherical(
            k, r0_support, Er0, z1 - z0, m, r0_centers, qs_center, r1_centers,
            'local_xy')
        assert mathx.allclose(Er1, Er1_theory, apod_frac)
    if 0:
        ##
        plot0 = asbp.plot_r_q_polar(r0_support, Er0, r0_centers, qs_center)
        plot0[0].setWindowTitle('Er0')
        plot1 = asbp.plot_r_q_polar(r1_support, Er1, r1_centers, qs_center)
        plot1[0].setWindowTitle('Er1')
        plot1_theory = asbp.plot_r_q_polar(r1_support, Er1_theory, r1_centers,
                                           qs_center)
        plot1_theory[0].setWindowTitle('Er1_theory')
        plot_diff = asbp.plot_r_q_polar(r1_support, Er1 - Er1_theory,
                                        r1_centers, qs_center)
        plot_diff[0].setWindowTitle('diff')

        plot_diff_abs = asbp.plot_r_q_polar(r1_support,
                                            abs(Er1) - abs(Er1_theory),
                                            r1_centers, qs_center)
        plot_diff_abs[0].setWindowTitle('diff_abs')
コード例 #5
0
def test_invert_plane_to_curved_spherical_arbitrary():
    # Number of points to invert to.
    num_pointss1 = 48, 64
    # Starting number of points.
    num_pointss2 = 52, 68
    roc_x2 = 50e-3
    roc_y2 = 75e-3
    k = 2 * np.pi / 860e-9
    waist0s = np.asarray((20e-6, 20e-6))
    r0_supports = waist0s * 8
    z_Rs = waist0s**2 * k / 2
    trials = (
        (0, (0, 0), (0, 0), (0, 0), (0, 0), 5e-6, (0, 0), 1),  # 0
        (0, (0, 0), (0, 0), (0, 0), (0, 0), 50e-3, (0, 0), 1),  # 1
        (20e-3, (0, 0), (0, 0), (0, 0), (0, 0), 50e-3, (0, 0), 1),  # 2
        (50e-3, (0, 0), (0, 0), (0, 0), (0, 0), 50e-3, (0, 0), 1),  # 3
        (0, (30e-6, -10e-6), (30e3, 100e3), (30e-6, -15e-6), (20e3, 80e3), 0,
         (30e-6, -10e-6), 1),  # 4
        (20e-3, (30e-6, -10e-6), (30e3, 25e3), (0, 0), (20e3, 35e3), 20e-3,
         (30e-6, -10e-6), 1),  # 5
        ((0, (0, 0), (0, 0), (0, 0), (0, 0), 0e-6, (0, 0), 1)))  # 6

    invert_kwargs = dict(max_iterations=50, tol=1e-11)
    for trial_num, trial in tuple(enumerate(trials)):
        z1, r_offsets, q_offsets, r1_centers, qs_center, z2_mean, r2_centers, r2_supports_factor = trial

        m1s = (1 + (z1 / z_Rs)**2)**0.5
        r1_supports = r0_supports * m1s
        x1, y1 = asbp.calc_xy(r1_supports, num_pointss1, r1_centers)
        Er1_theory = asbp.calc_gaussian(k, x1, y1, waist0s, z1, r_offsets,
                                        q_offsets)

        m2s_mean = (1 + (z2_mean / z_Rs)**2)**0.5
        r2_supports = r0_supports * m2s_mean * r2_supports_factor

        x2, y2 = asbp.calc_xy(r2_supports, num_pointss2, r2_centers)
        z2 = x2**2 / (2 * roc_x2) + y2**2 / (2 * roc_y2) + z2_mean
        Er2 = asbp.calc_gaussian(k, x2, y2, waist0s, z2, r_offsets, q_offsets)

        roc12_x = bvar.calc_sziklas_siegman_roc_from_waist(
            z_Rs[0], -z1, z2 - z1)
        roc12_y = bvar.calc_sziklas_siegman_roc_from_waist(
            z_Rs[1], -z1, z2 - z1)

        # calc_gaussian uses paraxial propagation, but the angles are small enough so local_xy agrees too. For
        # thoroughness, test both.
        for kz_mode in ('local_xy', 'paraxial'):
            Er1, propagator = asbp.invert_plane_to_curved_spherical_arbitrary(
                k, r1_supports, num_pointss1, Er2, z2 - z1, x2, y2, roc12_x,
                roc12_y, r1_centers, qs_center, r2_centers, kz_mode,
                invert_kwargs)
            assert Er1.shape == num_pointss1
            Er2p = propagator.apply(Er1)
            print(
                (mathx.sum_abs_sqd(Er2 - Er2p) / mathx.sum_abs_sqd(Er2))**0.5)
            assert mathx.allclose(Er2, Er2p, 1e-4), (kz_mode, trial_num)
            assert mathx.allclose(Er1, Er1_theory, 1e-4)

            if trial == trials[-1]:
                roc21_x = bvar.calc_sziklas_siegman_roc_from_waist(
                    z_Rs[0], -z2, z1 - z2)
                roc21_y = bvar.calc_sziklas_siegman_roc_from_waist(
                    z_Rs[1], -z2, z1 - z2)
                Er1 = asbp.propagate_arbitrary_curved_to_plane_spherical(
                    k, x2, y2, Er2, roc21_x, roc21_y, z1 - z2, r1_supports,
                    num_pointss1, r2_centers, qs_center, r1_centers, kz_mode,
                    invert_kwargs)

                assert mathx.allclose(Er2, propagator.apply(Er1),
                                      1e-4), trial_num
                assert mathx.allclose(Er1, Er1_theory, 1e-4)
    if 0:
        ##
        Er1_fig = asbp.plot_r_q_polar(r1_supports, Er1, r1_centers, qs_center)
        Er1_fig[0].setWindowTitle('Er1')
        Er1_theory_fig = asbp.plot_r_q_polar(r1_supports, Er1_theory,
                                             r1_centers, qs_center)
        Er1_theory_fig[0].setWindowTitle('Er1_theory')
        Er2_fig = asbp.plot_r_q_polar(r2_supports, Er2, r2_centers, qs_center)
        Er2_fig[0].setWindowTitle('Er2')
        Er1_diff_fig = asbp.plot_r_q_polar(r1_supports, Er1 - Er1_theory,
                                           r1_centers, qs_center)
        Er1_diff_fig[0].setWindowTitle('Er1 diff')
        # Er2p =\
        # asbp.propagate_plane_to_curved_spherical_arbitrary(k, r1_supports, Er1_theory, z2 - z1, x2, y2, m12x, m12y)[0]
        # Er2p_fig = asbp.plot_r_q_polar(r2_supports, Er2p, r2_centers, qs_center)
        # Er2p_fig[0].setWindowTitle('Er2p')
        Er2_diff_fig = asbp.plot_r_q_polar(r1_supports, Er2p - Er2, r1_centers,
                                           qs_center)
        Er2_diff_fig[0].setWindowTitle('Er2 diff')
        ##
        absEr1_diff_fig = asbp.plot_r_q_polar(r1_supports,
                                              abs(Er1) - abs(Er1_theory),
                                              r1_centers, qs_center)
        absEr1_diff_fig[0].setWindowTitle('abs Er1 diff')