def plot_all_trims(aircraft, hs, Mas, sms, kms, trims, filename=None):
    '''
    Affichage graphique des valeurs de trim
    '''
    margins = (0.03, 0.05, 0.98, 0.95, 0.15, 0.46)
    fig = ut.prepare_fig(window_title='Trims {}'.format(aircraft.name), figsize=(20.48, 10.24), margins=margins)
    
    m=0
    for k, sm in enumerate(sms):
        for l,km in enumerate(kms):
            for i, h in enumerate(hs):
                for j, Ma in enumerate(Mas):
                    alpha, dphr, dth = trims[i, j, k, l]
                    fmt = 'alt {:5.0f} Ma {:.1f} sm {:.1f} km {:.1f} -> alpha {:5.2f} deg phr {:-5.1f} deg throttle {:.1f} %'
                    print fmt.format(h, Ma, sm, km, ut.deg_of_rad(alpha), ut.deg_of_rad(dphr), 100*dth)
            legend, params = ['Mach {}'.format(Ma) for Ma in Mas], r'\quad sm={} \quad km={}'.format(sm, km)
            ax = plt.subplot(4, 3, 3*m+1)
            plt.plot(hs, ut.deg_of_rad(trims[:, 0, k, l, 0]))
            plt.plot(hs, ut.deg_of_rad(trims[:, 1, k, l, 0]))
            ut.decorate(ax, r'$\alpha {}$'.format(params), r'altitude', '$deg$', legend=legend)
            ax = plt.subplot(4, 3, 3*m+2)
            plt.plot(hs, ut.deg_of_rad(trims[:, 0, k, l, 1]))
            plt.plot(hs, ut.deg_of_rad(trims[:, 1, k, l, 1]))
            ut.decorate(ax, r'$\delta_{{PHR}} {}$'.format(params), r'altitude', '$deg$', legend=legend)
            ax = plt.subplot(4, 3, 3*m+3)
            plt.plot(hs, trims[:, 0, k, l, 2]*100)
            plt.plot(hs, trims[:, 1, k, l, 2]*100)
            ut.decorate(ax, r'$\delta_{{th}} {}$'.format(params), r'altitude', '$\%$', legend=legend)
            m = m+1
    if filename<> None: plt.savefig(filename, dpi=160)
def plot_Cm(P, filename=None):
    alphas = np.linspace(ut.rad_of_deg(-10), ut.rad_of_deg(20), 30)
    mss = np.array([-0.1, 0, 0.2, 1])
    figure = ut.prepare_fig(None, u'Coefficient du moment de tangage {}'.format(P.name))
    for ms1 in mss:
        plt.plot(ut.deg_of_rad(alphas), Cm(P, alphas, ms1))
    ut.decorate(plt.gca(), u'Coefficient du moment de tangage', r'$\alpha$ en degres', '$C_m$')
    plt.legend(['ms =  {}'.format(ms) for ms in mss], loc='best')
    if filename<> None: plt.savefig(filename, dpi=160)
def plot_CL(P, filename=None):
    alphas = np.linspace(ut.rad_of_deg(-10), ut.rad_of_deg(20), 30)
    dms = np.linspace(ut.rad_of_deg(20), ut.rad_of_deg(-30), 3)
    figure = ut.prepare_fig(None, u'Coefficient de Portance {}'.format(P.name))
    for dm in dms:
        plt.plot(ut.deg_of_rad(alphas), CL(P, alphas, dm))
    ut.decorate(plt.gca(), u'Coefficient de Portance', r'$\alpha$ en degres', '$C_L$')
    plt.legend(['$\delta _{{PHR}} =  ${:.1f}'.format(ut.deg_of_rad(dm)) for dm in dms], loc='best')
    if filename<> None: plt.savefig(filename, dpi=160)
def plot_dphr_e(P, filename=None):
    alphas = np.linspace(ut.rad_of_deg(-10), ut.rad_of_deg(20), 30)
    mss = [-0.1, 0., 0.2, 1.]
    figure = ut.prepare_fig(None, u'Équilibre {}'.format(P.name))
    for ms in mss:
        P.set_mass_and_static_margin(0.5, ms)
        dmes = np.array([dphr_e(P, alpha) for alpha in alphas])
        plt.plot(ut.deg_of_rad(alphas), ut.deg_of_rad(dmes))
    ut.decorate(plt.gca(), r'$\delta_{PHR_e}$', r'$\alpha$ en degres', r'$\delta_{PHR_e}$ en degres',
                ['$ms =  ${: .1f}'.format(ms) for ms in mss])
def plot_CLe(P):
    alphas = np.linspace(ut.rad_of_deg(-10), ut.rad_of_deg(20), 30)
    figure = ut.prepare_fig(None, u'Coefficient de portance équilibrée {}'.format(P.name))
    sms = [0.2, 1]
    for sm in sms:
        P.set_mass_and_static_margin(0.5, sm)
        dphres = [dphr_e(P, alpha) for alpha in alphas]
        CLes = [CL(P, alpha, dphr) for alpha, dphr in zip(alphas, dphres)]
        plt.plot(ut.deg_of_rad(alphas), CLes)
    ut.decorate(plt.gca(), u'Coefficient de portance équilibrée', r'$\alpha$ en degres', r'$CL_e$',
                ['$ms =  ${: .1f}'.format(sm) for sm in sms])
def plot_polar(P):
    alphas = np.linspace(ut.rad_of_deg(-10), ut.rad_of_deg(20), 30)
    figure = ut.prepare_fig(None, u'Polaire équilibrée{}'.format(P.name))
    sms = [0.2, 1]
    for sm in sms:
        P.set_mass_and_static_margin(0.5, sm)
        dphres = [dphr_e(P, alpha) for alpha in alphas]
        CLes = [CL(P, alpha, dphr) for alpha, dphr in zip(alphas, dphres)]
        CDes = [P.CD0 + P.ki * CL1**2 for CL1 in CLes]
        plt.plot(CDes, CLes)
    ut.decorate(plt.gca(), u'Polaire équilibrée', r'$CD_e$', r'$CL_e$',
                ['$ms =  ${: .1f}'.format(sm) for sm in sms])
Пример #7
0
def plot(time, X, U=None, figure=None, window_title="Trajectory"):
    figure = ut.prepare_fig(figure, window_title, (20.48, 10.24))
    plots = [("$y$", "m", X[:, s_y], None), ("$h$", "m", X[:, s_h], 2.),
             ("$v_a$", "m/s", X[:, s_va], 1.),
             ("$\\alpha$", "deg", ut.deg_of_rad(X[:, s_a]), 2.),
             ("$\\theta$", "deg", ut.deg_of_rad(X[:, s_th]), 2.),
             ("$q$", "deg/s", ut.deg_of_rad(X[:, s_q]), 2.)]
    for i, (title, ylab, data, min_yspan) in enumerate(plots):
        ax = plt.subplot(3, 2, i + 1)
        plt.plot(time, data)
        ut.decorate(ax, title=title, ylab=ylab, min_yspan=min_yspan)
    return figure
Пример #8
0
    def plot(self, n_col=7):
        margins = (0.08, 0.06, 0.97, 0.95, 0.15, 0.33)
        fig = utils.prepare_fig(window_title='database', margins=margins)
        n_row = int(math.ceil(len(self.ms) / float(n_col))) + 2
        for i in range(n_row):
            for j in range(n_col):
                k = i * n_col + j
                if k >= len(self.ms): break
                ax = plt.subplot(n_row, n_col, k + 1)
                _m = self.ms[k]['marker']
                plt.scatter(_m.pts[:, 0], _m.pts[:, 1])
                plt.scatter(_m.Xc[0], _m.Xc[1], color='r')
                s = 0.025
                #pdb.set_trace()
                has = ax.arrow(_m.Xc[0],
                               _m.Xc[1],
                               _m.smallest_evec[0] * s,
                               _m.smallest_evec[1] * s,
                               head_width=0.005,
                               head_length=0.01,
                               fc='g',
                               ec='k',
                               alpha=0.5)
                hal = ax.arrow(_m.Xc[0],
                               _m.Xc[1],
                               _m.largest_evec[0] * s,
                               _m.largest_evec[1] * s,
                               head_width=0.005,
                               head_length=0.01,
                               fc='r',
                               ec='k',
                               alpha=0.5)
                leg = plt.legend(handles=[has, hal],
                                 labels=['smallest ev', 'largest ev'])
                leg.get_frame().set_alpha(0.2)
                utils.decorate(ax, title=_m.name, xlab='x',
                               ylab='y')  #, legend=['1', '2'])

                ax.set_aspect('equal')

        for i in range(n_col):
            ax = plt.subplot(n_row, n_col, n_col + i + 1)
            m = self.ms[i]['marker']
            plt.scatter(m.pts_c2[:, 0], m.pts_c2[:, 1])
            ax.set_aspect('equal')
            utils.decorate(ax, title='normalized', xlab='x', ylab='y')

        ax = plt.subplot(n_row, 1, n_row)
        plt.text(0.5,
                 0.5,
                 "{}".format(self.inter_marker_dists),
                 family='monospace')
def plot_thrust(P, filename=None):
    figure = ut.prepare_fig(None, u'Poussée {}'.format(P.name))
    hs = np.linspace(3000, 11000, 5)
    for h in hs:
        Machs = np.linspace(0.5, 0.8, 30)
        thrusts = np.zeros(len(Machs))
        for i in range(0, len(Machs)):
            thrusts[i] = dyn.propulsion_model([0, h, dyn.va_of_mach(Machs[i], h), 0, 0, 0], [0, 1., 0, 0], P)
        plt.plot(Machs, thrusts)
    ut.decorate(plt.gca(), u'Poussée maximum {}'.format(P.name), r'Mach', '$N$', 
                ['{} m'.format(h) for h in hs])
    if filename<> None: plt.savefig(filename, dpi=160)
    return figure
Пример #10
0
def plot(time, X, U=None, figure=None, window_title="Trajectory"):
    figure = ut.prepare_fig(figure, window_title, (20.48, 10.24))
    plots = [("$y$", "m", X[:, s_y], None),
             ("$h$", "m", X[:, s_h], 2.),
             ("$v_a$", "m/s", X[:, s_va], 1.),
             ("$\\alpha$", "deg", ut.deg_of_rad(X[:, s_a]), 2.),
             ("$\\theta$", "deg", ut.deg_of_rad(X[:, s_th]), 2.),
             ("$q$", "deg/s", ut.deg_of_rad(X[:, s_q]), 2.)]
    for i, (title, ylab, data, min_yspan) in enumerate(plots):
        ax = plt.subplot(3, 2, i + 1)
        plt.plot(time, data)
        ut.decorate(ax, title=title, ylab=ylab, min_yspan=min_yspan)
    return figure
Пример #11
0
def plot_short(time, X, U, figure=None, window_title="trajectory"):
    margins = (0.06, 0.05, 0.98, 0.96, 0.20, 0.34)
    figure = utils.prepare_fig(figure,
                               window_title,
                               figsize=(0.75 * 20.48, 0.75 * 10.24),
                               margins=margins)
    plots = [("x", "m", X[:, Plant.s_x]),
             ("$\\theta$", "deg", utils.deg_of_rad(X[:, Plant.s_theta])),
             ("$\\tau$", "N.m", U[:, Plant.i_t])]
    for i, (title, ylab, data) in enumerate(plots):
        ax = plt.subplot(3, 1, i + 1)
        plt.plot(time, data, linewidth=2)
        utils.decorate(ax, title=title, ylab=ylab)
    return figure
def plot_poles(aicraft, hs, Mas, sms, kms, filename=None):
    '''
    Affichage graphique de la position des poles pour une série de points de trim
    '''
    margins = (0.03, 0.05, 0.98, 0.95, 0.2, 0.38)
    fig = ut.prepare_fig(window_title='Poles {}'.format(aircraft.name), figsize=(20.48, 10.24), margins=margins)
    for i, h in enumerate(hs[::-1]):
        for j, Ma in enumerate(Mas):
            ax = plt.subplot(len(hs), len(Mas), i*len(Mas)+j+1)
            legend = []
            for k, sm in enumerate(sms):
                for l, km in enumerate(kms):
                    A, B, poles, vect_p = get_linearized_model(aicraft, h, Ma, sm, km)
                    print('{}'.format(poles))
                    plt.plot(poles.real, poles.imag, '*', markersize=10)
                    legend.append('ms={} km={}'.format(sm, km))
            ut.decorate(ax, r'$h={}m \quad  Ma={}$'.format(h, Ma), legend=legend,  xlim=[-3., 0.1])
    if filename<> None: plt.savefig(filename, dpi=160)                                    
Пример #13
0
def plot_marker(m, label_points=True, plot_pc=False):
    margins = (0.08, 0.06, 0.97, 0.95, 0.15, 0.33)
    fig = utils.prepare_fig(window_title='{}'.format(m.name),
                            figsize=(10.24, 10.24),
                            margins=margins)
    ax = plt.subplot(1, 2, 1)
    plt.scatter(m.pts[:, 0], m.pts[:, 1])
    plt.scatter(m.Xc[0], m.Xc[1], color='r')
    if label_points:
        for i, p in enumerate(m.pts):
            ax.text(p[0], p[1], '{}'.format(i))
    if plot_pc:
        s = 0.25 * m.scale
        ax.arrow(m.Xc[0],
                 m.Xc[1],
                 m.smallest_evec[0] * s,
                 m.smallest_evec[1] * s,
                 head_width=0.005,
                 head_length=0.01,
                 fc='g',
                 ec='g',
                 alpha=0.5)
        ax.arrow(m.Xc[0],
                 m.Xc[1],
                 m.largest_evec[0] * s,
                 m.largest_evec[1] * s,
                 head_width=0.005,
                 head_length=0.01,
                 fc='r',
                 ec='r',
                 alpha=0.5)
    plt.plot(m.pts[:, 0], m.pts[:, 1])
    utils.decorate(ax, title='original', xlab='x', ylab='y')
    ax.set_aspect('equal')

    ax = plt.subplot(1, 2, 2)
    n_pts = m.pts_c1  #m.pts_c2
    plt.scatter(n_pts[:, 0], n_pts[:, 1])
    plt.scatter(0, 0, color='r')
    if label_points:
        for i, p in enumerate(n_pts):
            ax.text(p[0], p[1], '{}'.format(i))
    utils.decorate(ax, title="normalized")
    ax.set_aspect('equal')