"""Lecture 9, two wind models of the engine (flight.wind): a surface boundary layer with the 1/7 power law, 10 m/s at
10 m (left), and a westerly jet stream with a 60 m/s core at 11 km (right). Writes img/fig-09-winds.png."""
import numpy as np
from _visual import plt, save, despine, BLUE, MAROON, GREY
from flight import wind

BL = wind.PowerLawBoundaryLayer(10.0, 270.0)
JET = wind.JetStream()
H_BL = np.linspace(0.5, 700.0, 300)
H_JET = np.linspace(0.0, 20e3, 401)


def speed(model, h):
    return np.linalg.norm(model.ned(0.0, h, 0.0, 0.0)[:2])


if __name__ == "__main__":
    fig, (a1, a2) = plt.subplots(1, 2, figsize=(11, 4.8))
    a1.plot([speed(BL, h) for h in H_BL], H_BL, color=BLUE, lw=2.4)
    a1.set_xlabel("wind speed (m/s)")
    a1.set_ylabel("height above ground (m)")
    a1.set_title("near the ground: $W\\propto h^{1/7}$", fontsize=12)
    a2.plot([speed(JET, h) for h in H_JET], H_JET / 1e3, color=MAROON, lw=2.4)
    a2.set_xlabel("wind speed (m/s)")
    a2.set_ylabel("altitude (km)")
    a2.set_title("a jet stream near the tropopause", fontsize=12)
    for a in (a1, a2):
        despine(a)
    fig.tight_layout(w_pad=3)
    save(fig, "fig-09-winds")
