cy1_orbnum_checkΒΆ

#!/usr/bin/env python
''' The script checks whether the .irfpyrc setting is correct.

Due to the change in orbnum file, the IRF data base and .irfpyrc would be
wrongly set up.  This script checks the data base is correct or not.
'''
import datetime

import Sadppac
from irfpy.util.irfpyrc import RcFile
from irfpy.util.utc import convert
from irfpy.cy1orb.Cy1OrbitNr import Cy1OrbitNr

import irfpy.swim.SwimSciCount
import irfpy.cena.cena_scicnt

def main():

    ok = 0
    ng = 0

    o942v2 = datetime.datetime(2009, 0o1, 25, 19, 24, 0o4, 81000)
    accpt = datetime.timedelta(seconds = 10)  # 10 sec acceptancy
    o2045v2_0 = datetime.datetime(2009, 0o4, 26, 5, 9, 39, 81000) - accpt
    o2045v2_1 = datetime.datetime(2009, 0o4, 26, 7, 7, 41, 81000) + accpt

    # RcFile should have entry of cy1orb/
    rc = RcFile()
    orbnruri=rc.get('cy1orb', 'orbnruri')
    print(orbnruri)
    if orbnruri == None:
        print("!!!! No entry of cy1orb/orbnruri in ${HOME}/.irfpyrc")
        ng += 1
    else:
        print("oooo Loading the orbitnr file from %s" % orbnruri)

        orbnr = Cy1OrbitNr()
        orbnr.setFromDefaultUri()
        o942 = convert(orbnr.getStartTime(942), datetime.datetime)
        
        print("     orbit 942 starts at %s" % o942)

        if o942 == o942v2:
            print("oooo The orbit information looks v2.")
            ok += 1
        else:
            print("!!!! The orbit information looks v1 or other.")
            ng += 1

    # SWIM data
    loader = irfpy.swim.SwimSciCount.SwimLoader()
    try:
        data2045 = loader.getObservationTime(2045)
    except IOError as e:
        print("!!! The SWIM data base definition in irfpyrc looks wrong")
        ng += 1
    else:
        data2045_start = convert(data2045[0], datetime.datetime)

        if data2045_start >= o2045v2_0 and data2045_start <= o2045v2_1:
            print("oooo The SWIM data base looks v2.")
            ok += 1
        else:
            print("!!!! The SWIM data base looks v1 or other.")
            ng += 1

    # CEAN data

    loader = irfpy.cena.cena_scicnt.CenaLoader()

    data2045 = loader.getObservationTime(2045)

    if len(data2045) == 0:
        print("!!!! The CENA data base definition in irfpyrc looks wrong")
        ng += 1
    else:
        data2045_start = convert(data2045[0], datetime.datetime)
        if data2045_start >= o2045v2_0 and data2045_start <= o2045v2_1:
            print("oooo The CENA data base looks v2.")
            ok += 1
        else:
            print("!!!! The CENA data base looks v1 or other.")
            ng += 1
    
    # Final message.
    print("     Tested %d, Ok %d, Ng %d" % (ok + ng, ok, ng))

    if ng == 0:
        print("oooo No errors found in ${HOME}/.irfpyrc")
    else:
        print("!!!! Some errors found in ${HOME}/.irfpyrc")

if __name__ == "__main__":
    main()