Cosmic Background component added

This commit is contained in:
Lukas Klass 2020-06-18 09:03:36 +02:00
parent d72f9f9fce
commit ea25b4ec0f
3 changed files with 76 additions and 0 deletions

View File

@ -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

View File

@ -6,3 +6,4 @@ from .Filter import *
from .Lens import *
from .BeamSplitter import *
from .Mirror import *
from .CosmicBackground import *

View File

@ -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)))