apps120712_spice1205.mission_summaryΒΆ

''' Mission summary from 1205 spice kernel.

.. image:: ../../../src/scripts/apps120712_spice1205/mission_summary.png
    :width: 100%
'''

import datetime

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mpldates

import pyana.pep.juice_spice1205 as jspice

def main():

    missiontable = jspice.JuiceSummary.table

    # Mission JOI.
    tjoi = missiontable['G1'][1]
    print('JOI is', tjoi)
    t0 = datetime.datetime(tjoi.year, tjoi.month, 1)
    
    # Mission end
    tend = missiontable['END'][1]
    print('END is', tend)
    t1 = tend

    # Create time list  (from tjoi to tend with 1 hr tick)
    resolution = datetime.timedelta(hours=1)
    tlist = [mpldates.num2date(t).replace(tzinfo=None) for t in mpldates.drange(t0, t1, resolution)]

    # Tick for the plot
    ticklist = []
    for yr in range(2030, 2034):
        for mo in range(1, 13):
            ticklist.append(datetime.datetime(yr, mo, 1))

    # JUICE spice object
    juice = jspice.JuiceSpice.get_default_instance()

    # Plotting object
    fig = plt.figure(figsize=(20, 15))
    ax = fig.add_subplot(111)

    # Distance to Jupiter
    pos_j = juice.get_positions(tlist, relative_to='JUPITER')
    r_j = np.sqrt((pos_j ** 2).sum(axis=1))
    ax.plot(tlist, r_j / 71000, label='Jupiter')    

    pos_e = juice.get_positions(tlist, relative_to='EUROPA')
    r_e = np.sqrt((pos_e ** 2).sum(axis=1))
    ax.plot(tlist, r_e / 1569.0, 'r', label='Europa')    

    pos_g = juice.get_positions(tlist, relative_to='GANYMEDE')
    r_g = np.sqrt((pos_g ** 2).sum(axis=1))
    ax.plot(tlist, r_g / 2634.1, 'g', label='Ganymede')    

    pos_c = juice.get_positions(tlist, relative_to='CALLISTO')
    r_c = np.sqrt((pos_c ** 2).sum(axis=1))
    ax.plot(tlist, r_c / 2410.0, 'c', label='Callisto')    


    xy = []
    rbody = {'G': 2634.1, 'C':2410.0, 'E':1569}
    cbody = {'G': 'g', 'C': 'c', 'E': 'r'}
    for index, dat in enumerate(missiontable):
        x, y = [missiontable[dat][1], missiontable[dat][3] / rbody[dat[0]] + 1]
        xy.append((x, y))
        ax.annotate(dat, xy=(x, y), xytext=(x, y / (1.2 + (index * 0.5) % 4) ), xycoords='data',
                horizontalalignment='center', verticalalignment='top', arrowprops=dict(arrowstyle='->', color=cbody[dat[0]]))
        ax.plot(x, y, cbody[dat[0]] + 'o')
#        ax.vlines(x, y, y * 10, colors=cbody[dat[0]], linestyle='solid')

    ax.xaxis.set_major_formatter(mpldates.DateFormatter('%F'))
    ax.xaxis.set_ticks(ticklist)
    ax.set_yscale('log')
    ax.set_xlim(t0, t1)
    ax.set_ylim(0.1, 1e4)
    ax.set_ylabel('Distance (Body radius)')
    ax.axhspan(0.1, 1, facecolor='0.8')
    ax.grid()
    ax.legend(loc='upper right')

    fig.autofmt_xdate()

    fig.savefig('mission_summary.png')

if __name__ == "__main__":
    main()