Propagate target size.
This commit is contained in:
parent
2e6df65928
commit
62013e323e
@ -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
|
||||
|
||||
|
@ -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:
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)))
|
||||
|
||||
|
@ -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)))
|
||||
|
@ -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)))
|
||||
|
@ -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 /
|
||||
|
@ -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)))
|
||||
|
@ -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)))
|
||||
|
@ -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)))
|
||||
|
@ -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))
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user