"""Lecture 33: the same entry (8 km/s at 100 km, 8 deg) for bodies of three ballistic coefficients, made by changing
the SRE-1 mass: deceleration and heat flux against height. Writes img/fig-33-beta.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, GREEN
import _entry33 as X
from flight.constants import G0

GAMMA = -8.0
CASES = []
for factor, c in ((0.5, GREEN), (2.0, BLUE), (8.0, MAROON)):
    v = X.capsule("sre-1")
    v.payload *= factor
    tr = X.fly(v, X.SRE_V, X.SRE_H, GAMMA)
    CASES.append(dict(B=X.B_of(v), c=c, tr=tr, **X.peaks(tr)))

if __name__ == "__main__":
    fig, (a, b) = plt.subplots(1, 2, figsize=(10, 4.4), gridspec_kw=dict(wspace=0.2), sharey=True)
    for cs in CASES:
        tr = cs["tr"]
        a.plot(tr.drag / tr.m / G0, tr.h / 1e3, color=cs["c"], lw=2.4, label=f"$m/C_DS$ = {cs['B']:.0f} kg/m²")
        b.plot(tr.heat_flux / 1e6, tr.h / 1e3, color=cs["c"], lw=2.4)
    a.set_xlabel("drag deceleration (g)"); a.set_ylabel("height (km)"); a.set_ylim(10, 90)
    b.set_xlabel("stagnation heat flux (MW/m²)")
    despine(a); despine(b)
    fig.legend(*a.get_legend_handles_labels(), frameon=False, fontsize=11, ncol=3, loc="upper center", bbox_to_anchor=(0.5, 0.0))
    save(fig, "fig-33-beta")
