tests added

This commit is contained in:
Lukas Klass 2020-04-08 17:31:55 +02:00
parent fec2e53e97
commit 9a95468f40
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,22 @@
from unittest import TestCase
from esbo_etc.classes.target.BlackBodyTarget import BlackBodyTarget
from esbo_etc.classes.SpectralQty import SpectralQty
import numpy as np
import astropy.units as u
class TestBlackBodyTarget(TestCase):
def setUp(self):
self.target = BlackBodyTarget(wl_bins=np.arange(400, 800, 100) * u.nm,
temp=5778 * u.K, mag=10 * u.mag, band="U")
def test_signal(self):
signal = SpectralQty(np.arange(400, 800, 100) << u.nm,
[4.77851291e-15, 5.46505832e-15, 5.08243077e-15,
4.31009246e-15] << u.W / (u.m ** 2 * u.nm))
self.assertTrue(self.target.calcSignal().__eq__(signal))
def test_noise(self):
noise = SpectralQty(np.arange(400, 800, 100) << u.nm,
[0.] * 10 << u.W / (u.m ** 2 * u.nm * u.sr))
self.assertEqual(self.target.calcNoise(), noise)

31
tests/test_SpectralQty.py Normal file
View File

@ -0,0 +1,31 @@
from unittest import TestCase
from esbo_etc.classes.SpectralQty import SpectralQty
import astropy.units as u
import numpy as np
class TestSpectralQty(TestCase):
qty = np.arange(1.1e-15, 2.0e-15, 1e-16) << u.W / (u.m ** 2 * u.nm)
wl = np.arange(200, 210, 1) << u.nm
def setUp(self):
self.sqty = SpectralQty(self.wl, self.qty)
def test_equality(self):
sqty_2 = SpectralQty(self.wl, self.qty)
self.assertTrue(self.sqty.__eq__(sqty_2))
def test_rebinning(self):
# Test interpolation
wl_new = np.arange(200.5, 210.5, 1) << u.nm
sqty_new = SpectralQty(wl_new, [1.15e-15, 1.25e-15, 1.35e-15, 1.45e-15, 1.55e-15, 1.65e-15, 1.75e-15, 1.85e-15,
1.95e-15, 2.05e-15] << u.W / (u.m ** 2 * u.nm))
self.sqty.rebin(wl_new)
self.assertTrue(self.sqty.__eq__(sqty_new))
# Test binning
self.setUp()
wl_new = np.arange(200.5, 210, 2) << u.nm
sqty_new = SpectralQty(wl_new, [1.15e-15, 1.35e-15, 1.55e-15, 1.75e-15, 1.95e-15] << u.W / (u.m ** 2 * u.nm))
self.sqty.rebin(wl_new)
self.assertTrue(self.sqty.__eq__(sqty_new))