From 62013e323eed5eb060ea12b43a3245e83d631f7a Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Tue, 28 Apr 2020 17:21:26 +0200 Subject: [PATCH] Propagate target size. --- esbo_etc/classes/IRadiant.py | 5 ++++- .../optical_component/AOpticalComponent.py | 10 ++++++---- esbo_etc/classes/target/ATarget.py | 16 ++++++++++++---- esbo_etc/classes/target/BlackBodyTarget.py | 6 ++++-- esbo_etc/classes/target/FileTarget.py | 6 ++++-- .../optical_component/test_AOpticalComponent.py | 2 +- tests/optical_component/test_Atmosphere.py | 2 +- tests/optical_component/test_BeamSplitter.py | 2 +- tests/optical_component/test_Filter.py | 4 ++-- tests/optical_component/test_Lens.py | 2 +- tests/optical_component/test_Mirror.py | 2 +- tests/optical_component/test_StrayLight.py | 2 +- tests/target/test_BlackBodyTarget.py | 2 +- tests/target/test_FileTarget.py | 4 ++-- 14 files changed, 41 insertions(+), 24 deletions(-) diff --git a/esbo_etc/classes/IRadiant.py b/esbo_etc/classes/IRadiant.py index 8ebc2d0..a913f9c 100644 --- a/esbo_etc/classes/IRadiant.py +++ b/esbo_etc/classes/IRadiant.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod from .SpectralQty import SpectralQty +from typing import Tuple class IRadiant(ABC): @@ -8,7 +9,7 @@ class IRadiant(ABC): in the beam. """ @abstractmethod - def calcSignal(self) -> SpectralQty: + def calcSignal(self) -> Tuple[SpectralQty, str]: """ Calculate the signal coming from the component @@ -16,6 +17,8 @@ class IRadiant(ABC): ------- signal : SpectralQty The emitted, reflected or transmitted signal + size : str + The size of the target. """ pass diff --git a/esbo_etc/classes/optical_component/AOpticalComponent.py b/esbo_etc/classes/optical_component/AOpticalComponent.py index 82a9a18..3c8bd4c 100644 --- a/esbo_etc/classes/optical_component/AOpticalComponent.py +++ b/esbo_etc/classes/optical_component/AOpticalComponent.py @@ -4,7 +4,7 @@ from ...lib.helpers import error from abc import abstractmethod import astropy.units as u from astropy.modeling.models import BlackBody -from typing import Union, Callable +from typing import Union, Callable, Tuple from logging import info, debug @@ -51,7 +51,7 @@ class AOpticalComponent(IRadiant): self.__obstructor_temp = obstructor_temp self.__obstructor_emissivity = obstructor_emissivity - def calcSignal(self) -> SpectralQty: + def calcSignal(self) -> Tuple[SpectralQty, str]: """ Calculate the spectral flux density of the target's signal @@ -59,12 +59,14 @@ class AOpticalComponent(IRadiant): ------- signal : SpectralQty The spectral flux density of the target's signal + size : str + The size of the target. """ - signal = self.__parent.calcSignal() + signal, size = self.__parent.calcSignal() info("Calculating signal for class '" + self.__class__.__name__ + "'.") signal = self._propagate(signal) * (1 - self.__obstruction) debug(signal) - return signal + return signal, size def calcBackground(self) -> SpectralQty: """ diff --git a/esbo_etc/classes/target/ATarget.py b/esbo_etc/classes/target/ATarget.py index ed80637..adef083 100644 --- a/esbo_etc/classes/target/ATarget.py +++ b/esbo_etc/classes/target/ATarget.py @@ -4,6 +4,7 @@ from ..SpectralQty import SpectralQty import astropy.units as u import numpy as np from logging import info, debug +from typing import Tuple class ATarget(IRadiant): @@ -13,17 +14,22 @@ class ATarget(IRadiant): @abstractmethod @u.quantity_input(wl_bins="length") - def __init__(self, sfd: SpectralQty, wl_bins: u.Quantity): + def __init__(self, sfd: SpectralQty, wl_bins: u.Quantity, size: str = "Point"): """ Initialize a new target Parameters ---------- - sfd: SpectralQty + sfd : SpectralQty The spectral flux density of the target + wl_bins : length-Quantity + The bins to be used for evaluating spectral quantities. + size : str + The size of the target. Can be either point or extended. """ self.__sfd = sfd self.__wl_bins = wl_bins + self.__size = size def calcBackground(self) -> SpectralQty: """ @@ -39,7 +45,7 @@ class ATarget(IRadiant): debug(background) return background - def calcSignal(self) -> SpectralQty: + def calcSignal(self) -> Tuple[SpectralQty, str]: """ Calculate the spectral flux density of the target's signal @@ -47,7 +53,9 @@ class ATarget(IRadiant): ------- signal : SpectralQty The spectral flux density of the target's signal + size : str + The size of the target. """ info("Calculating Signal for class '" + self.__class__.__name__ + "'.") debug(self.__sfd) - return self.__sfd + return self.__sfd, self.__size diff --git a/esbo_etc/classes/target/BlackBodyTarget.py b/esbo_etc/classes/target/BlackBodyTarget.py index 44be86d..2191999 100644 --- a/esbo_etc/classes/target/BlackBodyTarget.py +++ b/esbo_etc/classes/target/BlackBodyTarget.py @@ -24,7 +24,7 @@ class BlackBodyTarget(ATarget): @u.quantity_input(wl_bins='length', temp=[u.Kelvin, u.Celsius], mag=u.mag) def __init__(self, wl_bins: u.Quantity, temp: u.Quantity = 5778 * u.K, - mag: u.Quantity = 0 * u.mag, band: str = "V"): + mag: u.Quantity = 0 * u.mag, band: str = "V", size: str = "Point"): """ Initialize a new black body point source @@ -38,6 +38,8 @@ class BlackBodyTarget(ATarget): Desired apparent magnitude of the point source band : str Band used for fitting the planck curve to a star of 0th magnitude. Can be one of [U, B, V, R, I, J, H, K]. + size : str + The size of the target. Can be either point or extended Returns ------- @@ -54,4 +56,4 @@ class BlackBodyTarget(ATarget): sfd = bb(wl_bins) * factor * 10 ** (- 2 / 5 * mag / u.mag) # Initialize super class - super().__init__(SpectralQty(wl_bins, sfd), wl_bins) + super().__init__(SpectralQty(wl_bins, sfd), wl_bins, size) diff --git a/esbo_etc/classes/target/FileTarget.py b/esbo_etc/classes/target/FileTarget.py index 3d4c00f..21e375c 100644 --- a/esbo_etc/classes/target/FileTarget.py +++ b/esbo_etc/classes/target/FileTarget.py @@ -9,7 +9,7 @@ class FileTarget(ATarget): """ @u.quantity_input(wl_bins="length") - def __init__(self, file: str, wl_bins: u.Quantity): + def __init__(self, file: str, wl_bins: u.Quantity, size: str = "Point"): """ Initialize a new target from a file containing the spectral flux density values @@ -22,8 +22,10 @@ class FileTarget(ATarget): will be read from the column headers or otherwise assumed to be *nm* and *W / m^2 / nm*. wl_bins : length-Quantity Wavelengths used for binning + size : str + The size of the target. Can be either point or extended. """ # Create spectral quantity from file sfd = SpectralQty.fromFile(file, u.nm, u.W / (u.m ** 2 * u.nm)) # Initialize the super class - super().__init__(sfd, wl_bins) + super().__init__(sfd, wl_bins, size) diff --git a/tests/optical_component/test_AOpticalComponent.py b/tests/optical_component/test_AOpticalComponent.py index 9410c72..db12875 100644 --- a/tests/optical_component/test_AOpticalComponent.py +++ b/tests/optical_component/test_AOpticalComponent.py @@ -21,7 +21,7 @@ class TestAOpticalComponent(TestCase): obstruction=0.1, obstructor_temp=300 * u.K, obstructor_emissivity=1) def test_calcSignal(self): - self.assertEqual(self.comp.calcSignal(), + self.assertEqual(self.comp.calcSignal()[0], SpectralQty(self.wl, np.array([1.29074440e-17, 5.65909989e-18, 2.85372997e-18, 1.58973516e-18]) << u.W / (u.m ** 2 * u.nm))) diff --git a/tests/optical_component/test_Atmosphere.py b/tests/optical_component/test_Atmosphere.py index d11aa6f..102e728 100644 --- a/tests/optical_component/test_Atmosphere.py +++ b/tests/optical_component/test_Atmosphere.py @@ -11,7 +11,7 @@ class TestAtmosphere(TestCase): "data/atmosphere/atmosphere_emission_1.csv") def test_calcSignal(self): - self.assertEqual(self.atmosphere.calcSignal(), + self.assertEqual(self.atmosphere.calcSignal()[0], SpectralQty(np.arange(200, 210) << u.nm, np.array([1.10e-15, 1.20e-15, 1.30e-15, 1.26e-15, 1.20e-15, 1.12e-15, 1.02e-15, 0.9e-15, 0, 0]) << u.W / (u.m ** 2 * u.nm))) diff --git a/tests/optical_component/test_BeamSplitter.py b/tests/optical_component/test_BeamSplitter.py index 9baada8..fb122e9 100644 --- a/tests/optical_component/test_BeamSplitter.py +++ b/tests/optical_component/test_BeamSplitter.py @@ -18,7 +18,7 @@ class TestBeamSplitter(TestCase): self.assertEqual(self.splitter.calcBackground(), SpectralQty(self.wl, np.array([4.31413931e-96, 1.37122214e-95, 4.30844544e-95, 1.33846280e-94]) << u.W / (u.m ** 2 * u.nm * u.sr))) - self.assertEqual(self.splitter.calcSignal(), + self.assertEqual(self.splitter.calcSignal()[0], SpectralQty(np.arange(200, 210, 1) << u.nm, np.array([0, 1.20e-15, 1.30e-15, 1.40e-15, 1.35e-15, 0, 0, 0, 0, 0]) << u.W / (u.m ** 2 * u.nm))) diff --git a/tests/optical_component/test_Filter.py b/tests/optical_component/test_Filter.py index 9d01b5c..feca53b 100644 --- a/tests/optical_component/test_Filter.py +++ b/tests/optical_component/test_Filter.py @@ -9,14 +9,14 @@ class TestFilter(TestCase): wl = np.array([400, 500, 501, 545, 589, 590, 600]) << u.nm target = BlackBodyTarget(wl, temp=5778 * u.K, mag=10 * u.mag, band="U") filt = Filter.fromBand(target, "V") - self.assertEqual(filt.calcSignal(), SpectralQty(wl, np.array([0.0, 0.0, 0.0, 5.52730709e-15, 5.29671115e-15, + self.assertEqual(filt.calcSignal()[0], SpectralQty(wl, np.array([0.0, 0.0, 0.0, 5.52730709e-15, 5.29671115e-15, 5.29030718e-15, 0.0]) << u.W / (u.m ** 2 * u.nm))) def test_fromFile(self): target = FileTarget("data/target/target_demo_1.csv", np.arange(200, 210, 1) << u.nm) filt = Filter.fromFile(target, "data/filter/filter_transmittance.csv") - self.assertEqual(filt.calcSignal(), + self.assertEqual(filt.calcSignal()[0], SpectralQty(np.arange(200, 210, 1) << u.nm, np.array([1.10e-15, 1.20e-15, 1.30e-15, 1.40e-15, 1.35e-15, 1.44e-15, 1.53e-15, 1.44e-15, 1.52e-15, 1.40e-15]) << u.W / diff --git a/tests/optical_component/test_Lens.py b/tests/optical_component/test_Lens.py index b59794f..aee8af7 100644 --- a/tests/optical_component/test_Lens.py +++ b/tests/optical_component/test_Lens.py @@ -17,7 +17,7 @@ class TestLens(TestCase): self.assertEqual(self.lens.calcBackground(), SpectralQty(self.wl, np.array([4.31413931e-96, 1.37122214e-95, 4.30844544e-95, 1.33846280e-94]) << u.W / (u.m ** 2 * u.nm * u.sr))) - self.assertEqual(self.lens.calcSignal(), + self.assertEqual(self.lens.calcSignal()[0], SpectralQty(np.arange(200, 210, 1) << u.nm, np.array([0, 1.20e-15, 1.30e-15, 1.40e-15, 1.35e-15, 0, 0, 0, 0, 0]) << u.W / (u.m ** 2 * u.nm))) diff --git a/tests/optical_component/test_Mirror.py b/tests/optical_component/test_Mirror.py index 28bc53f..e253f28 100644 --- a/tests/optical_component/test_Mirror.py +++ b/tests/optical_component/test_Mirror.py @@ -17,7 +17,7 @@ class TestMirror(TestCase): self.assertEqual(self.mirror.calcBackground(), SpectralQty(self.wl, np.array([4.31413931e-96, 1.37122214e-95, 4.30844544e-95, 1.33846280e-94]) << u.W / (u.m ** 2 * u.nm * u.sr))) - self.assertEqual(self.mirror.calcSignal(), + self.assertEqual(self.mirror.calcSignal()[0], SpectralQty(np.arange(200, 210, 1) << u.nm, np.array([0, 1.20e-15, 1.30e-15, 1.40e-15, 1.35e-15, 0, 0, 0, 0, 0]) << u.W / (u.m ** 2 * u.nm))) diff --git a/tests/optical_component/test_StrayLight.py b/tests/optical_component/test_StrayLight.py index ebde35a..55473ad 100644 --- a/tests/optical_component/test_StrayLight.py +++ b/tests/optical_component/test_StrayLight.py @@ -10,7 +10,7 @@ class TestStrayLight(TestCase): self.zodiac = StrayLight(self.target, "data/straylight/zodiacal_emission_1.csv") def test_calcSignal(self): - self.assertEqual(self.zodiac.calcSignal(), + self.assertEqual(self.zodiac.calcSignal()[0], SpectralQty(np.arange(200, 210) << u.nm, np.array([1.1e-15, 1.2e-15, 1.3e-15, 1.4e-15, 1.5e-15, 1.6e-15, 1.7e-15, 1.8e-15, 1.9e-15, 2.0e-15]) << u.W / (u.m ** 2 * u.nm))) diff --git a/tests/target/test_BlackBodyTarget.py b/tests/target/test_BlackBodyTarget.py index 077c527..f4b5744 100644 --- a/tests/target/test_BlackBodyTarget.py +++ b/tests/target/test_BlackBodyTarget.py @@ -13,7 +13,7 @@ class TestBlackBodyTarget(TestCase): def test_calcSignal(self): signal = SpectralQty(np.arange(400, 800, 100) << u.nm, np.array([4.91164694e-15, 5.61732017e-15, 5.22403225e-15, 4.43017583e-15]) << u.W / (u.m ** 2 * u.nm)) - self.assertEqual(self.target.calcSignal(), signal) + self.assertEqual(self.target.calcSignal(), (signal, "Point")) def test_calcBackground(self): noise = SpectralQty(np.arange(400, 800, 100) << u.nm, np.repeat(0, 4) << u.W / (u.m ** 2 * u.nm * u.sr)) diff --git a/tests/target/test_FileTarget.py b/tests/target/test_FileTarget.py index 14326c7..783b29c 100644 --- a/tests/target/test_FileTarget.py +++ b/tests/target/test_FileTarget.py @@ -11,8 +11,8 @@ class TestFileTarget(TestCase): def test_calcSignal(self): signal = SpectralQty(np.arange(200, 210, 1) << u.nm, - np.arange(1.1e-15, 2.0e-15, 1e-16) << u.W / (u.m ** 2 * u.nm)) - self.assertTrue(self.target.calcSignal().__eq__(signal)) + np.arange(1.1e-15, 2.0e-15, 1e-16) << u.W / (u.m ** 2 * u.nm)) + self.assertEqual(self.target.calcSignal(), (signal, "Point")) def test_calcBackground(self): noise = SpectralQty(np.arange(200, 210, 1) << u.nm,