Source code for irfpy.cy1orb.eclipse

''' Get umbra time from eclipse.dat file.

From eclipse.dat file, one can get the eclipse time.
The eclipse.dat file location is set from .irfpyrc file cy1orb/eclipseuri entry.

>>> e = EclipseDat()
>>> print(e.getEclipse(1000))       # Obtain the time of eclipse for the orbit 1000.
(datetime.datetime(2009, 1, 30, 14, 37, 50), datetime.datetime(2009, 1, 30, 15, 18, 40))
>>> print(e.inEclipse(datetime.datetime(2009, 1, 25, 15, 0, 0)))  # Check if s/c is in eclipse at 2009-01-25T15:00:00.
True

The original data file is generated via spice using ISSDC/spice/cy1_event.cpp program, but this is re-implemented in scripts/cy1orb_mkeclipse.py script.
'''

from irfpy.util.irfpyrc import Rc
from irfpy.util.utc import convert
from irfpy.cy1orb.Cy1OrbitNr import Cy1OrbitNr

import datetime
import dateutil.parser
import logging
import urllib.request
import urllib.parse
import urllib.error

[docs]class EclipseDat: def __init__(self, uri=None): ''' Constructor of the EclipseDat class. Read the data from the specified uri. The eclipse.dat file is read and reformated. The location of file (or uri) can be specified in .irfpyrc file, cy1orb eclipseuri entry. ''' if uri is None: rc=Rc() self.uri = rc.get('cy1orb', 'eclipseuri') else: self.uri = uri logging.debug('URI of Eclpise.dat = %s'%self.uri) self.oNr=Cy1OrbitNr() self.oNr.setFromDefaultUri() try: fname, info = urllib.request.urlretrieve(self.uri) logging.debug('Retrieved Eclipse.dat = %s'%self.uri) # logging.debug('Info of retrieval: %s'%info) f=open(fname, 'r') self.eclip={} for l in f: if l.startswith('#'): continue else: tok = l.split() if len(tok)!=4: continue t = dateutil.parser.parse(tok[0]+' '+tok[1]) orb = int(tok[2]) if orb in self.eclip: pair=self.eclip[orb] else: pair=[None, None] if tok[3] == 'OUT_ECLIPSE': pair[1] = t elif tok[3] == 'IN__ECLIPSE': pair[0] = t self.eclip[orb] = pair logging.debug('Orb=%d/Data=%s'%(orb,self.eclip[orb])) except IOError as e: logging.error('Failed to open or to read the %s'%self.uri) logging.error(e)
[docs] def getEclipse(self, orbit): ''' Obtain a eclipse time for the specified orbit. ''' if orbit in self.eclip: t0, t1 = self.eclip[orbit] return (t0,t1) else: return (None, None)
[docs] def inEclipse(self, t): ''' Check whether the specified time t is inside the eclipse or not. ''' tdt = convert(t, datetime.datetime) logging.debug('Time specified = %s'%tdt) onr=self.oNr.getOrbitNr(tdt) logging.debug('Orbit is =%d'%onr) t0,t1=self.getEclipse(onr) if t0 is None or t1 is None: return False else: if tdt>=t0 and tdt<=t1: return True else: return False
#if __name__=='__main__': # logging.basicConfig() # logging.getLogger().setLevel(logging.DEBUG) # e=EclipseDat() # # for i in range(1750,1800): # t0,t1=e.getEclipse(i) # if t0!=None and t1!=None: # dt=t1-t0 # else: # dt=0 # print i, t0, t1, dt # # print e.inEclipse( datetime.datetime(2009,1,25,15,0,0) ) # from irfpy.util.julday import Julday # print e.inEclipse( Julday(2009,1,25,15,50,0))