"""
Callisto flybys groundtrack
===========================

Example of representation of all the groundtrack
during the Callisto flybys.

"""

import matplotlib.pyplot as plt

from planetary_coverage import CALLISTO, TourConfig


# %%
# List all the Callisto flybys
# ----------------------------

# %%
tour = TourConfig(
    mk='5.1 150lb_23_1',
    version='v422',
    spacecraft='JUICE',
    target='Callisto',
)

tour

# %%
flybys = tour.flybys

flybys

# %%
# Represent the Callisto flybys with CA below 500 km
# --------------------------------------------------

# %%
fig = plt.figure(figsize=(12, 7))
ax = fig.add_subplot(projection=CALLISTO)

for name, flyby in tour.get_flybys(alt_min=500).items():
    ax.plot(
        flyby.where(flyby.alt < 20_000), 'inc', linewidth=3, vmin=0, vmax=90, cbar=False
    )

    ax.plot(flyby.ca, 'o', color='lightgrey')

    ax.annotate(
        f'{name} ({flyby.date_ca})',
        flyby.ca.lonlat,
        xytext=(0, 10),
        textcoords='offset points',
        color='lightgrey',
        ha='center',
        va='center',
    )

ax.colorbar(vmin=0, vmax=90, label='inc', extend='max')
ax.set_title('Callisto flybys below 500 km at CA')

plt.show()

# %%
# .. admonition:: Download
#
#   - :download:`02-callisto_flybys.ipynb`
#   - :download:`02-callisto_flybys.py`
