Ejemplo n.º 1
0
from beluga.visualization import BelugaPlot
from beluga.visualization.datasources import Dill
# plots = BelugaPlot('./data.dill',default_sol=-1,default_step=0)
unc_ds = Dill('../../mpbvp/boundedBrachistochrone/data.dill')
plots = BelugaPlot('./data.dill',
                   default_sol=-1,
                   default_step=-1,
                   renderer='matplotlib')

plots.add_plot().line('x','y',label='Solution', sol=-1, step=-1,style={'lw':2.0})               \
                .line('x','y',label='Unconstrained Solution', datasource=unc_ds, step=0, sol=-1,style={'lw':2.0})\
                .line('x','xlim-x',label='Constraint1',step=-1,sol=-1) \
                .xlabel('x(t)').ylabel('y(t)')      \
                .title('Trajectory')
# .line('x','-2-0.75*x',label='Constraint2',step=-1,sol=-1) \
plots.add_plot().line('t','theta*180/3.14')                    \
                .xlabel('t (s)').ylabel('theta (degrees)')      \
                .title('Control history')

plots.add_plot().line('t','lamX')                    \
                .xlabel('t (s)').ylabel('lamX')      \
                .title('lamX')
plots.render()
Ejemplo n.º 2
0
from beluga.visualization import BelugaPlot
from beluga.visualization.datasources import Dill
# plots = BelugaPlot('./data.dill',default_sol=-1,default_step=0)
mpbvp_ds = Dill('../../mpbvp/planarHypersonicWithHeatRate/data_1200.dill')
plots = BelugaPlot('./data_1200_2deg15km_ep4.dill',
                   default_sol=-1,
                   default_step=-1,
                   renderer='matplotlib')


plots.add_plot().line('theta*180/3.14','h/1000',label='ICRM Solution')                    \
                .xlabel('Downrange (deg)').ylabel('h (km)')      \
                .title('Altitude vs. Downrange') \
                .line('theta*180/3.14','h/1000',label='MPBVP Solution', datasource=mpbvp_ds, step=-1, sol=-1) \

plots.add_plot().line('t','k*sqrt(rho0*exp(-h/H)/rn)*v**3/10000',label='ICRM Solution') \
                .line('t','k*sqrt(rho0*exp(-h/H)/rn)*v**3/10000',label='MPBVP Solution', datasource=mpbvp_ds, step=-1, sol=-1) \
                .xlabel('t (s)').ylabel('Heat-rate')      \
                .title('Heat-rate vs. Time')

# plots.add_plot().line('t','theta*180/3.14',label='ICRM Solution')                    \
#                 .line('t','theta*180/3.14',label='MPBVP Solution', datasource=mpbvp_ds, step=-1, sol=-1)\
#                 .line('t','theta*180/3.14',label='Unconstrained Solution', datasource=mpbvp_ds, step=0, sol=-1)\
#                 .xlabel('t (s)').ylabel('theta (degrees)')      \
#                 .title('Control history')
#
# plots.add_plot().line('t','lamY', label='ICRM Solution')                    \
#                 .line('t','lamY', label='MPBVP Solution', datasource=mpbvp_ds, step=-1, sol=-1)\
#                 .line('t','lamY', label='Unconstrained Solution', datasource=mpbvp_ds, step=0, sol=-1) \
#                 .xlabel('t (s)').ylabel('lamY')      \
#                 .title('lamY')
Ejemplo n.º 3
0
import matplotlib.cm as cmx
import matplotlib as mpl

mpl.rcParams['axes.labelsize'] = 'x-large'
mpl.rcParams['legend.fontsize'] = 'x-large'
mpl.rcParams['xtick.labelsize'] = 'x-large'
mpl.rcParams['ytick.labelsize'] = 'x-large'

output_dir = './plots/'
def save_pic(renderer, fig, p, suffix):
    fh = renderer._get_figure(fig);
    plt.tight_layout()
    plt.savefig(f'{output_dir}/planarHypersonic_{suffix}.eps')

# mpbvp_ds = Dill('../../mpbvp/boundedBrachistochrone/data.dill')
icrm_ds = Dill('../planarHypersonic/data_thesis.dill')
plots = BelugaPlot('./data.dill',default_sol=-1,default_step=-1, renderer='matplotlib')

plots.add_plot().line('theta*re/1000','h/1000',label='QCPI', sol=-1, step=-1, style={'lw':0.0, 'marker':'o'})\
                .line('theta*re/1000','h/1000',label='Shooting', sol=-1, step=-1, style={'lw':2.0})\
                .xlabel('Downrange distance [km]').ylabel('$h$ [km]') \
                .postprocess(ft.partial(save_pic,suffix='qcpi_ht'))

plots.add_plot().line('t','alfa*180/3.14',label='QCPI', style={'lw':0.0, 'marker':'o'})\
                .line('t','alfa*180/3.14',label='Shooting', datasource=icrm_ds, step=-1, sol=-1, style={'lw':2.0})\
                .xlabel('$t$ [s]').ylabel('$\\theta$ [deg]') \
                .postprocess(ft.partial(save_pic,suffix='qcpi_alfa'))

plots.add_plot(colormap=cmx.viridis).line_series('theta*re/1000','h/1000',step=-1,skip=5,  style={'lw':1.5})\
                .xlabel('Downrange distance [km]').ylabel('$h$ [km]') \
                .postprocess(ft.partial(save_pic,suffix='qcpi_evol_ht'))
Ejemplo n.º 4
0
from beluga.visualization import BelugaPlot
from beluga.visualization.datasources import Dill
# from beluga.visualization.renderers import ToyPlot

ds_constraint = Dill('./data-1k2-eps4-eps4.dill') # 26 steps
ds_epsHR = Dill('./data-1k2-eps6-eps4.dill') # 36 steps
ds_epsAlfa = Dill('./data-1k2-eps6-eps7.dill') # 36 steps

# toyplot = ToyPlot(backend = 'png')
# plots = BelugaPlot(datasource=ds_constraint,default_sol=-1,default_step=-1,renderer='bokeh')
plots = BelugaPlot('./data-1k2-eps4-eps4.dill',default_sol=-1,default_step=-1,renderer='matplotlib')

qdot = 'k*v**3*sqrt(rho0*exp(-h/H)/rn)'
# 90
plots.add_plot(mesh_size=512).line_series('theta*re/1000','h/1000', skip=5, datasource=ds_constraint)   \
                .xlabel('Downrange (km)').ylabel('Altitude (km)')      \
                .title('Altitude vs. Downrange')

plots.add_plot(mesh_size=512).line_series('t','qdot/1e4', skip=5, datasource=ds_constraint)              \
                .xlabel('t (s)').ylabel('Heat Rate (W/cm^2)')      \
                .title('Heat Rate vs. Time')

plots.add_plot(mesh_size=512).line_series('t','alfa*180/3.14', skip=5, datasource=ds_constraint) \
                .line('t','alfaMax*180/3.14', datasource=ds_epsAlfa) \
                .xlabel('t (s)').ylabel('Alpha (deg)')      \
                .title('Control History')

plots.add_plot(mesh_size=512).line_series('v/1000','h/1000', skip=5, datasource=ds_constraint) \
                .xlabel('Velocity (km/s)').ylabel('Altitude (km)')      \
                .title('Altitude vs. Velocity')
Ejemplo n.º 5
0
output_dir = './plots/'


def save_pic(renderer, fig, p, suffix):
    fh = renderer._get_figure(fig)
    # tikz_save(f'{output_dir}/brachisto_{suffix}.tex', figureheight='\\figureheight', figurewidth='\\figurewidth')
    plt.tight_layout()
    plt.savefig(f'{output_dir}/brachisto_{suffix}.eps')


def postprocess_ham(r, f, p):
    plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
    save_pic(r, f, p, 'qcpi_ham')


mpbvp_ds = Dill('../../1-brachistochrone/data.dill')
plots = BelugaPlot('./data.dill',
                   default_sol=-1,
                   default_step=-1,
                   renderer='matplotlib')

plots.add_plot(mesh_size=None).line('x','y',label='QCPI', sol=-1, step=-1, style={'lw': 0.0, 'marker':'o'}) \
                .line('x','y',label='Multiple Shooting', datasource=mpbvp_ds, step=-1, sol=-1, style={'lw': 2.0})\
                .xlabel('$x(t)$ [m]').ylabel('$y(t)$ [m]')      \
                .postprocess(ft.partial(save_pic, suffix='qcpi_xy'))

plots.add_plot(mesh_size=None).line('abs(t)','theta*180/3.14',label='QCPI', style={'lw': 0.0, 'marker':'o'}) \
                .line('abs(t)','theta*180/3.14',label='Multiple Shooting', datasource=mpbvp_ds, step=-1, sol=-1, style={'lw': 2.0})\
                .xlabel('$t$ [s]').ylabel('$\\theta$ [deg]')      \
                .postprocess(ft.partial(save_pic, suffix='qcpi_theta'))
Ejemplo n.º 6
0
mpl.rcParams['axes.labelsize'] = 'x-large'
mpl.rcParams['legend.fontsize'] = 'x-large'
mpl.rcParams['xtick.labelsize'] = 'x-large'
mpl.rcParams['ytick.labelsize'] = 'x-large'

output_dir = './plots/'


def save_pic(renderer, fig, p, suffix):
    fh = renderer._get_figure(fig)
    plt.tight_layout()
    plt.savefig(f'{output_dir}/boundedbrachisto_{suffix}.eps')


# mpbvp_ds = Dill('../../mpbvp/boundedBrachistochrone/data.dill')
icrm_ds = Dill('../../icrm/boundedBrachistochrone/data.dill')
plots = BelugaPlot('./data.dill',
                   default_sol=-1,
                   default_step=-1,
                   renderer='matplotlib')

plots.add_plot().line('x','y',label='QCPI', sol=-1, step=-1, style={'lw':0.0, 'marker':'o'})               \
                .line('x','y',label='ICRM + Shooting', datasource=icrm_ds, step=-1, sol=-1, style={'lw':2.0})\
                .line('x','-1.0-x',label='x + y = 1',step=-1,sol=-1,style={'lw':2.0, 'linestyle':'--'}) \
                .xlabel('$x(t)$ [m]').ylabel('$y(t)$ [m]') \
                .postprocess(ft.partial(save_pic,suffix='qcpi_xy'))

plots.add_plot().line('t','theta*180/3.14',label='QCPI Solution', style={'lw':0.0, 'marker':'o'})                    \
                .line('t','theta*180/3.14',label='ICRM + Shooting', datasource=icrm_ds, step=-1, sol=-1, style={'lw':2.0})\
                .xlabel('$t$ [s]').ylabel('$\\theta$ [deg]') \
                .postprocess(ft.partial(save_pic,suffix='qcpi_theta'))
Ejemplo n.º 7
0
            # b = int(b)
            # return r'${} \times 10^{{{}}}$'.format(a, b)

        formatter = ticker.FuncFormatter(fmt)
    else:
        formatter = None
    cb = mpl.colorbar.ColorbarBase(cax,
                                   cmap=cmap,
                                   norm=norm,
                                   orientation=orient,
                                   format=formatter)
    cb.set_label(label)


plots = BelugaPlot('./data_fpa60.dill', default_sol=-1, default_step=-1)
mpbvp_ds = Dill('../../mpbvp/planarHypersonicWithHeatRate/data_1200.dill')
const_ds = Dill('./data_1200_5k_1deg_ep6.dill')
qdot_ds = Dill('./data_1200_ep4.dill')

# Remove \addlegendimage lines from tex file for dot plots

plots.add_plot(colormap=cmx.viridis_r).line_series('theta*re/1000','h/1000',step=1,skip=0,style={'lw':2.0}) \
                .xlabel('Downrange [km]').ylabel('$h$ [km]')\
                .postprocess(ft.partial(save_pic, suffix='evol1_htheta'))

plots.add_plot(colormap=cmx.viridis_r).line_series('t','gam*180/3.14159',step=1,skip=0,style={'lw':2.0}) \
                .xlabel('$t$ [s]').ylabel('$\\gamma$ [deg]')\
                .postprocess(ft.partial(save_pic, suffix='evol1_fpa'))

rho = 'rho0*exp(-h/H)'
Cl = '(1.5658*alfa + -0.0000)'
Ejemplo n.º 8
0
#                 .line3d('xbar5*V*tfreal/1e3','ybar5*V*tfreal/1e3','zbar5*V*tfreal/1e3', datasource=ds_psi5, label='Vehicle 5',style={'lw':2.0})\
#                 .postprocess(ft.partial(add_cylinder,params=Zone1, opacity=0.2, invert=True))\
#                 .xlabel('$x(t)$ [km]').ylabel('$y(t)$ [km]')\
#                 .postprocess(lambda r,f,p: plt.gca().view_init(azim=-35,elev=30))\
#                 .postprocess(lambda r,f,p: plt.axis('equal'))\
#                 .postprocess(ft.partial(save_pic, suffix='psi5_xyz',format='pdf'))
#
#
# plots.add_plot(colormap=cmx.jet).line_series('t*tfreal','gam5*180/pi',  datasource=ds_psi5,style={'lw':1.5})\
#                 .xlabel('$t$ [s]').ylabel('$\\gamma_5(t)$ [deg]')\
#                 .postprocess(ft.partial(add_colorbar, lb=45, ub=125, label='$\psi_5(T)$ [deg]',cmap=cmx.jet))\
#                 .postprocess(ft.partial(save_pic, suffix='psi5_gam'))
#
# plots.add_plot().postprocess(v_psi5_plot)\
#                 .postprocess(ft.partial(save_pic, suffix='psi5_v'))

# Eps6 plots`
ds_eps6 = Dill('data-5v-eps6-14ks-N150.dill')
plots.add_plot()\
                .line('xbar*V*tfreal/1e3','ybar*V*tfreal/1e3',  datasource=ds_eps6, label='Vehicle 1',style={'lw':2.0})\
                .line('xbar2*V*tfreal/1e3','ybar2*V*tfreal/1e3',datasource=ds_eps6, label='Vehicle 2',style={'lw':2.0})\
                .line('xbar3*V*tfreal/1e3','ybar3*V*tfreal/1e3',datasource=ds_eps6, label='Vehicle 3',style={'lw':2.0})\
                .line('xbar4*V*tfreal/1e3','ybar4*V*tfreal/1e3',datasource=ds_eps6, label='Vehicle 4',style={'lw':2.0})\
                .line('xbar5*V*tfreal/1e3','ybar5*V*tfreal/1e3',datasource=ds_eps6, label='Vehicle 5',style={'lw':2.0})\
                .line('xc*V*tfreal/1e3+rc*V*tfreal/1e3*cos(2*pi*t/tf)','yc*V*tfreal/1e3+rc*V*tfreal/1e3*sin(2*pi*t/tf)',datasource=ds_eps6, label='No-Fly Zone',style={'color':'k'})\
                .xlabel('$x(t)$ [km]').ylabel('$y(t)$ [km]')\
                .postprocess(lambda r,f,p: plt.axis('equal'))\
                .postprocess(ft.partial(save_pic, suffix='eps6_xy'))

plots.render()
Ejemplo n.º 9
0
    save_pic(renderer, fig, p, 'icrm_costates')


def postprocess_gpops(renderer, fig, p):
    from matplotlib.font_manager import FontProperties
    fontP = FontProperties()
    fontP.set_size('small')
    fh = renderer._get_figure(fig)
    plt.ylim([-0.11, 0.05])
    plt.legend(loc='upper left', prop=fontP, ncol=2)
    plt.tight_layout()
    # Replace − with - in the output file
    save_pic(renderer, fig, p, 'gpops_costates')


mpbvp_ds = Dill('../../mpbvp/boundedBrachistochrone/data_mpbvp_sol.dill')
plots = BelugaPlot('./data.dill',
                   default_sol=-1,
                   default_step=-1,
                   renderer='matplotlib')
gpops_ds = GPOPS('./brachisto_eps5.mat',
                 states=('x', 'y', 'v', 'xi', 'tf'),
                 controls=('theta', 'ue1'))

plots.add_plot(mesh_size=10).line('x','y',label='ICRM Solution', sol=-1, step=-1, style={'lw': 2.0, 'marker': '.', 'ms':5, 'mew':3.0})               \
                .line('x','y',label='MPBVP Solution', datasource=mpbvp_ds, step=-1, sol=-1, style={'lw': 2.0})\
                .line('x','y',label='Unconstrained Solution', datasource=mpbvp_ds, step=0, sol=-1, style={'lw': 2.0})\
                .line('x','-1.0-x',label='x + y + 1 = 0',step=-1,sol=-1, style={'lw': 2.0, 'ls':'dashed'}) \
                .xlabel('$x(t)$ [m]').ylabel('$y(t)$ [m]')      \
                .postprocess(ft.partial(save_pic, suffix='icrm_xy'))
#
Ejemplo n.º 10
0
    divider = make_axes_locatable(ax)
    cax = divider.append_axes(pos, size="5%", pad=0.05)

    cb = mpl.colorbar.ColorbarBase(cax,
                                   cmap=cmap,
                                   norm=norm,
                                   orientation=orient)

    #
    # cb1 = mpl.colorbar.ColorbarBase(plt.gca(), cmap=cmap,
    #                                 norm=norm,
    #                                 orientation='vertical')
    cb.set_label(label)


one_path_ds = Dill('data-twoveh-s2-a.dill')
plots = BelugaPlot('data-twoveh-unc.dill',
                   default_sol=-1,
                   default_step=-1,
                   renderer='matplotlib')

scale = 300 * 50 / 1e3
Zone1 = np.array([-0.6, 0.0, 0.1]) * scale
Zone2 = np.array([-0.2, 0.3, 0.2]) * scale
Zone2b = np.array([-0.25, 0.225, 0.2]) * scale


def add_vehicle_labels(r, f, p):
    y0 = np.array([0.0, 0.1]) * scale
    x0 = np.ones_like(y0) * -0.8 * scale
Ejemplo n.º 11
0
from beluga.visualization import BelugaPlot
from beluga.visualization.datasources import Dill

# plots = BelugaPlot('./data.dill',default_sol=-1,default_step=-1)
ds = Dill('./data.dill')
# ds2 = Dill('./phu_2k5_eps4.dill')
plots = BelugaPlot(datasource=ds,default_sol=-1,default_step=-1, renderer='matplotlib')
# plots = BelugaPlot('./phu_2k5_eps4.dill',default_sol=-1,default_step=-1, renderer='bokeh')
#
# plots.add_plot().line_series('theta*re/1000','h/1000', step=-1, skip=3)                    \
#                 .xlabel('Downrange (km)').ylabel('h (km)')      \
#                 .title('Altitude vs. Downrange')

plots.add_plot().line('theta*re/1000','h/1000',datasource=ds,label='DS1')                    \
                .xlabel('Downrange (km)').ylabel('h (km)')      \
                .title('Altitude vs. Downrange')
#                .line('theta*re/1000','h/1000',datasource=ds2,label='DS2')                   \
#
# plots.add_plot().line('v/1000','h/1000')                    \
#                 .xlabel('v (km/s)').ylabel('h (km)')      \
#                 .title('Altitude vs. Velocity')
#

plots.add_plot().line('t','gam*180/3.14')                    \
                .xlabel('t (s)').ylabel('fpa (degrees)')      \
                .title('FPA vs. Time')

plots.add_plot().line('t','alfa*180/3.14')                    \
                .xlabel('t (s)').ylabel('alfa (degrees)')      \
                .title('Angle of attack vs. Time')