"""Lecture 30: the same first three stages and pitch-over launched from Sriharikota on every heading, in steps of
15 deg: the inertial specific energy v^2/2 - mu/r at third-stage burnout, and the burnout height.
Writes img/fig-30-energy.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE
import _orbit30 as O

HEAD = np.arange(0.0, 361.0, 15.0)
RUNS = [O.boost(float(a % 360)) for a in HEAD]
E = np.array([r["energy"] for r in RUNS]) / 1e6
H = np.array([r["h"] for r in RUNS]) / 1e3

if __name__ == "__main__":
    fig, (a, b) = plt.subplots(1, 2, figsize=(10, 4.2), gridspec_kw=dict(wspace=0.3))
    a.plot(HEAD, E, "o-", color=MAROON, lw=2.2, ms=4)
    b.plot(HEAD, H, "o-", color=BLUE, lw=2.2, ms=4)
    for ax in (a, b):
        ax.set_xticks([0, 90, 180, 270, 360], ["N", "E", "S", "W", "N"]); ax.set_xlabel("launch heading"); despine(ax)
    a.set_ylabel("energy at PS3 end (MJ/kg)"); b.set_ylabel("height at PS3 end (km)")
    save(fig, "fig-30-energy")
