mexpvat_demo.plot_positionΒΆ

An example to plot out the position of MEX for a selected time interval.

""" An example to plot out the position of MEX for a selected time interval.
"""
import numpy as np
import matplotlib.pyplot as plt

if __name__ == "__main__":

    ### Spice binding (SpiceyPy) is used. Installation of SpiceyPy is needed.
    ### If the following ``import`` fails, the installation of SpiceyPy has not done.
    ### See https://irfpy.irf.se/projects/aspera/quickinstall.html
    import spiceypy as spice

    ### MEX Spice related functionalites.
    ### See https://irfpy.irf.se/projects/aspera/api/api_irfpy.mexpvat.mexspice.html
    ### for the setup of MEX spice setting.
    from irfpy.mexpvat import mexspice
    mexspice.init(level='noatt')   # Initialize the spice.  'noatt' will not load attitude file.

    ### Use get_position function to get the position at the given time.
    import datetime
    t0 = datetime.datetime(2008, 6, 27, 0, 0, 0)    # 2008-06-27T00:00:00
    t1 = datetime.datetime(2008, 6, 27, 3, 0, 0)    # 2008-06-27T03:00:00

    ### To make the plot, every 1 min data is retrieved.
    dsamples = datetime.timedelta(minutes=1)

    ### Using dtrange function in irfpy.util.utc package, an list of datetime
    ### is obtained.
    from irfpy.util import utc
    tsamples = utc.dtrange(t0, t1, dsamples)

    ### Define the parameter
    frame = 'MSO'
    origin = 'MARS'
    target = 'MEX'

    ### Positions
    xsamples = np.array([mexspice.get_position(t, target=target, origin=origin, frame=frame) for t in tsamples])    #  [N, 3] array where N is the length of tsamples

    ### X-Y plot as example
    plt.plot(xsamples[:, 0], xsamples[:, 1], 'k:')

    ### X is flipped.  (Left is sun)
    x0, x1 = plt.xlim()
    plt.xlim(x1, x0)

    plt.xlabel('X MSO [km]')
    plt.ylabel('Y MSO [km]')
    plt.gca().set_aspect(1)