Source code for irfpy.mima.background
''' MEX/IMA background proxy module
It provides a getter of background proxy.
The best-practice is to use :class:`DataCenterMimaBackground` class as follows.
>>> from irfpy.mima import background
>>> dc = background.DataCenterMimaBackground()
>>> import datetime
>>> tobs, (back, total) = dc.nearest(datetime.datetime(2010, 1, 9, 20, 10))
>>> print(tobs) # Observed time nearest to the given time (2010-01-09:20:10
2010-01-09 20:09:40.355900
>>> print(back) # Background count
3.45
>>> print(total) # Total count
68115.0
'''
from irfpy.util.irfpyrc import Rc
import irfpy.imacommon.background as cbg
import logging as _logging
_logger = _logging.getLogger(__name__)
[docs]class DataCenterMimaBackground(cbg.DataCenterBackground):
""" MEX IMA background data center
"""
def __init__(self):
"""
"""
rc = Rc()
path = rc.get('mima', 'backgroundbase')
cbg.DataCenterBackground.__init__(self, path, name="MEX IMA background")
_db = None
def _createdb(base=None):
''' Create database for MEX/IMA
:keyword base: Base path of database.
'''
global _db
if base is None:
rc = Rc()
base = rc.get('mima', 'backgroundbase')
_db = cbg.Database(base)
[docs]def isdb():
global _db
if _db is not None:
return True
try:
_createdb()
except (OSError, IOError):
_db = None
if _db is not None:
_db = None # Back to the original
return True
else:
return False
[docs]def get_background_level(t0, t1, refresh=False, base=None):
''' Get MEX 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) # doctest: +SKIP
>>> print(len(bg[1])) # doctest: +SKIP
294
'''
import warnings as _warnings
warn = ('irfpy.mima.background.get_background_level() method was deprecated.\n' +
'Use irfpy.mima.background.DataCenterMimaBackground().\n' +
'Refer to https://irfpy.irf.se/projects/aspera/')
_warnings.warn(warn, DeprecationWarning)
if _db is None or refresh:
_createdb(base=base)
return _db.get_background_level(t0, t1)