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
|
|
|
|
2020-10-24 16:50:17 +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.
|
2020-10-24 16:50:17 +02:00
|
|
|
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
|
|
|
"""
|
|
|
|
|
2020-10-24 16:50:17 +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:
|
2020-10-24 16:50:17 +02:00
|
|
|
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:
|
2020-10-03 18:30:52 +02:00
|
|
|
# Create black body
|
2020-10-24 16:50:17 +02:00
|
|
|
bb = self.__gb_factory(temp)
|
2020-10-03 18:30:52 +02:00
|
|
|
# Calculate emission
|
2020-10-24 16:50:17 +02:00
|
|
|
emission_sqty = SpectralQty(transmittance_sqty.wl, bb(transmittance_sqty.wl)) * (
|
|
|
|
-1 * transmittance_sqty + 1)
|
2020-10-05 20:45:30 +02:00
|
|
|
else:
|
2020-10-24 16:50:17 +02:00
|
|
|
emission_sqty = 0
|
2020-09-30 21:53:09 +02:00
|
|
|
|
2020-10-24 16:50:17 +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)
|
2020-10-03 18:30:52 +02:00
|
|
|
|
|
|
|
@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.
|
|
|
|
"""
|
2020-10-24 16:50:17 +02:00
|
|
|
mes = conf.check_file("transmittance")
|
|
|
|
if mes is not None:
|
|
|
|
return mes
|
2020-10-03 18:30:52 +02:00
|
|
|
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
|