{
  "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": [
        "NASA JunoCam\n============\n\nExample of JunoCam field of view projection during the 2021 Ganymede\nflyby.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "In June 2021, the Juno spacecraft made a flyby of Ganymede an recorded a\nseries of images of the surface.\n\n![JunoCam image 10,629](/images/junocam_10629-rgb.png)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nfrom planetary_coverage import GANYMEDE, TourConfig\nfrom planetary_coverage.misc import wget"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Manually download the required kernels\n======================================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "remote = 'https://naif.jpl.nasa.gov/pub/naif/JUNO/kernels'\n\nkernels = (\n    'lsk/naif0012.tls',\n    'pck/pck00010.tpc',\n    'fk/juno_v12.tf',\n    'ik/juno_junocam_v03.ti',\n    'sclk/JNO_SCLKSCET.00114.tsc',\n    'spk/de440s.bsp',\n    'spk/juno_pred_orbit.bsp',\n    'spk/juno_rec_orbit.bsp',\n    'spk/juno_struct_v04.bsp',\n    'spk/jup363.bsp',\n    'spk/spk_pre_210416_210902_210608_btm34_p.bsp',\n    'ck/juno_sc_rec_210607_210608_v01.bc',\n)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "for kernel in kernels:\n    wget(f'{remote}/{kernel}', f'data/JUNO/kernels/{kernel}', skip=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Load Juno trajectory\n====================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "juno = TourConfig(\n    kernels=[f'data/JUNO/kernels/{kernel}' for kernel in kernels],\n    spacecraft='JUNO',\n    target='Ganymede',\n)\n\njunocam = juno['2021-06-07T16:57:22.8']  # Frame 6 of image 10,629\n\njunocam"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Project the JunoCam FOVs\n========================\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(12, 8))\n\nax = fig.add_subplot(projection=GANYMEDE)\n\nax.add_collection(junocam['JUNOCAM_RED'].fovs(edgecolor='tab:red', lw=3))\nax.add_collection(junocam['JUNOCAM_GREEN'].fovs(edgecolor='tab:green', lw=3))\nax.add_collection(junocam['JUNOCAM_BLUE'].fovs(edgecolor='tab:blue', lw=3))\n\nax.set_xticks(range(300, 361, 5))\nax.set_yticks(range(-10, 31, 5))\n\nax.set_xlim(300, 360)\nax.set_ylim(-10, 31)\n\nax.set_title('JunoCam RGB footprints (frame 6 of image 10,629)')\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Comparison with the original image\n==================================\n\n![JunoCam image 10,629 - frame 6](/images/junocam_10629-rgb_frame_6.png)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "::: {.admonition}\nDownload\n\n-   `juno.ipynb`{.interpreted-text role=\"download\"}\n-   `juno.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
}