def cavity(E):
        E_p = propagator1.dot(E)
        E_p = lens(E_p, f)
        E_p *= aberration
        E_p = propagator2.dot(E_p)
        E_p = lens(E_p, f)
        E_p *= aberration
        E_p = propagator1.dot(E_p)
        return E_p * R * TL


    fields = get_fields(cavity, np.sqrt(1-R)*E, n_rt=250)

    s = Spectrum(lambda phase: power(rs, fields, phase))

    resonance_phases = s.compute_resonances(n_res=1, gain_thres=1)


    phases, spectrum = s.spectrum(linspace_kwargs={'focus_width': 1/20})
    ax_spectrum.plot((phases - resonance_phases[0])/(2*np.pi), spectrum, label='2w={:.1f}'.format(2*w*1e3))
    mode = total_field(fields, resonance_phases[0])


    image = ih.image_from_radial(abs(mode) ** 2, N=100, ratio=0.8)
    images.append(image)

    I = abs(mode)**2
    ax_mode.plot(rs/w, I / I.max())
    R1, R2 = 0.98, 0.98
    T = 1 - R1

    base = np.sqrt(R1 * R2) * np.exp(1j * phase_map)

    def power(phase):
        u = x[len(x) // 2:]
        v = E.E[len(x) // 2:]
        b = base[len(x) // 2:]
        return np.trapz(x=u,
                        y=(2 * np.pi * u *
                           abs(v * np.sqrt(T) /
                               (1 - b * np.exp(1j * phase)))**2))

    S = Spectrum(power_fun=power)
    S.compute_resonances()
    phases, spectrum = S.spectrum()

    fig, ax = plt.subplots()
    ax.semilogy(phases, spectrum)
    ax.grid(which='both')
    ax.grid(which='minor', color=[0.9] * 3, linewidth=0.5)

    modes = [
        E.transmit(((np.sqrt(T) / (1 - base * np.exp(1j * phase)))))
        for phase in S.resonance_phases
    ]

    fig, (axI, axP) = EField.create_figure()
    for mode in modes:
Example #3
0
    displacement_phase_factor = np.exp(-2 * 2 * np.pi / lda * 1j * d2)

    def cavity(E):
        E_p = E * aberration
        E_p = propagator1.dot(E_p)
        E_p = lens(E_p, f)
        E_p = propagator2.dot(E_p)
        E_p = lens(E_p, f)
        E_p = propagator1.dot(E_p)
        E_p *= displacement_phase_factor
        return E_p * R * TL

    fields = get_fields(cavity, np.sqrt(1 - R) * E, n_rt=250)

    s = Spectrum(lambda phase: power(rs, fields, phase))

    resonance_phases = s.compute_resonances(n_res=1, gain_thres=0.1)

    limits = (resonance_phases[0] - np.pi, resonance_phases[0] + np.pi)

    phases, spectrum = s.spectrum(linspace_kwargs={
        'focus_width': 1 / 30,
        'num_focused': 300,
        'limits': limits
    })

    ret.append(phases)
    ret.append(spectrum)

    gains.append(spectrum.max())
in_field = gaussian(X, Y, 1.0, w, 0, 0).astype(np.complex64)
in_field /= np.sqrt(power(in_field))

# plt.show()
#
# exit()

print('Computing fields.')
fields = get_fields(np.sqrt(1 - R) * in_field, cavity_fun, 50)
print('Fields computed.')
print('Memory used : {:.0f} Mb'.format(fields.nbytes / 1e6))

# total_field = get_total_field(fields, 0)

s = Spectrum(lambda phase: power_at_phase(fields, phase))

print('Computing resonances.')
resonance_phases = s.compute_resonances(n_res=1, gain_thres=0.3)
print('Resonances computed.')

phases, spectrum = s.spectrum()


def plot_field(field, axis=0, axI=None, axP=None, **kwargs):
    if axis == 0:
        s = np.s_[:, N // 2]
    else:
        s = np.s_[N // 2, :]
    if axI is not None:
        axI.plot(abs(field[s])**2, **kwargs)
Example #5
0
fig.canvas.set_window_title('Spectrum')
fig, ax_mode = plt.subplots()
fig.canvas.set_window_title('Mode')

propagator1 = propagator(Y, d1, lda, ps)
propagator2 = propagator(Y, 2 * d2, lda, ps)


def cavity(E):
    E_p = propagator1.dot(E)
    E_p = lens(E_p, f)
    E_p = propagator2.dot(E_p)
    E_p = lens(E_p, f)
    E_p = propagator1.dot(E_p)
    return E_p * R * TL


fields = get_fields(cavity, np.sqrt(1 - R) * E, n_rt=250)

s = Spectrum(lambda phase: power(rs, fields, phase))

resonance_phases = s.compute_resonances(n_res=5, gain_thres=1)

phases, spectrum = s.spectrum()
ax_spectrum.plot((phases) * 375 / (2 * np.pi), spectrum)
mode = total_field(fields, resonance_phases[0])

ax_mode.plot(rs * 1e3, abs(mode)**2)

plt.show()
    # the definition of the cavity function is in the loop as it depends on delta2
    def cavity(E):
        E_p = E * aberration
        E_p = propagator1.dot(E_p)
        E_p = lens(E_p, f)
        E_p = propagator2.dot(E_p)
        E_p = lens(E_p, f)
        E_p = propagator1.dot(E_p)
        E_p *= displacement_phase_factor
        return E_p * R * TL

    fields = get_fields(cavity, np.sqrt(1 - R) * E,
                        n_rt=340)  # vérifier avec 2*finesse

    s = Spectrum(lambda phase: power_at_phase(rs, fields, phase)
                 )  # helps to find the resonance of the cavity

    resonance_phases = s.compute_resonances(n_res=1, gain_thres=0.1)

    limits = (resonance_phases[0] - np.pi, resonance_phases[0] + np.pi)

    # to plot the spectrum,  we vary a phase but the resonane might be badly sampled
    # this function creates an adequate linspace to have many points around the resonance
    # focus width = width in FSR around the resonance where we want many points
    # num focus = how many points in this interval
    # limits = range of the scan
    phases, spectrum = s.spectrum(linspace_kwargs={
        'focus_width': 1 / 30,
        'num_focused': 300,
        'limits': limits
    })