Source code for irfpy.vexpvat.pvat

''' VEX pvat information.

.. warning::

    This module is deprecated. Use :mod:`irfpy.vexpvat.vexspice` 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)    # doctest: +SKIP
>>> print(pv.poslist.firstJd())    # doctest: +SKIP
 2455346.25200(2010-05-29T18:02:52.800)
>>> print(pv.poslist.lastJd())    # doctest: +SKIP
 2455347.25270(2010-05-30T18:03:53.280)

>>> pv2 = getPvatFile(1501)    # doctest: +SKIP
>>> print(pv2.poslist.firstJd())    # doctest: +SKIP
 2455347.25294(2010-05-30T18:04:14.016)
'''
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 datetime

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

[docs]class PvatFile: ''' PVAT data file. Peje's formatted file. ''' def __init__(self, uriname): ''' Open a file. ''' filename, header = urllib.request.urlretrieve(uriname) self.filename = filename fp = gzip.open(filename) self.poslist = JdSeries() for lin in fp: if lin.startswith('#'): continue elem = lin.split() if len(elem) != 20: continue jd = Julday(float(elem[0])) vec = v3d(float(elem[1]), float(elem[2]), float(elem[3])) self.poslist.add(jd, vec) fp.close()
[docs] def getNeighbor(self, t): ''' >>> t0 = datetime.datetime(2010, 5, 29, 21, 18, 30) # doctest: +SKIP >>> pvat_file = getPvatFile(1500) # Orbit 1500 # doctest: +SKIP >>> pos0 = pvat_file.getNeighbor(t0) # doctest: +SKIP >>> print(pos0.getJd()) # doctest: +SKIP 2455346.38811(2010-05-29T21:18:52.704) >>> print(pos0.getData()) # doctest: +SKIP Vector3d( -2051.54, 4795.86, -68846.3 ) ''' 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)
def __str__(self): return "<irfpy.vexpvat.pvat.PvatFile (%s-%s)>" % ( self.poslist.firstJd(), self.poslist.lastJd())
[docs]def getPvatFile(orbnr): logger = logging.getLogger('getPvatFile') rc = Rc() filebase = rc.get('vexpvat', 'pvaturibase') if filebase is None: raise RuntimeError('No entry in RC. vexpvat/pvaturibase') file = filebase + '/venus_orbit_%04d_pos_sunframe.dat.gz' % orbnr logger.debug('File = %s' % file) return PvatFile(file)
import unittest import doctest
[docs]def doctests(): return unittest.TestSuite(( doctest.DocTestSuite(), ))
if __name__ == '__main__': unittest.main(defaultTest='doctests')