Source code for irfpy.vexpvat.esaspice

''' ESASPICE metakernel handling.

This module provides access to the SPICE metakernel for ESA planetary
missions (Mars Express, Venus Express, ...).

The metakernel file path is specified in the ``.irfpyrc`` configuration
file, under the ``[vexpvat]`` section::

    [vexpvat]
    metakernel = /path/to/meta_kernel.tm

Usage::

    >>> from irfpy.vexpvat import esaspice
    >>> esaspice.furnsh_mk()   # Load the metakernel specified in .irfpyrc

``furnsh_mk()`` reads ``metakernel`` from ``[vexpvat]`` and calls
``spice.furnsh()`` with it.  If the entry is not defined, or the file
does not exist, nothing is done (a warning is logged).
'''
import os
import logging

import spiceypy as spice

import irfpy.util.irfpyrc

logger = logging.getLogger(__name__)


[docs] def metakernel_name(): ''' Return the metakernel path from ``[vexpvat] metakernel`` in .irfpyrc. :return: Metakernel file path, or ``None`` if not specified. ''' rc = irfpy.util.irfpyrc.Rc() return rc.get('vexpvat', 'metakernel')
[docs] def furnsh_mk(mkfile=None): ''' Furnsh the metakernel. If ``mkfile`` is given, it is used. Otherwise the metakernel path is read from ``[vexpvat] metakernel`` in the .irfpyrc file. When the entry is not defined, or the file does not exist, a warning is logged and nothing is done. ''' if mkfile is None: mkfile = metakernel_name() if mkfile is None: logger.warning('No metakernel specified. Set [vexpvat] metakernel in .irfpyrc.') return if not os.path.exists(mkfile): logger.warning('Metakernel file not found: {}'.format(mkfile)) return logger.info('Furnsh metakernel: {}'.format(mkfile)) spice.furnsh(mkfile)