"""
ESA EnVision
============

Example of mission planning for EnVision Venus orbital insertion.

In June 2021, ESA selected a new M-class mission, `Envision`_, to study Venus planet
from its inner core to upper atmosphere. This mission is still in development but its
proposed orbital trajectory is already available on the ESA-SPICE archive.

.. _`EnVision`: https://www.esa.int/Science_Exploration/Space_Science/ESA_selects_revolutionary_Venus_mission_EnVision

.. image:: https://www.esa.int/var/esa/storage/images/esa_multimedia/images/2021/06/envision_understanding_why_earth_s_closest_neighbour_is_so_different/23341064-1-eng-GB/EnVision_Understanding_why_Earth_s_closest_neighbour_is_so_different_pillars.jpg
    :alt: EnVision spacecraft (Credits ESA)

"""

# sphinx_gallery_thumbnail_number = 2

import matplotlib.pyplot as plt

from planetary_coverage import VENUS, TourConfig
from planetary_coverage.ticks import date_ticks, km_ticks


# %%
# Download EnVision kernels and load the orbital insertion trajectory
# -------------------------------------------------------------------
# *Note*: the location of the EnVision kernels are not explicitly
# listed in the metakernel header, we need to provide this information
# manually in ``remote_kernels``.

# %%
tour = TourConfig(
    mk='study_esc_t2_south_voi_v040',
    version='v040_20220503_001',
    kernels_dir='./data/EnVision/kernels',
    remote_kernels='https://spiftp.esac.esa.int/data/SPICE/ENVISION/kernels',
    download_kernels=True,
    spacecraft='ENVISION',
    target='Venus',
)

voi_traj = tour['2033-05-01':'2033-06-01':'6 h']

voi_traj

# %%
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot()


ax.plot(voi_traj.utc, voi_traj.alt, color='tab:green')

ax.set_ylabel('Altitude')
ax.xaxis.set_major_formatter(date_ticks)
ax.yaxis.set_major_formatter(km_ticks)

plt.title('EnVision Venus orbital insertion')

plt.show()

# %%
# First orbits after insertion
# ----------------------------

# %%
orbits = tour['2033-05-21':'2033-05-25':'1 min']

orbits

# %%
fig = plt.figure(figsize=(14, 9))
ax = fig.add_subplot(projection=VENUS)

ax.plot(orbits, 'alt', vmax=20_000, cmap='Greens_r', lw=3)

ax.set_title('EnVision orbits after Venus insertion')

plt.show()


# %%
# .. admonition:: Download
#
#   - :download:`06-envision.ipynb`
#   - :download:`06-envision.py`
