''' List the SC position and velocity.
'''
import datetime
import dateutil.parser
from argparse import ArgumentParser
import numpy as np
from pyana.util.timeseries import dtrange
import pyana.juice.jspice as js
js.init()
def main(tlist):
''' A primitive way of getting the SPICE for JUICE
'''
rj = 71492.
for t in tlist:
print(t, end=' ')
sc_jeqs = js.get_posvel(t, frame='JEQS', target='JUICE', origin='Jupiter')
print('%.3f' % (sc_jeqs[0] / rj), end=' ')
print('%.3f' % (sc_jeqs[1] / rj), end=' ')
print('%.3f' % (sc_jeqs[2] / rj), end=' ')
print('%.3f' % (sc_jeqs[3]), end=' ')
print('%.3f' % (sc_jeqs[4]), end=' ')
print('%.3f' % (sc_jeqs[5]), end=' ')
io_jeqs = js.get_posvel(t, frame='JEQS', target='Io', origin='Jupiter')
print('%.3f' % (io_jeqs[0] / rj), end=' ')
print('%.3f' % (io_jeqs[1] / rj), end=' ')
print('%.3f' % (io_jeqs[2] / rj), end=' ')
# sc_jup_io_angle = np.dot(sc_jeqs[:3], io_jeqs[:3]) / np.linalg.norm(sc_jeqs[:3]) / np.linalg.norm(io_jeqs[:3])
# sc_jup_io_angle = np.clip(sc_jup_io_angle, -1, 1)
# sc_jup_io_angle = np.arccos(sc_jup_io_angle)
# sc_jup_io_angle = np.rad2deg(sc_jup_io_angle)
#
# print '%.1f' % sc_jup_io_angle,
iophase = np.arctan2(io_jeqs[1], io_jeqs[0])
print(' %.1f' % np.rad2deg(iophase), end=' ')
print(' %.1f' % js.sun_longitude_system3(t), end=' ')
print()
def parse():
desc = "Using SPICE, list the SC position and velocity together with Io position in EqSC."
parser = ArgumentParser(description=desc)
timedelta = lambda s: datetime.timedelta(seconds=int(s))
parser.add_argument('-d', '--delta', dest='dt', default=timedelta(60),
type=timedelta, help='Time delta',
)
parser.add_argument('-f', '--t0', dest='t0', default=dateutil.parser.parse('2031-05-01T00:00:00'),
type=dateutil.parser.parse, help='Start time')
parser.add_argument('-t', '--t1', dest='t1', default=dateutil.parser.parse('2031-06-01T00:00:00'),
type=dateutil.parser.parse, help='End time')
args = parser.parse_args()
return args
if __name__ == "__main__":
args = parse()
tlist = dtrange(args.t0, args.t1, args.dt)
main(tlist)