diff --git a/esbo_etc/classes/SpectralQty.py b/esbo_etc/classes/SpectralQty.py index 07e8c8d..2102244 100644 --- a/esbo_etc/classes/SpectralQty.py +++ b/esbo_etc/classes/SpectralQty.py @@ -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 diff --git a/esbo_etc/classes/config.py b/esbo_etc/classes/config.py index 7444460..3bdb4e8 100644 --- a/esbo_etc/classes/config.py +++ b/esbo_etc/classes/config.py @@ -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 diff --git a/esbo_etc/classes/optical_component/AHotOpticalComponent.py b/esbo_etc/classes/optical_component/AHotOpticalComponent.py index 033bf3c..f52e294 100644 --- a/esbo_etc/classes/optical_component/AHotOpticalComponent.py +++ b/esbo_etc/classes/optical_component/AHotOpticalComponent.py @@ -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. diff --git a/esbo_etc/classes/optical_component/AOpticalComponent.py b/esbo_etc/classes/optical_component/AOpticalComponent.py index 9874428..d7f64a5 100644 --- a/esbo_etc/classes/optical_component/AOpticalComponent.py +++ b/esbo_etc/classes/optical_component/AOpticalComponent.py @@ -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.") diff --git a/esbo_etc/classes/optical_component/BeamSplitter.py b/esbo_etc/classes/optical_component/BeamSplitter.py index 4ee9269..bd9df0c 100644 --- a/esbo_etc/classes/optical_component/BeamSplitter.py +++ b/esbo_etc/classes/optical_component/BeamSplitter.py @@ -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 diff --git a/esbo_etc/classes/optical_component/Filter.py b/esbo_etc/classes/optical_component/Filter.py index 0576b41..925357d 100644 --- a/esbo_etc/classes/optical_component/Filter.py +++ b/esbo_etc/classes/optical_component/Filter.py @@ -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 diff --git a/esbo_etc/classes/optical_component/Lens.py b/esbo_etc/classes/optical_component/Lens.py index e76c688..944072b 100644 --- a/esbo_etc/classes/optical_component/Lens.py +++ b/esbo_etc/classes/optical_component/Lens.py @@ -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 diff --git a/esbo_etc/classes/optical_component/Mirror.py b/esbo_etc/classes/optical_component/Mirror.py index e931635..90d723c 100644 --- a/esbo_etc/classes/optical_component/Mirror.py +++ b/esbo_etc/classes/optical_component/Mirror.py @@ -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 diff --git a/esbo_etc/classes/optical_component/StrayLight.py b/esbo_etc/classes/optical_component/StrayLight.py index b6cd36b..82a290e 100644 --- a/esbo_etc/classes/optical_component/StrayLight.py +++ b/esbo_etc/classes/optical_component/StrayLight.py @@ -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 diff --git a/esbo_etc/classes/target/ATarget.py b/esbo_etc/classes/target/ATarget.py index da2c451..73f0191 100644 --- a/esbo_etc/classes/target/ATarget.py +++ b/esbo_etc/classes/target/ATarget.py @@ -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 diff --git a/tests/optical_component/test_AHotOpticalComponent.py b/tests/optical_component/test_AHotOpticalComponent.py index 1d45c84..b7e3ec4 100644 --- a/tests/optical_component/test_AHotOpticalComponent.py +++ b/tests/optical_component/test_AHotOpticalComponent.py @@ -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