Source code for irfpy.pep.juice_spice1205

''' JUICE orbit (2012-May version) using SPICE

.. warning::

    Deprecated and replaced by :mod:`irfpy.juice.jspice`.

The JUICE orbit information from SPICE for the 2012 May version.
The old version (2011-Nov version), use :mod:`juice_spice` module.

The kernel name is ``mantra.jgo_2022_ipc_eur_inc_gan_003.bsp``.
The kernel is not included in the repository.

The kernels are specified by ``.irfpyrc`` file.

::

    [pep]
    juice1205kernels = /Volumes/scidata/data/jupiter/kernels/setup1205.mk

For nominal use, try the following.

>>> juice = JuiceSpice.get_default_instance()

'''

import os
import glob
import logging
logging.basicConfig()
import datetime
import dateutil.parser
import bisect

from pkg_resources import resource_filename

import numpy as np

try:
    import spiceypy as spice
except ImportError:
    import spice


import irfpy.util.irfpyrc

import warnings
warnings.warn('This module is deprecated and replced by irfpy.juice.jspice module.',
    DeprecationWarning)

[docs]class JuiceSpice: __default_instance = None juice_id = -907 juice_name = "JGO"
[docs] @classmethod def get_default_instance(cls): if cls.__default_instance == None: cls.__default_instance = JuiceSpice() cls.__default_instance.load_default_kernels() return cls.__default_instance
def __init__(self): self.logger = logging.getLogger('JuiceSpice') # self.logger.setLevel(logging.INFO) self.logger.setLevel(logging.DEBUG)
[docs] def load_kernel(self, kernel_filename): ''' Load a kernel. Wrapper to spice.furnsh(). ''' self.logger.info('Furnsh: %s' % kernel_filename) spice.furnsh(kernel_filename)
[docs] def load_default_kernels(self): ''' Load default kernels. ''' rc = irfpy.util.irfpyrc.Rc() pepkerns = rc.get('pep', 'juice1205kernels') if pepkerns == None: self.logger.error('Failed to load PEP kernel files') self.logger.error('Specify [pep] juice1205kernels in .irfpyrc') raise RuntimeError('No kernel file specified.') kerns = pepkerns.split(',') kerns = [k.strip() for k in kerns] for k in kerns: self.load_kernel(k) self.logger.debug("Define JUICE") spice.boddef(self.juice_name, self.juice_id)
[docs] def get_position(self, t, relative_to="JUPITER", frame="JSE"): ''' Return the Juice orbiter's position vector. :param t: Time :type t: ``datetime.datetime`` :keyword relative_to: The SPICE name of the body to calculate the position :type relative_to: String :keyword frame: Frame of the position vector :type frame: String :returns: Return the Juice orbiter's position in the given frame :rtype: ``np.array`` of (3,) shape. >>> juice = JuiceSpice.get_default_instance() >>> pos = juice.get_position(datetime.datetime(2031, 6, 5, 12, 55, 15)) >>> print('%.2f %.2f %.2f' % (pos[0], pos[1], pos[2])) 97514.29 -1409055.30 550473.59 ''' et0 = spice.str2et(t.strftime('%FT%T')) self.logger.debug('%s -> ' % (t.strftime('%FT%T'))) et0 = spice.str2et(t.strftime('%FT%T')) self.logger.debug(' %.3f' % (et0)) # self.logger.debug(' -> %s' % spice.et2utc(et0, "ISOC", 3)) relative_to_id = spice.bodn2c(relative_to) try: posvel, lt = spice.spkez(self.juice_id, et0, frame, "LT+S", relative_to_id) except spice.SpiceException as e: self.logger.warn('Spice returned exception. t=%s. et=%.3f.\n### %s' % ( t, et0, e)) return np.array([np.nan, np.nan, np.nan]) return np.array(posvel[0:3])
[docs] def get_velocity(self, t, relative_to="JUPITER", frame="JSE"): ''' Return the Juice orbiter's velocity vector. :param t: Time :type t: ``datetime.datetime`` :keyword relative_to: The SPICE name of the body to calculate the relative velocity :type relative_to: String :keyword frame: Frame of the velocity vector :type frame: String :returns: Return the Juice orbiter's velocity vector in the given frame :rtype: ``np.array`` ''' et0 = spice.str2et(t.strftime('%FT%T')) posvel, lt = spice.spkezr(self.juice_name, et0, frame, 'LT+S', relative_to) return np.array(posvel[3:])
[docs] def get_positions(self, tlist, *args, **kwds): ''' Get position from the list of time. See :meth:`get_position` for the acceptable arguments and keywords. ''' return np.array([self.get_position(t, *args, **kwds) for t in tlist])
[docs]class JuiceSummary: ''' A data base of the juice operation summary. The operation summary has been provided from the project team together with the kernel file. The file name is ``mantra.jgo_2022_ipc_eur_inc_gan_003_summary.pdf``. ''' table = { 'G1': ['G1', datetime.datetime(2030, 1, 22), 'JOI PRM', 400., ], 'G2': ['G2', datetime.datetime(2030, 0o7, 27), 'EVI RED', 300., ], 'G3': ['G3', datetime.datetime(2030, 9, 15), 'EVI RED', 300., ], 'G4': ['G4', datetime.datetime(2030, 10, 16), 'EVI RED', 2179., ], 'G5': ['G5', datetime.datetime(2030, 11, 0o4), 'EVI RED', 1692., ], 'C6': ['C6', datetime.datetime(2030, 11, 16), 'EVI RED', 1107., ], 'C7': ['C7', datetime.datetime(2031, 0o1, 16), 'EVI RED', 1725., ], 'C8': ['C8', datetime.datetime(2031, 0o2, 0o2), 'EUROPA', 743., ], 'E9': ['E9', datetime.datetime(2031, 0o2, 13), 'EUROPA', 400., ], 'E10': ['E10', datetime.datetime(2031, 0o2, 27), 'EUROPA', 400., ], 'C11': ['C11', datetime.datetime(2031, 0o3, 12), 'EUROPA', 837., ], 'G12': ['G12', datetime.datetime(2031, 0o4, 0o2), 'JUP HIGH LAT', 1671., ], 'C13': ['C13', datetime.datetime(2031, 0o4, 14), 'JUP HIGH LAT', 200., ], 'C14': ['C14', datetime.datetime(2031, 0o5, 0o1), 'JUP HIGH LAT', 200., ], 'C15': ['C15', datetime.datetime(2031, 0o5, 17), 'JUP HIGH LAT', 367., ], 'C16': ['C16', datetime.datetime(2031, 0o6, 0o3), 'JUP HIGH LAT', 713., ], 'C17': ['C17', datetime.datetime(2031, 0o6, 20), 'JUP HIGH LAT', 200., ], 'C18': ['C18', datetime.datetime(2031, 0o7, 0o7), 'JUP HIGH LAT', 200., ], 'C19': ['C19', datetime.datetime(2031, 0o7, 15), 'JUP HIGH LAT', 200., ], 'C20': ['C20', datetime.datetime(2031, 0o7, 31), 'JUP HIGH LAT', 200., ], 'C21': ['C21', datetime.datetime(2031, 8, 17), 'JUP HIGH LAT', 1305., ], 'C22': ['C22', datetime.datetime(2031, 9, 0o3), 'JUP HIGH LAT', 200., ], 'C23': ['C23', datetime.datetime(2031, 9, 19), 'JUP HIGH LAT', 200., ], 'C24': ['C24', datetime.datetime(2031, 10, 0o6), 'JUP HIGH LAT', 589., ], 'G25': ['G25', datetime.datetime(2031, 11, 15), 'TRANS GANY', 1036., ], 'C26': ['C26', datetime.datetime(2031, 11, 22), 'TRANS GANY', 382., ], 'C27': ['C27', datetime.datetime(2031, 12, 17), 'TRANS GANY', 1704., ], 'C28': ['C28', datetime.datetime(2032, 0o1, 16), 'TRANS GANY', 528., ], 'C29': ['C29', datetime.datetime(2032, 0o2, 0o1), 'TRANS GANY', 4936., ], 'G30': ['G30', datetime.datetime(2032, 0o3, 0o2), 'TRANS GANY', 17352., ], 'G31': ['G31', datetime.datetime(2032, 0o5, 0o6), 'TRANS GANY', 47805., ], 'G32': ['G32', datetime.datetime(2032, 0o6, 11), 'TRANS GANY', 27191., ], 'G33': ['G33', datetime.datetime(2032, 0o7, 0o2), 'TRANS GANY', 36227., ], 'G34': ['G34', datetime.datetime(2032, 8, 22), 'TRANS GANY', 37483., ], 'GOI': ['GOI', datetime.datetime(2032, 9, 23), 'IN ORBIT GANY', 200., ], 'GCO-500': ['GCO-500', datetime.datetime(2033, 0o2, 22), 'IN ORBIT GANY', 500., ], 'GCO-200': ['GCO-200', datetime.datetime(2033, 0o6, 0o4), 'IN ORBIT GANY', 200., ], 'END': ['END', datetime.datetime(2033, 0o7, 0o4), 'IN ORBIT GANY', 200., ],}
import unittest import doctest
[docs]def doctests(): return unittest.TestSuite(( doctest.DocTestSuite(), ))
if __name__ == '__main__': unittest.main(defaultTest='doctests')