Caching of ATRAN requests added
This commit is contained in:
parent
60262b384c
commit
aa8492cb5e
@ -1,5 +1,6 @@
|
|||||||
import esbo_etc as eetc
|
import esbo_etc as eetc
|
||||||
from esbo_etc.lib.logger import logger
|
from esbo_etc.lib.logger import logger
|
||||||
|
from esbo_etc.lib.cache import cache
|
||||||
import logging as log
|
import logging as log
|
||||||
import astropy.units as u
|
import astropy.units as u
|
||||||
|
|
||||||
@ -65,4 +66,5 @@ class esbo_etc:
|
|||||||
res = detector.getSNR(self.conf.common.exposure_time())
|
res = detector.getSNR(self.conf.common.exposure_time())
|
||||||
elif hasattr(self.conf.common, "snr"):
|
elif hasattr(self.conf.common, "snr"):
|
||||||
res = detector.getExpTime(self.conf.common.snr())
|
res = detector.getExpTime(self.conf.common.snr())
|
||||||
|
cache.close()
|
||||||
return res
|
return res
|
||||||
|
@ -3,9 +3,11 @@ from ..IRadiant import IRadiant
|
|||||||
from ..SpectralQty import SpectralQty
|
from ..SpectralQty import SpectralQty
|
||||||
from ..Entry import Entry
|
from ..Entry import Entry
|
||||||
from ...lib.logger import logger
|
from ...lib.logger import logger
|
||||||
|
from ...lib.cache import cache
|
||||||
import astropy.units as u
|
import astropy.units as u
|
||||||
from astropy.io import ascii
|
from astropy.io import ascii
|
||||||
from astropy.modeling.models import BlackBody
|
from astropy.modeling.models import BlackBody
|
||||||
|
from astropy.table import QTable
|
||||||
from typing import Union
|
from typing import Union
|
||||||
import re
|
import re
|
||||||
import requests as req
|
import requests as req
|
||||||
@ -58,7 +60,8 @@ class Atmosphere(AOpticalComponent):
|
|||||||
|
|
||||||
args = dict()
|
args = dict()
|
||||||
if "atran" in kwargs:
|
if "atran" in kwargs:
|
||||||
args = self._fromATRAN(**{x: kwargs[x] for x in kwargs.keys() if x not in ["emission", "temp"]})
|
data = self.__parse_ATRAN(kwargs["atran"])
|
||||||
|
args = self._fromATRAN(parent=kwargs["parent"], atran=data)
|
||||||
elif "altitude" in kwargs:
|
elif "altitude" in kwargs:
|
||||||
logger.info("Requesting ATRAN transmission profile.")
|
logger.info("Requesting ATRAN transmission profile.")
|
||||||
data = self.__call_ATRAN(**{x: kwargs[x] for x in kwargs.keys() if x not in ["parent", "temp"]})
|
data = self.__call_ATRAN(**{x: kwargs[x] for x in kwargs.keys() if x not in ["parent", "temp"]})
|
||||||
@ -103,7 +106,7 @@ class Atmosphere(AOpticalComponent):
|
|||||||
qty_unit_default=u.dimensionless_unscaled)
|
qty_unit_default=u.dimensionless_unscaled)
|
||||||
return {"parent": parent, "transmittance": transmittance}
|
return {"parent": parent, "transmittance": transmittance}
|
||||||
|
|
||||||
def _fromATRAN(self, parent: IRadiant, atran: str):
|
def _fromATRAN(self, parent: IRadiant, atran: QTable):
|
||||||
"""
|
"""
|
||||||
Initialize a new atmosphere model from an ATRAN output file
|
Initialize a new atmosphere model from an ATRAN output file
|
||||||
|
|
||||||
@ -111,22 +114,21 @@ class Atmosphere(AOpticalComponent):
|
|||||||
----------
|
----------
|
||||||
parent : IRadiant
|
parent : IRadiant
|
||||||
The parent element of the atmosphere from which the electromagnetic radiation is received.
|
The parent element of the atmosphere from which the electromagnetic radiation is received.
|
||||||
atran : str
|
atran : QTable
|
||||||
Path to the ATRAN output file containing the spectral transmittance-coefficients of the atmosphere.
|
QTable containing the atmospheric transmission coefficients.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
args : dict
|
args : dict
|
||||||
The arguments for the class instantiation.
|
The arguments for the class instantiation.
|
||||||
"""
|
"""
|
||||||
# Read the file
|
|
||||||
data = self.__parse_ATRAN(atran)
|
|
||||||
# Create spectral quantity
|
# Create spectral quantity
|
||||||
transmittance = SpectralQty(data["col2"].quantity, data["col3"].quantity)
|
transmittance = SpectralQty(atran["col2"].quantity, atran["col3"].quantity)
|
||||||
return {"parent": parent, "transmittance": transmittance}
|
return {"parent": parent, "transmittance": transmittance}
|
||||||
|
|
||||||
@u.quantity_input(altitude="length", latitude="angle", water_vapor="length", zenith_angle="angle", wl_min="length",
|
@u.quantity_input(altitude="length", latitude="angle", water_vapor="length", zenith_angle="angle", wl_min="length",
|
||||||
wl_max="length")
|
wl_max="length")
|
||||||
|
@cache
|
||||||
def __call_ATRAN(self, altitude: u.Quantity, wl_min: u.Quantity, wl_max: u.Quantity,
|
def __call_ATRAN(self, altitude: u.Quantity, wl_min: u.Quantity, wl_max: u.Quantity,
|
||||||
latitude: u.Quantity = 39 * u.degree, water_vapor: u.Quantity = 0 * u.um, n_layers: int = 2,
|
latitude: u.Quantity = 39 * u.degree, water_vapor: u.Quantity = 0 * u.um, n_layers: int = 2,
|
||||||
zenith_angle: u.Quantity = 0 * u.degree, resolution: int = 0):
|
zenith_angle: u.Quantity = 0 * u.degree, resolution: int = 0):
|
||||||
@ -154,7 +156,7 @@ class Atmosphere(AOpticalComponent):
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
data : str
|
data : QTable
|
||||||
The ATRAN computation results
|
The ATRAN computation results
|
||||||
"""
|
"""
|
||||||
# Select closest latitude from ATRAN options
|
# Select closest latitude from ATRAN options
|
||||||
@ -200,7 +202,7 @@ class Atmosphere(AOpticalComponent):
|
|||||||
# Check if result is empty
|
# Check if result is empty
|
||||||
if data == "":
|
if data == "":
|
||||||
logger.error("Error: Request returned empty response.")
|
logger.error("Error: Request returned empty response.")
|
||||||
return data
|
return self.__parse_ATRAN(data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __parse_ATRAN(table: str):
|
def __parse_ATRAN(table: str):
|
||||||
|
4
esbo_etc/lib/cache.py
Normal file
4
esbo_etc/lib/cache.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import percache
|
||||||
|
|
||||||
|
cache = percache.Cache("cache")
|
||||||
|
cache.clear(3600 * 24)
|
@ -8,4 +8,5 @@ pyfiglet~=0.8.post1
|
|||||||
|
|
||||||
Sphinx~=3.1.2
|
Sphinx~=3.1.2
|
||||||
sphinx-rtd-theme~=0.5.0
|
sphinx-rtd-theme~=0.5.0
|
||||||
requests~=2.24.0
|
requests~=2.24.0
|
||||||
|
percache~=0.4.4
|
Loading…
x
Reference in New Issue
Block a user