{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# This example is part of the planetary-coverage examples gallery.\n# More examples can be found here: https://docs.planetary-coverage.org"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "ROIs seen by MAJIS during GCO5000\n=================================\n\nExample of opportunities for MAJIS to observe Ganymede ROIs during\nGCO5000 phase.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nfrom planetary_coverage import GANYMEDE, GanymedeROIs, TourConfig, read_events\nfrom planetary_coverage.misc import wget\nfrom planetary_coverage.ticks import deg_ticks"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Download JUICE mission phases from the SOC\n==========================================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "URL = 'https://juicesoc.esac.esa.int/data/DATA/crema_5_0'\nMISSION_PHASES = 'Mission_Phases.csv'\n\nwget(f'{URL}/{MISSION_PHASES}', MISSION_PHASES, skip=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Get GCO 5000 windows from the mission phases\n============================================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "phases = read_events(MISSION_PHASES)\n\ngco_5000 = phases['GCO5000']\n\ngco_5000"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Load JUICE trajectory during GCO 5000\n=====================================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "tour = TourConfig(mk='5.1 150lb', spacecraft='JUICE', instrument='MAJIS',\n                  target='Ganymede', version='v400')\n\nmajis_gco_5000 = tour[gco_5000:'15 min']\n\nmajis_gco_5000"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Keep only the part of the trajectory well lighted\n=================================================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "traj = majis_gco_5000.where(majis_gco_5000.inc < 70)\n\ntraj"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Find the ROIs intersected by the trajectory\n===========================================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "traj_in_rois = traj & GanymedeROIs\n\ntraj_in_rois"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "rois_visible = GanymedeROIs & traj\nrois_not_visible = GanymedeROIs ^ traj\n\nlen(GanymedeROIs), len(rois_visible), len(rois_not_visible)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "(\n    f'{len(rois_visible) / len(GanymedeROIs):.0%} of Ganymede ROIs are '\n    'visible with MAJIS with an incidence lower than 70\u00b0 during GCO 5000.'\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Represent the intersection opportunities on the map\n===================================================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(12, 9))\nax = fig.add_subplot(projection=GANYMEDE)\n\nax.add_collection(traj_in_rois.fovs(facecolors='inc', vmin=45, vmax=70, sort='inc'))\n\nax.add_collection(rois_visible(edgecolors='red'))\nax.add_collection(rois_not_visible(edgecolors='white', linewidths=1, linestyles='--'))\n\nax.colorbar(vmin=45, vmax=70, label='inc')\nax.twin_colorbar(label='Solar elevation', format=90 - deg_ticks)\nax.set_title('MAJIS coverage opportunities during GCO 5000 (downlink windows excluded)')\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "::: {.admonition}\nDownload\n\n-   `majis_gco_5000.ipynb`{.interpreted-text role=\"download\"}\n-   `majis_gco_5000.py`{.interpreted-text role=\"download\"}\n:::\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}