コード例 #1
0
    def plot_fields(self, fig=None):
        '''
        Plots the fields at 7 round trips distributed through
        all the round trips.
        '''
        if not self.fields_are_calculated():
            self.logger.error('Fields are not calculated')
            message = 'Calculate fields before ploting'
            raise NotReady(message)
        if fig is None:
            fig, (axI, axP) = EField.create_figure()

        step = round_to_odd(self.fields.shape[0] / 7)
        for i in range(0, self.fields.shape[0], step):
            efield = EField(self.input_efield.x, self.fields[i, :])
            fig, (axI, axP) = efield.plot(fig,
                                          label='# {}'.format(i),
                                          normalize=True)
        axI.legend()
        return fig, (axI, axP)
    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:
        print(mode.P)
        mode.plot(fig, normalize=False)

    plt.show()