From ea25b4ec0f13c63fb3340f850182abd40d6453b9 Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Thu, 18 Jun 2020 09:03:36 +0200 Subject: [PATCH] Cosmic Background component added --- .../optical_component/CosmicBackground.py | 51 +++++++++++++++++++ .../classes/optical_component/__init__.py | 1 + .../test_CosmicBackground.py | 24 +++++++++ 3 files changed, 76 insertions(+) create mode 100644 esbo_etc/classes/optical_component/CosmicBackground.py create mode 100644 tests/optical_component/test_CosmicBackground.py diff --git a/esbo_etc/classes/optical_component/CosmicBackground.py b/esbo_etc/classes/optical_component/CosmicBackground.py new file mode 100644 index 0000000..36b58df --- /dev/null +++ b/esbo_etc/classes/optical_component/CosmicBackground.py @@ -0,0 +1,51 @@ +from .AOpticalComponent import AOpticalComponent +from ..IRadiant import IRadiant +import astropy.units as u +from astropy.modeling.models import BlackBody +from ..Entry import Entry +from typing import Union + + +class CosmicBackground(AOpticalComponent): + """ + This class models the spectral radiance of the cosmic background as black body radiator + """ + + @u.quantity_input(temp=[u.Kelvin, u.Celsius]) + def __init__(self, parent: IRadiant, temp: u.Quantity = 2.725 * u.K): + """ + Initialize a new black body point source + + Parameters + ---------- + parent : IRadiant + The parent element of the optical component from which the electromagnetic radiation is received + temp : Quantity in Kelvin / Celsius + Temperature of the black body + + Returns + ------- + """ + # Create black body model with given temperature + bb = BlackBody(temperature=temp, scale=1 * u.W / (u.m ** 2 * u.nm * u.sr)) + # Initialize super class + super().__init__(parent, 1.0, lambda wl: bb(wl)) + + @staticmethod + def check_config(conf: Entry) -> Union[None, str]: + """ + Check the configuration for this class + + Parameters + ---------- + conf : Entry + The configuration entry to be checked. + + Returns + ------- + mes : Union[None, str] + The error message of the check. This will be None if the check was successful. + """ + mes = conf.check_quantity("temp", u.K) + if mes is not None: + return mes diff --git a/esbo_etc/classes/optical_component/__init__.py b/esbo_etc/classes/optical_component/__init__.py index 1f1884b..61e5b01 100644 --- a/esbo_etc/classes/optical_component/__init__.py +++ b/esbo_etc/classes/optical_component/__init__.py @@ -6,3 +6,4 @@ from .Filter import * from .Lens import * from .BeamSplitter import * from .Mirror import * +from .CosmicBackground import * diff --git a/tests/optical_component/test_CosmicBackground.py b/tests/optical_component/test_CosmicBackground.py new file mode 100644 index 0000000..7ba7c5d --- /dev/null +++ b/tests/optical_component/test_CosmicBackground.py @@ -0,0 +1,24 @@ +from unittest import TestCase +from esbo_etc import CosmicBackground, BlackBodyTarget, SpectralQty +import numpy as np +import astropy.units as u + + +class TestBlackBodyTarget(TestCase): + def setUp(self): + self.target = BlackBodyTarget(np.arange(100, 105) * u.um) + self.cosmic = CosmicBackground(self.target) + + def test_calcSignal(self): + print(self.cosmic.calcSignal()[0]) + self.assertTrue(self.cosmic.calcSignal()[0] == SpectralQty(np.arange(100, 105) * u.um, + np.array([6.65e-19, 6.391e-19, 6.145e-19, 5.91e-19, + 5.687e-19]) << u.W / (u.m ** 2 * u.nm))) + + def test_calcBackground(self): + print(self.cosmic.calcBackground()) + self.assertTrue(self.cosmic.calcBackground() == SpectralQty(np.arange(100, 105) * u.um, + np.array( + [1.398e-28, 2.244e-28, 3.566e-28, 5.614e-28, + 8.756e-28]) << u.W / ( + u.m ** 2 * u.nm * u.sr)))