From 9a95468f4001105af7c33566099c7e103e43f56f Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Wed, 8 Apr 2020 17:31:55 +0200 Subject: [PATCH] tests added --- tests/test_BlackBodyTarget.py | 22 ++++++++++++++++++++++ tests/test_SpectralQty.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/test_BlackBodyTarget.py create mode 100644 tests/test_SpectralQty.py diff --git a/tests/test_BlackBodyTarget.py b/tests/test_BlackBodyTarget.py new file mode 100644 index 0000000..191e0c6 --- /dev/null +++ b/tests/test_BlackBodyTarget.py @@ -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) diff --git a/tests/test_SpectralQty.py b/tests/test_SpectralQty.py new file mode 100644 index 0000000..d2e7c69 --- /dev/null +++ b/tests/test_SpectralQty.py @@ -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))