Source code for irfpy.vnpi.background

''' VEX/NPI background proxy module

It provides a getter of background proxy.

The best practice is to use :class:`DataCenterVnpiBackground` class as folows.

>>> from irfpy.vnpi import background
>>> dc = background.DataCenterVnpiBackground()
>>> import datetime
>>> tobs, (back, total) = dc.nearest(datetime.datetime(2006, 12, 5, 5, 42))
>>> print(tobs)
2006-12-05 05:42:00.898000
>>> print(back)
6.0
>>> print(total)
130.0
'''
from irfpy.util.irfpyrc import Rc
import irfpy.npicommon.background as cbg

[docs]class DataCenterVnpiBackground(cbg.DataCenterBackground): """ VEX NPD background data center """ def __init__(self): """ """ rc = Rc() path = rc.get('vnpi', 'backgroundbase') cbg.DataCenterBackground.__init__(self, path, name="VEX NPI background")
_db = None def _createdb(base=None): ''' Create database for VEX/NPI :keyword base: Base path of database. ''' global _db if base is None: rc = Rc() base = rc.get('vnpi', 'backgroundbase') _db = cbg.Database(base)
[docs]def isdb(): global _db if not _db is None: return True try: _createdb() except (OSError, IOError): _db = None if not _db is None: _db = None # Back to the original return True else: return False
[docs]def get_background_level(t0, t1, refresh=False, base=None): ''' Get VEX/IMA background level. :param t0: Time start. :param t1: Time end. :keyword refresh: If ``True``, a new database is created. :keyword base: Give base path of the dataset. If ``None``, the dataset path is given from ``.irfpyrc``. :returns: (``time array``, ``bg array``). >>> import datetime >>> t0 = datetime.datetime(2006, 12, 4) >>> t1 = datetime.datetime(2006, 12, 7) >>> bg = get_background_level(t0, t1) >>> print(len(bg[1])) 832 ''' if _db is None or refresh: _createdb(base=base) return _db.get_background_level(t0, t1)
import unittest import doctest
[docs]def doctests(): return unittest.TestSuite(( doctest.DocTestSuite(), ))
if __name__ == '__main__': unittest.main(defaultTest='doctests')