Code clean up
This commit is contained in:
parent
00aa567eda
commit
e2f432137c
@ -110,7 +110,8 @@ class SpectralQty:
|
||||
all([math.isclose(x, y, rel_tol=1e-5) for x, y in zip(self.wl.value, other.wl.to(self.wl.unit).value)]) and\
|
||||
all([math.isclose(x, y, rel_tol=1e-5) for x, y in zip(self.qty.value, other.qty.to(self.qty.unit).value)])
|
||||
|
||||
def __add__(self, other: Union[int, float, u.Quantity, "SpectralQty", Callable]) -> "SpectralQty":
|
||||
def __add__(self, other: Union[int, float, u.Quantity, "SpectralQty", Callable[[u.Quantity], u.Quantity]]) ->\
|
||||
"SpectralQty":
|
||||
"""
|
||||
Calculate the sum with another object
|
||||
|
||||
@ -157,7 +158,8 @@ class SpectralQty:
|
||||
|
||||
__radd__ = __add__
|
||||
|
||||
def __sub__(self, other: Union[int, float, u.Quantity, "SpectralQty", Callable]) -> "SpectralQty":
|
||||
def __sub__(self, other: Union[int, float, u.Quantity, "SpectralQty", Callable[[u.Quantity], u.Quantity]]) ->\
|
||||
"SpectralQty":
|
||||
"""
|
||||
Calculate the difference to another object
|
||||
|
||||
@ -202,7 +204,8 @@ class SpectralQty:
|
||||
else:
|
||||
error("Units are not matching for substraction.")
|
||||
|
||||
def __mul__(self, other: Union[int, float, u.Quantity, "SpectralQty", Callable]) -> "SpectralQty":
|
||||
def __mul__(self, other: Union[int, float, u.Quantity, "SpectralQty", Callable[[u.Quantity], u.Quantity]]) ->\
|
||||
"SpectralQty":
|
||||
"""
|
||||
Calculate the product with another object
|
||||
|
||||
|
@ -75,13 +75,13 @@ class Configuration(object):
|
||||
|
||||
self.calc_metaoptions()
|
||||
|
||||
def parser(self, parent):
|
||||
def parser(self, parent: eT.Element):
|
||||
"""
|
||||
Parse a XML element tree to an Entry-tree
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent : ElementTree
|
||||
parent : xml.etree.ElementTree.Element
|
||||
The parent XML tree to be parsed
|
||||
|
||||
Returns
|
||||
|
@ -42,32 +42,32 @@ class AHotOpticalComponent(AOpticalComponent):
|
||||
if temp > 0 * u.K:
|
||||
# Create noise from black body model
|
||||
if isinstance(emissivity, SpectralQty):
|
||||
bb = self._gb_factory(temp)
|
||||
self._noise = SpectralQty(emissivity.wl, bb(emissivity.wl)) * emissivity
|
||||
bb = self.__gb_factory(temp)
|
||||
self.__noise = SpectralQty(emissivity.wl, bb(emissivity.wl)) * emissivity
|
||||
elif isinstance(emissivity, str):
|
||||
em = SpectralQty.fromFile(emissivity, u.nm, u.dimensionless_unscaled)
|
||||
bb = self._gb_factory(temp)
|
||||
self._noise = SpectralQty(em.wl, bb(em.wl)) * em
|
||||
bb = self.__gb_factory(temp)
|
||||
self.__noise = SpectralQty(em.wl, bb(em.wl)) * em
|
||||
else:
|
||||
bb = self._gb_factory(temp, emissivity)
|
||||
self._noise = bb
|
||||
bb = self.__gb_factory(temp, emissivity)
|
||||
self.__noise = bb
|
||||
else:
|
||||
self._noise = 0
|
||||
self.__noise = 0
|
||||
|
||||
def ownNoise(self) -> Union[SpectralQty, Callable, int, float]:
|
||||
def _ownNoise(self) -> Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]:
|
||||
"""
|
||||
Calculate the noise created by the optical component
|
||||
|
||||
Returns
|
||||
-------
|
||||
noise : Union[SpectralQty, Callable, int, float]
|
||||
noise : Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]
|
||||
The noise created by the optical component
|
||||
"""
|
||||
return self._noise
|
||||
return self.__noise
|
||||
|
||||
@staticmethod
|
||||
@u.quantity_input(temp=[u.Kelvin, u.Celsius])
|
||||
def _gb_factory(temp: u.Quantity, em: Union[int, float] = 1):
|
||||
def __gb_factory(temp: u.Quantity, em: Union[int, float] = 1):
|
||||
"""
|
||||
Factory for a grey body lambda-function.
|
||||
|
||||
|
@ -41,14 +41,14 @@ class AOpticalComponent(IRadiant):
|
||||
obstructor_emissivity : float
|
||||
Emissivity of the obstructing component.
|
||||
"""
|
||||
self._parent = parent
|
||||
self.__parent = parent
|
||||
if transreflectivity:
|
||||
self._transreflectivity = transreflectivity
|
||||
self.__transreflectivity = transreflectivity
|
||||
if noise:
|
||||
self._noise = noise
|
||||
self._obstruction = obstruction
|
||||
self._obstructor_temp = obstructor_temp
|
||||
self._obstructor_emissivity = obstructor_emissivity
|
||||
self.__noise = noise
|
||||
self.__obstruction = obstruction
|
||||
self.__obstructor_temp = obstructor_temp
|
||||
self.__obstructor_emissivity = obstructor_emissivity
|
||||
|
||||
def calcSignal(self) -> SpectralQty:
|
||||
"""
|
||||
@ -59,7 +59,7 @@ class AOpticalComponent(IRadiant):
|
||||
signal : SpectralQty
|
||||
The spectral flux density of the target's signal
|
||||
"""
|
||||
return self.propagate(self._parent.calcSignal()) * (1 - self._obstruction)
|
||||
return self._propagate(self.__parent.calcSignal()) * (1 - self.__obstruction)
|
||||
|
||||
def calcNoise(self) -> SpectralQty:
|
||||
"""
|
||||
@ -70,44 +70,44 @@ class AOpticalComponent(IRadiant):
|
||||
noise : SpectralQty
|
||||
The spectral radiance of the target's noise
|
||||
"""
|
||||
parent = self.propagate(self._parent.calcNoise())
|
||||
if self._obstructor_temp > 0 * u.K:
|
||||
bb = BlackBody(temperature=self._obstructor_temp, scale=1. * u.W / (u.m ** 2 * u.nm * u.sr))
|
||||
obstructor = bb(parent.wl) * self._obstructor_emissivity
|
||||
noise = parent * (1. - self._obstruction) + obstructor * self._obstruction
|
||||
parent = self._propagate(self.__parent.calcNoise())
|
||||
if self.__obstructor_temp > 0 * u.K:
|
||||
bb = BlackBody(temperature=self.__obstructor_temp, scale=1. * u.W / (u.m ** 2 * u.nm * u.sr))
|
||||
obstructor = bb(parent.wl) * self.__obstructor_emissivity
|
||||
noise = parent * (1. - self.__obstruction) + obstructor * self.__obstruction
|
||||
else:
|
||||
noise = parent * (1. - self._obstruction)
|
||||
return noise + self.ownNoise()
|
||||
noise = parent * (1. - self.__obstruction)
|
||||
return noise + self._ownNoise()
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
def _propagate(self, rad: SpectralQty) -> SpectralQty:
|
||||
"""
|
||||
Propagate incoming radiation through the optical component
|
||||
|
||||
Parameters
|
||||
----------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
The incoming radiation
|
||||
|
||||
Returns
|
||||
-------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
Manipulated incoming radiation
|
||||
"""
|
||||
if hasattr(self, "_transreflectivity"):
|
||||
return sqty * self._transreflectivity
|
||||
else:
|
||||
try:
|
||||
return rad * self.__transreflectivity
|
||||
except AttributeError:
|
||||
error("Transreflectivity not given. Method propagate() needs to be implemented.")
|
||||
|
||||
def ownNoise(self) -> Union[SpectralQty, Callable, int, float]:
|
||||
def _ownNoise(self) -> Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]:
|
||||
"""
|
||||
Calculate the noise created by the optical component
|
||||
|
||||
Returns
|
||||
-------
|
||||
noise : Union[SpectralQty, Callable, int, float]
|
||||
noise : Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]
|
||||
The noise created by the optical component
|
||||
"""
|
||||
if hasattr(self, "_noise"):
|
||||
return self._noise
|
||||
else:
|
||||
try:
|
||||
return self.__noise
|
||||
except AttributeError:
|
||||
error("noise not given. Method ownNoise() needs to be implemented.")
|
||||
|
@ -39,18 +39,18 @@ class BeamSplitter(AHotOpticalComponent):
|
||||
self._transmittance = SpectralQty.fromFile(transmittance, u.nm, u.dimensionless_unscaled)
|
||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
def _propagate(self, rad: SpectralQty) -> SpectralQty:
|
||||
"""
|
||||
Propagate incoming radiation through the optical component
|
||||
|
||||
Parameters
|
||||
----------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
The incoming radiation
|
||||
|
||||
Returns
|
||||
-------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
Manipulated incoming radiation
|
||||
"""
|
||||
return sqty * self._transmittance
|
||||
return rad * self._transmittance
|
||||
|
@ -17,7 +17,7 @@ class Filter(AHotOpticalComponent):
|
||||
H=dict(cwl=1630 * u.nm, bw=400 * u.nm), K=dict(cwl=2190 * u.nm, bw=600 * u.nm))
|
||||
|
||||
@u.quantity_input(temp=[u.Kelvin, u.Celsius], obstructor_temp=[u.Kelvin, u.Celsius])
|
||||
def __init__(self, parent: IRadiant, transmittance: Union[SpectralQty, Callable],
|
||||
def __init__(self, parent: IRadiant, transmittance: Union[SpectralQty, Callable[[u.Quantity], u.Quantity]],
|
||||
emissivity: Union[int, float, str] = 1, temp: u.Quantity = 0 * u.K,
|
||||
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
"""
|
||||
@ -159,10 +159,10 @@ class Filter(AHotOpticalComponent):
|
||||
filter : Filter
|
||||
The instantiated filter object.
|
||||
"""
|
||||
return cls(parent, cls._filter_factory(start, end), emissivity, temp,
|
||||
return cls(parent, cls.__filter_factory(start, end), emissivity, temp,
|
||||
obstruction, obstructor_temp, obstructor_emissivity)
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
def _propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
"""
|
||||
Propagate incoming radiation through the optical component
|
||||
|
||||
@ -179,8 +179,8 @@ class Filter(AHotOpticalComponent):
|
||||
return sqty * self._transmittance
|
||||
|
||||
@staticmethod
|
||||
# @u.quantity_input(start="length", end="length")
|
||||
def _filter_factory(start: u.Quantity, end: u.Quantity):
|
||||
@u.quantity_input(start="length", end="length")
|
||||
def __filter_factory(start: u.Quantity, end: u.Quantity):
|
||||
"""
|
||||
Create a infinite order bandpass filter
|
||||
|
||||
@ -193,7 +193,7 @@ class Filter(AHotOpticalComponent):
|
||||
|
||||
Returns
|
||||
-------
|
||||
lambda : Callable
|
||||
lambda : Callable[[u.Quantity], u.Quantity]
|
||||
The filter function
|
||||
"""
|
||||
return lambda wl: 1 * u.dimensionless_unscaled if start <= wl <= end else 0 * u.dimensionless_unscaled
|
||||
|
@ -39,18 +39,18 @@ class Lens(AHotOpticalComponent):
|
||||
self._transmittance = SpectralQty.fromFile(transmittance, u.nm, u.dimensionless_unscaled)
|
||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
def _propagate(self, rad: SpectralQty) -> SpectralQty:
|
||||
"""
|
||||
Propagate incoming radiation through the optical component
|
||||
|
||||
Parameters
|
||||
----------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
The incoming radiation
|
||||
|
||||
Returns
|
||||
-------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
Manipulated incoming radiation
|
||||
"""
|
||||
return sqty * self._transmittance
|
||||
return rad * self._transmittance
|
||||
|
@ -39,18 +39,18 @@ class Mirror(AHotOpticalComponent):
|
||||
self._reflectance = SpectralQty.fromFile(reflectance, u.nm, u.dimensionless_unscaled)
|
||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
def _propagate(self, rad: SpectralQty) -> SpectralQty:
|
||||
"""
|
||||
Propagate incoming radiation through the optical component
|
||||
|
||||
Parameters
|
||||
----------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
The incoming radiation
|
||||
|
||||
Returns
|
||||
-------
|
||||
sqty : SpectralQty
|
||||
rad : SpectralQty
|
||||
Manipulated incoming radiation
|
||||
"""
|
||||
return sqty * self._reflectance
|
||||
return rad * self._reflectance
|
||||
|
@ -9,7 +9,7 @@ class StrayLight(AOpticalComponent):
|
||||
A class to model additional stray light sources e.g. zodiacal light
|
||||
"""
|
||||
|
||||
def __init__(self, parent: IRadiant, emission: str = None):
|
||||
def __init__(self, parent: IRadiant, emission: str):
|
||||
"""
|
||||
Initialize a new stray light source
|
||||
|
||||
|
@ -20,7 +20,7 @@ class ATarget(IRadiant):
|
||||
sfd: SpectralQty
|
||||
The spectral flux density of the target
|
||||
"""
|
||||
self._sfd = sfd
|
||||
self.__sfd = sfd
|
||||
|
||||
def calcNoise(self) -> SpectralQty:
|
||||
"""
|
||||
@ -31,7 +31,7 @@ class ATarget(IRadiant):
|
||||
noise : SpectralQty
|
||||
The spectral radiance of the target's noise
|
||||
"""
|
||||
return SpectralQty(self._sfd.wl, np.repeat(0, len(self._sfd.wl)) << u.W / (u.m**2 * u.nm * u.sr))
|
||||
return SpectralQty(self.__sfd.wl, np.repeat(0, len(self.__sfd.wl)) << u.W / (u.m**2 * u.nm * u.sr))
|
||||
|
||||
def calcSignal(self) -> SpectralQty:
|
||||
"""
|
||||
@ -42,4 +42,4 @@ class ATarget(IRadiant):
|
||||
signal : SpectralQty
|
||||
The spectral flux density of the target's signal
|
||||
"""
|
||||
return self._sfd
|
||||
return self.__sfd
|
||||
|
@ -13,7 +13,7 @@ class HotOpticalComponent(AHotOpticalComponent):
|
||||
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
||||
|
||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
def _propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||
return sqty
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user