ESBO-ETC/esbo_etc/classes/optical_component/Atmosphere.py

103 lines
3.7 KiB
Python
Raw Permalink Normal View History

2020-04-16 09:35:24 +02:00
from .AOpticalComponent import AOpticalComponent
from ..IRadiant import IRadiant
from ..SpectralQty import SpectralQty
2020-05-08 15:06:13 +02:00
from ..Entry import Entry
2020-04-14 13:12:33 +02:00
import astropy.units as u
2020-09-30 21:53:09 +02:00
from astropy.modeling.models import BlackBody
2020-05-08 15:06:13 +02:00
from typing import Union
2020-04-14 13:12:33 +02:00
class Atmosphere(AOpticalComponent):
"""
A class to model the atmosphere including the atmosphere's spectral transmittance and emission.
"""
2020-04-16 09:35:24 +02:00
@u.quantity_input(temp=[u.Kelvin, u.Celsius])
def __init__(self, parent: IRadiant, transmittance: Union[str, float, SpectralQty], emission: str = None,
temp: u.Quantity = None):
2020-04-14 13:12:33 +02:00
"""
Initialize a new atmosphere model
2020-09-30 21:53:09 +02:00
Parameters
----------
parent : IRadiant
The parent element of the atmosphere from which the electromagnetic radiation is received.
transmittance : str, float, SpectralQty
2020-09-30 21:53:09 +02:00
Path to the file containing the spectral transmittance-coefficients of the atmosphere.
The format of the file will be guessed by `astropy.io.ascii.read()`.
emission : str
Path to the file containing the spectral radiance of the atmosphere.
The format of the file will be guessed by `astropy.io.ascii.read()`.
2020-10-02 15:10:34 +02:00
temp : u.Quantity
The atmospheric temperature for the atmosphere's black body radiation.
2020-09-30 21:53:09 +02:00
"""
# Read the transmittance
if isinstance(transmittance, str):
transmittance_sqty = SpectralQty.fromFile(transmittance, wl_unit_default=u.nm,
qty_unit_default=u.dimensionless_unscaled)
2020-09-30 21:53:09 +02:00
else:
transmittance_sqty = transmittance
if emission:
# Read the emission
emission_sqty = SpectralQty.fromFile(emission, wl_unit_default=u.nm,
qty_unit_default=u.W / (u.m ** 2 * u.nm * u.sr))
elif temp is not None:
# Create black body
bb = self.__gb_factory(temp)
# Calculate emission
emission_sqty = SpectralQty(transmittance_sqty.wl, bb(transmittance_sqty.wl)) * (
-1 * transmittance_sqty + 1)
2020-10-05 20:45:30 +02:00
else:
emission_sqty = 0
2020-09-30 21:53:09 +02:00
super().__init__(parent=parent, transreflectivity=transmittance_sqty, noise=emission_sqty)
2020-09-30 21:53:09 +02:00
@staticmethod
@u.quantity_input(temp=[u.Kelvin, u.Celsius])
def __gb_factory(temp: u.Quantity, em: Union[int, float] = 1):
"""
Factory for a grey body lambda-function.
Parameters
----------
temp : Quantity in Kelvin / Celsius
The temperature fo the grey body.
em : Union[int, float]
Emissivity of the the grey body
Returns
-------
bb : Callable
The lambda function for the grey body.
"""
bb = BlackBody(temperature=temp, scale=em * u.W / (u.m ** 2 * u.nm * u.sr))
return lambda wl: bb(wl)
@staticmethod
def check_config(conf: Entry) -> Union[None, str]:
"""
Check the configuration for this class
Parameters
----------
conf : Entry
The configuration entry to be checked.
Returns
-------
mes : Union[None, str]
The error message of the check. This will be None if the check was successful.
"""
mes = conf.check_file("transmittance")
if mes is not None:
return mes
if hasattr(conf, "emission"):
mes = conf.check_file("emission")
if mes is not None:
return mes
elif hasattr(conf, "temp"):
mes = conf.check_quantity("temp", u.K)
if mes is not None:
return mes