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

112 lines
4.4 KiB
Python
Raw Normal View History

2020-04-14 15:53:15 +02:00
from esbo_etc.classes.optical_component.AOpticalComponent import AOpticalComponent
2020-04-16 09:35:24 +02:00
from esbo_etc.classes.IRadiant import IRadiant
2020-04-14 15:53:15 +02:00
from esbo_etc.classes.SpectralQty import SpectralQty
from abc import abstractmethod
import astropy.units as u
from astropy.modeling.models import BlackBody
2020-04-14 19:58:23 +02:00
from typing import Union, Callable
2020-05-08 15:06:13 +02:00
from ..Entry import Entry
2020-04-14 15:53:15 +02:00
class AHotOpticalComponent(AOpticalComponent):
"""
Abstract super class for an optical component with thermal emission
"""
@abstractmethod
@u.quantity_input(wl_bins='length', temp=[u.Kelvin, u.Celsius], obstruction_temp=[u.Kelvin, u.Celsius])
2020-04-16 09:35:24 +02:00
def __init__(self, parent: IRadiant, emissivity: Union[SpectralQty, int, float, str], temp: u.Quantity,
2020-04-15 17:03:10 +02:00
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
2020-04-14 15:53:15 +02:00
"""
Initialize a new optical component with thermal emission
Parameters
----------
2020-04-16 09:35:24 +02:00
parent : IRadiant
2020-04-14 15:53:15 +02:00
The parent element of the optical component from which the electromagnetic radiation is received.
2020-04-15 17:03:10 +02:00
emissivity : Union[SpectralQty, int, float, str]
2020-04-14 15:53:15 +02:00
The spectral emissivity coefficient for the optical surface.
temp: Quantity in Kelvin / Celsius
Temperature of the optical component
obstruction : float
The additional obstruction factor of the optical component. 0 means the component is not obstructed, 1
denotes a completely obstructed component with therefore no incoming flux. It is important to note, that
the obstruction factor reflects the obstruction of the optical component additionally to the obstruction
factors of the prior elements in the beam.
obstructor_temp : Quantity in Kelvin / Celsius
Temperature of the obstructing component.
obstructor_emissivity : float
Emissivity of the obstructing component.
2020-04-14 15:53:15 +02:00
"""
# Initialize super class
super().__init__(parent, obstruction=obstruction, obstructor_temp=obstructor_temp,
obstructor_emissivity=obstructor_emissivity)
2020-04-14 15:53:15 +02:00
if temp > 0 * u.K:
# Create noise from black body model
2020-04-14 19:58:23 +02:00
if isinstance(emissivity, SpectralQty):
2020-04-16 13:04:21 +02:00
bb = self.__gb_factory(temp)
self.__noise = SpectralQty(emissivity.wl, bb(emissivity.wl)) * emissivity
2020-04-15 17:03:10 +02:00
elif isinstance(emissivity, str):
2020-04-22 10:36:27 +02:00
try:
em = float(emissivity)
bb = self.__gb_factory(temp, em)
self.__noise = bb
except ValueError:
em = SpectralQty.fromFile(emissivity, u.nm, u.dimensionless_unscaled)
bb = self.__gb_factory(temp)
self.__noise = SpectralQty(em.wl, bb(em.wl)) * em
2020-04-14 19:58:23 +02:00
else:
2020-04-16 13:04:21 +02:00
bb = self.__gb_factory(temp, emissivity)
self.__noise = bb
2020-04-14 15:53:15 +02:00
else:
2020-04-16 13:04:21 +02:00
self.__noise = 0
2020-04-14 15:53:15 +02:00
2020-04-16 13:04:21 +02:00
def _ownNoise(self) -> Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]:
2020-04-14 15:53:15 +02:00
"""
Calculate the noise created by the optical component
Returns
-------
2020-04-16 13:04:21 +02:00
noise : Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]
2020-04-14 15:53:15 +02:00
The noise created by the optical component
"""
2020-04-16 13:04:21 +02:00
return self.__noise
@staticmethod
@u.quantity_input(temp=[u.Kelvin, u.Celsius])
2020-04-16 13:04:21 +02:00
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-05-08 15:06:13 +02:00
@staticmethod
@abstractmethod
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.
"""
pass