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.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)])
|
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
|
Calculate the sum with another object
|
||||||
|
|
||||||
@ -157,7 +158,8 @@ class SpectralQty:
|
|||||||
|
|
||||||
__radd__ = __add__
|
__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
|
Calculate the difference to another object
|
||||||
|
|
||||||
@ -202,7 +204,8 @@ class SpectralQty:
|
|||||||
else:
|
else:
|
||||||
error("Units are not matching for substraction.")
|
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
|
Calculate the product with another object
|
||||||
|
|
||||||
|
@ -75,13 +75,13 @@ class Configuration(object):
|
|||||||
|
|
||||||
self.calc_metaoptions()
|
self.calc_metaoptions()
|
||||||
|
|
||||||
def parser(self, parent):
|
def parser(self, parent: eT.Element):
|
||||||
"""
|
"""
|
||||||
Parse a XML element tree to an Entry-tree
|
Parse a XML element tree to an Entry-tree
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
parent : ElementTree
|
parent : xml.etree.ElementTree.Element
|
||||||
The parent XML tree to be parsed
|
The parent XML tree to be parsed
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
|
@ -42,32 +42,32 @@ class AHotOpticalComponent(AOpticalComponent):
|
|||||||
if temp > 0 * u.K:
|
if temp > 0 * u.K:
|
||||||
# Create noise from black body model
|
# Create noise from black body model
|
||||||
if isinstance(emissivity, SpectralQty):
|
if isinstance(emissivity, SpectralQty):
|
||||||
bb = self._gb_factory(temp)
|
bb = self.__gb_factory(temp)
|
||||||
self._noise = SpectralQty(emissivity.wl, bb(emissivity.wl)) * emissivity
|
self.__noise = SpectralQty(emissivity.wl, bb(emissivity.wl)) * emissivity
|
||||||
elif isinstance(emissivity, str):
|
elif isinstance(emissivity, str):
|
||||||
em = SpectralQty.fromFile(emissivity, u.nm, u.dimensionless_unscaled)
|
em = SpectralQty.fromFile(emissivity, u.nm, u.dimensionless_unscaled)
|
||||||
bb = self._gb_factory(temp)
|
bb = self.__gb_factory(temp)
|
||||||
self._noise = SpectralQty(em.wl, bb(em.wl)) * em
|
self.__noise = SpectralQty(em.wl, bb(em.wl)) * em
|
||||||
else:
|
else:
|
||||||
bb = self._gb_factory(temp, emissivity)
|
bb = self.__gb_factory(temp, emissivity)
|
||||||
self._noise = bb
|
self.__noise = bb
|
||||||
else:
|
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
|
Calculate the noise created by the optical component
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
noise : Union[SpectralQty, Callable, int, float]
|
noise : Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]
|
||||||
The noise created by the optical component
|
The noise created by the optical component
|
||||||
"""
|
"""
|
||||||
return self._noise
|
return self.__noise
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@u.quantity_input(temp=[u.Kelvin, u.Celsius])
|
@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.
|
Factory for a grey body lambda-function.
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ class AOpticalComponent(IRadiant):
|
|||||||
obstructor_emissivity : float
|
obstructor_emissivity : float
|
||||||
Emissivity of the obstructing component.
|
Emissivity of the obstructing component.
|
||||||
"""
|
"""
|
||||||
self._parent = parent
|
self.__parent = parent
|
||||||
if transreflectivity:
|
if transreflectivity:
|
||||||
self._transreflectivity = transreflectivity
|
self.__transreflectivity = transreflectivity
|
||||||
if noise:
|
if noise:
|
||||||
self._noise = noise
|
self.__noise = noise
|
||||||
self._obstruction = obstruction
|
self.__obstruction = obstruction
|
||||||
self._obstructor_temp = obstructor_temp
|
self.__obstructor_temp = obstructor_temp
|
||||||
self._obstructor_emissivity = obstructor_emissivity
|
self.__obstructor_emissivity = obstructor_emissivity
|
||||||
|
|
||||||
def calcSignal(self) -> SpectralQty:
|
def calcSignal(self) -> SpectralQty:
|
||||||
"""
|
"""
|
||||||
@ -59,7 +59,7 @@ class AOpticalComponent(IRadiant):
|
|||||||
signal : SpectralQty
|
signal : SpectralQty
|
||||||
The spectral flux density of the target's signal
|
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:
|
def calcNoise(self) -> SpectralQty:
|
||||||
"""
|
"""
|
||||||
@ -70,44 +70,44 @@ class AOpticalComponent(IRadiant):
|
|||||||
noise : SpectralQty
|
noise : SpectralQty
|
||||||
The spectral radiance of the target's noise
|
The spectral radiance of the target's noise
|
||||||
"""
|
"""
|
||||||
parent = self.propagate(self._parent.calcNoise())
|
parent = self._propagate(self.__parent.calcNoise())
|
||||||
if self._obstructor_temp > 0 * u.K:
|
if self.__obstructor_temp > 0 * u.K:
|
||||||
bb = BlackBody(temperature=self._obstructor_temp, scale=1. * u.W / (u.m ** 2 * u.nm * u.sr))
|
bb = BlackBody(temperature=self.__obstructor_temp, scale=1. * u.W / (u.m ** 2 * u.nm * u.sr))
|
||||||
obstructor = bb(parent.wl) * self._obstructor_emissivity
|
obstructor = bb(parent.wl) * self.__obstructor_emissivity
|
||||||
noise = parent * (1. - self._obstruction) + obstructor * self._obstruction
|
noise = parent * (1. - self.__obstruction) + obstructor * self.__obstruction
|
||||||
else:
|
else:
|
||||||
noise = parent * (1. - self._obstruction)
|
noise = parent * (1. - self.__obstruction)
|
||||||
return noise + self.ownNoise()
|
return noise + self._ownNoise()
|
||||||
|
|
||||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
def _propagate(self, rad: SpectralQty) -> SpectralQty:
|
||||||
"""
|
"""
|
||||||
Propagate incoming radiation through the optical component
|
Propagate incoming radiation through the optical component
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
The incoming radiation
|
The incoming radiation
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
Manipulated incoming radiation
|
Manipulated incoming radiation
|
||||||
"""
|
"""
|
||||||
if hasattr(self, "_transreflectivity"):
|
try:
|
||||||
return sqty * self._transreflectivity
|
return rad * self.__transreflectivity
|
||||||
else:
|
except AttributeError:
|
||||||
error("Transreflectivity not given. Method propagate() needs to be implemented.")
|
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
|
Calculate the noise created by the optical component
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
noise : Union[SpectralQty, Callable, int, float]
|
noise : Union[SpectralQty, Callable[[u.Quantity], u.Quantity], int, float]
|
||||||
The noise created by the optical component
|
The noise created by the optical component
|
||||||
"""
|
"""
|
||||||
if hasattr(self, "_noise"):
|
try:
|
||||||
return self._noise
|
return self.__noise
|
||||||
else:
|
except AttributeError:
|
||||||
error("noise not given. Method ownNoise() needs to be implemented.")
|
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)
|
self._transmittance = SpectralQty.fromFile(transmittance, u.nm, u.dimensionless_unscaled)
|
||||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
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
|
Propagate incoming radiation through the optical component
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
The incoming radiation
|
The incoming radiation
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
Manipulated incoming radiation
|
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))
|
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])
|
@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,
|
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):
|
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||||
"""
|
"""
|
||||||
@ -159,10 +159,10 @@ class Filter(AHotOpticalComponent):
|
|||||||
filter : Filter
|
filter : Filter
|
||||||
The instantiated filter object.
|
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)
|
obstruction, obstructor_temp, obstructor_emissivity)
|
||||||
|
|
||||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
def _propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||||
"""
|
"""
|
||||||
Propagate incoming radiation through the optical component
|
Propagate incoming radiation through the optical component
|
||||||
|
|
||||||
@ -179,8 +179,8 @@ class Filter(AHotOpticalComponent):
|
|||||||
return sqty * self._transmittance
|
return sqty * self._transmittance
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
# @u.quantity_input(start="length", end="length")
|
@u.quantity_input(start="length", end="length")
|
||||||
def _filter_factory(start: u.Quantity, end: u.Quantity):
|
def __filter_factory(start: u.Quantity, end: u.Quantity):
|
||||||
"""
|
"""
|
||||||
Create a infinite order bandpass filter
|
Create a infinite order bandpass filter
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ class Filter(AHotOpticalComponent):
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
lambda : Callable
|
lambda : Callable[[u.Quantity], u.Quantity]
|
||||||
The filter function
|
The filter function
|
||||||
"""
|
"""
|
||||||
return lambda wl: 1 * u.dimensionless_unscaled if start <= wl <= end else 0 * u.dimensionless_unscaled
|
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)
|
self._transmittance = SpectralQty.fromFile(transmittance, u.nm, u.dimensionless_unscaled)
|
||||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
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
|
Propagate incoming radiation through the optical component
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
The incoming radiation
|
The incoming radiation
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
Manipulated incoming radiation
|
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)
|
self._reflectance = SpectralQty.fromFile(reflectance, u.nm, u.dimensionless_unscaled)
|
||||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
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
|
Propagate incoming radiation through the optical component
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
The incoming radiation
|
The incoming radiation
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
sqty : SpectralQty
|
rad : SpectralQty
|
||||||
Manipulated incoming radiation
|
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
|
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
|
Initialize a new stray light source
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class ATarget(IRadiant):
|
|||||||
sfd: SpectralQty
|
sfd: SpectralQty
|
||||||
The spectral flux density of the target
|
The spectral flux density of the target
|
||||||
"""
|
"""
|
||||||
self._sfd = sfd
|
self.__sfd = sfd
|
||||||
|
|
||||||
def calcNoise(self) -> SpectralQty:
|
def calcNoise(self) -> SpectralQty:
|
||||||
"""
|
"""
|
||||||
@ -31,7 +31,7 @@ class ATarget(IRadiant):
|
|||||||
noise : SpectralQty
|
noise : SpectralQty
|
||||||
The spectral radiance of the target's noise
|
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:
|
def calcSignal(self) -> SpectralQty:
|
||||||
"""
|
"""
|
||||||
@ -42,4 +42,4 @@ class ATarget(IRadiant):
|
|||||||
signal : SpectralQty
|
signal : SpectralQty
|
||||||
The spectral flux density of the target's signal
|
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):
|
obstruction: float = 0, obstructor_temp: u.Quantity = 0 * u.K, obstructor_emissivity: float = 1):
|
||||||
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
super().__init__(parent, emissivity, temp, obstruction, obstructor_temp, obstructor_emissivity)
|
||||||
|
|
||||||
def propagate(self, sqty: SpectralQty) -> SpectralQty:
|
def _propagate(self, sqty: SpectralQty) -> SpectralQty:
|
||||||
return sqty
|
return sqty
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user