from optparse import OptionParser
import datetime
import dateutil.parser
import numpy as np
from matplotlib.patches import Circle
import matplotlib.pyplot as plt
import pyana.util.timeseries
import pyana.juice.jspice as js
js.init()
radius = {'Ganymede': 2634, 'Callisto': 2410, 'Europa': 1561, 'Jupiter': 71490}
xyz2idx = {'x': 0, 'y': 1, 'z': 2}
def main(t0, t1, dt, tickdt=None, labeldt=None, origin='Jupiter', ax=None, projection='xy'):
'''Main script'''
if tickdt == None:
tickdt = dt * 10
if labeldt == None:
labeldt = dt * 30
if ax == None:
fig = plt.figure()
ax = fig.add_subplot(111)
body = Circle((0, 0), 1, color='y')
ax.add_patch(body)
tlist0 = pyana.util.timeseries.dtrange(t0, t1, dt)
tlist1 = pyana.util.timeseries.dtrange(t0, t1, tickdt)
tlist2 = pyana.util.timeseries.dtrange(t0, t1, labeldt)
xidx = xyz2idx[projection[0]] # X-axis quantity
yidx = xyz2idx[projection[1]] # X-axis quantity
xyz0 = np.array([js.get_position(t, frame='IAU_%s' % origin, origin=origin) for t in tlist0]) / radius[origin]
ax.plot(xyz0[:, xidx], xyz0[:, yidx])
xyz1 = np.array([js.get_position(t, frame='IAU_%s' % origin, origin=origin) for t in tlist1]) / radius[origin]
ax.plot(xyz1[:, xidx], xyz1[:, yidx], 'o')
xyz2 = np.array([js.get_position(t, frame='IAU_%s' % origin, origin=origin) for t in tlist2]) / radius[origin]
for i, t in enumerate(tlist2):
ax.text(xyz2[i, xidx], xyz2[i, yidx], t.strftime('%H:%M'))
ax.set_xlabel('%s [IAU_%s; R]' % (projection[0], origin))
ax.set_ylabel('%s [IAU_%s; R]' % (projection[1], origin))
ax.set_aspect(1)
return ax
if __name__ == "__main__":
usage = "usage: %prog [options] t0 t1 dt(s) dt2(s) origin projection"
parser = OptionParser(usage)
(options, args) = parser.parse_args()
if len(args) != 6:
parser.error("incorrect number of arguments")
main(dateutil.parser.parse(args[0]), dateutil.parser.parse(args[1]), datetime.timedelta(seconds=int(args[2])), origin=args[4], tickdt=datetime.timedelta(seconds=int(args[3])), projection=args[5])