Source code for irfpy.mexpvat.pvat

''' MEX pvat information.

.. warning::

    This module is deprecated. Use :mod:`irfpy.mexpvat.mexspice` module.

PVAT information is obtained from Peje's format file.
The simplest way is using :meth:`getPvatFile` to
instance :class:`PvatFile` class.

> pv = getPvatFile(1500)

.. todo::

    Sample code with embedded sample file should be produced.

.. todo::

    A new pvat2 module, resembling to vexpvat.pvat2 module, to be developed.

'''
import os
import gzip

import logging

from irfpy.util.julday import Julday, JdSeries, JdObject
from irfpy.util.vector3d import Vector3d as v3d
from irfpy.util.utc import convert
from irfpy.util.irfpyrc import Rc

import urllib.request, urllib.parse, urllib.error

import warnings as _w

_w.warn("irfpy.mexpvat.pvat is deplicated. Use irfpy.mexpvat.mexspice module for future use.", DeprecationWarning)

[docs]class PvatFile: ''' PVAT data file. Peje's formatted file. Peje's formatted file consists of various information. Two is so far supported. Position of MEX w.r.t. the Mars in MSO coordinates. Get via the member of ``poslist`` (``JdSeries`` instance) or :func:`getNeighbor` Position of Phobos w.r.t. the Mars in MSO coordinates. Get via the member of ``phoboslist`` (``JdSeries`` instance). A sample can be seen in the script of :mod:`mexpvat_phobos_distance`. ''' def __init__(self, uriname): ''' Open a specified. ''' self.logger = logging.getLogger(self.__class__.__name__) filename, header = urllib.request.urlretrieve(uriname) self.filename = filename fp = gzip.open(filename) self.poslist = JdSeries() self.phoboslist = JdSeries() for lin in fp: if lin.startswith('#'): continue elem = lin.split() if len(elem) != 26: # For MEX, 26 elements is in the list. continue jd = Julday(float(elem[0])) vec = v3d(float(elem[1]), float(elem[2]), float(elem[3])) self.poslist.add(jd, vec) phobos = v3d(float(elem[7]), float(elem[8]), float(elem[9])) self.phoboslist.add(jd, phobos) fp.close()
[docs] def getNeighbor(self, t): ''' Return the closest data in the format of ``JdObject``. ''' t0 = convert(t, Julday) if not self.poslist.isIncluded(t0): raise RuntimeError('Given t0=%s is not in the range of the file %s' % (t0, self.filename)) return self.poslist.getNeighbor(t0)
[docs]def getPvatFile(orbnr): ''' Return the instance of :class:`PvatFile` from the given orbit number. Read the PVAT file refering to [mexpvat]-pvaturibase entry in the RcFile. ''' logger = logging.getLogger('getPvatFile') rc = Rc() filebase = rc.get('mexpvat', 'pvaturibase') if filebase is None: raise RuntimeError('No entry in RC. mexpvat/pvaturibase') file = filebase + '/mars_orbit_%04d_pos_sunframe.dat.gz' % orbnr logger.debug('File = %s' % file) return PvatFile(file)