cy1orb_mkeclipseΒΆ

A script to make eclipse.dat file.

Eclipse data file, eclipse.dat, is generated via this program. The file is used for irfpy.cy1orb.eclipse module. The setting file .irfpyrc specifies the resulting file via cy1orb/eclipseuri entry.

#!/usr/bin/env python
''' A script to make eclipse.dat file.

Eclipse data file, eclipse.dat, is generated via this program.
The file is used for irfpy.cy1orb.eclipse module.
The setting file .irfpyrc specifies the resulting file via
cy1orb/eclipseuri entry.
'''

import os
import sys
import logging
import math
import datetime

import irfpy.cy1orb.Cy1OrbitNr
import irfpy.cy1orb.pvat2

if __name__ == '__main__':
    t0 = datetime.datetime(2008, 12, 8)
    t1 = datetime.datetime(2009, 8, 23)
    dt = datetime.timedelta(seconds=10)
    orbnr = irfpy.cy1orb.Cy1OrbitNr.Cy1OrbitNr()
    orbnr.setFromDefaultUri()

    t = t0

    rm = 1738.
    rm2 = rm*rm

    # Refreshing cache.
    refrat = 10000
    ref = refrat

    wasin = None

    in_eclipse = lambda pos: (pos[0] < 0 and pos[1]*pos[1] + pos[2]*pos[2] < rm2)

    print('#Date Time Orb Event')
    print('#Created by %s' % (os.path.abspath(sys.argv[0])))
    print('#Created at %s UTC'%datetime.datetime.utcnow())

    while t <= t1:
        try:
            pos = irfpy.cy1orb.pvat2.getlsepos(t)
        except IOError as e:
            print(t, 'Missing', file=sys.stderr)
            t = t + dt
            continue

        isin = in_eclipse(pos)

        # For the first data, just assume no status change.
        if wasin == None:
            wasin = isin

        if isin and not wasin:  # Enter
            onr = orbnr.getOrbitNr(t)
            print(t, onr, "IN__ECLIPSE")

        elif not isin and wasin:  # Exit
            onr = orbnr.getOrbitNr(t)
            print(t, onr, "OUT_ECLIPSE")


        t = t + dt
        wasin = isin

        # For refreshing the cache.
        ref = ref - 1
        if ref < 0:
            print('refreshing', file=sys.stderr)
            irfpy.cy1orb.pvat2.clear_cache()
            ref = refrat