From 62790e68de899bbf524240ab382105b210b3d3cc Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Fri, 17 Apr 2020 09:57:52 +0200 Subject: [PATCH] use numpy array instead of list --- .../test_AHotOpticalComponent.py | 10 +++++---- .../test_AOpticalComponent.py | 22 ++++++++++--------- tests/optical_component/test_Filter.py | 16 ++++++++------ tests/optical_component/test_StrayLight.py | 11 +++++----- tests/target/test_BlackBodyTarget.py | 8 +++---- tests/target/test_FileTarget.py | 2 +- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/tests/optical_component/test_AHotOpticalComponent.py b/tests/optical_component/test_AHotOpticalComponent.py index 37b9fcd..65a7857 100644 --- a/tests/optical_component/test_AHotOpticalComponent.py +++ b/tests/optical_component/test_AHotOpticalComponent.py @@ -26,9 +26,11 @@ class TestAHotOpticalComponent(TestCase): def test___init__(self): comp = HotOpticalComponent(self.target, SpectralQty(self.wl, np.repeat(0.5, 4) << u.dimensionless_unscaled), temp=300 * u.K) - self.assertEqual(comp.calcNoise(), SpectralQty(self.wl, [4.31413931e-96, 1.37122214e-95, 4.30844544e-95, - 1.33846280e-94] << u.W / (u.m ** 2 * u.nm * u.sr))) + self.assertEqual(comp.calcNoise(), + 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))) comp = HotOpticalComponent(self.target, "data/mirror/mirror_emissivity.csv", temp=300 * u.K) - self.assertEqual(comp.calcNoise(), SpectralQty(self.wl, [4.31413931e-96, 1.37122214e-95, 4.30844544e-95, - 1.33846280e-94] << u.W / (u.m ** 2 * u.nm * u.sr))) + self.assertEqual(comp.calcNoise(), + 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))) diff --git a/tests/optical_component/test_AOpticalComponent.py b/tests/optical_component/test_AOpticalComponent.py index 1fd01e0..e2fabbb 100644 --- a/tests/optical_component/test_AOpticalComponent.py +++ b/tests/optical_component/test_AOpticalComponent.py @@ -16,20 +16,22 @@ class TestAOpticalComponent(TestCase): def setUp(self): self.target = BlackBodyTarget(self.wl, temp=5778 * u.K, mag=10 * u.mag, band="U") - self.comp = OpticalComponent(self.target, SpectralQty(self.wl, [0.5] * 4), - SpectralQty(self.wl, [1e-5] * 4 << u.W / (u.m ** 2 * u.nm * u.sr)), + self.comp = OpticalComponent(self.target, SpectralQty(self.wl, np.repeat(0.5, 4) << u.dimensionless_unscaled), + SpectralQty(self.wl, np.repeat(1e-5, 4) << u.W / (u.m ** 2 * u.nm * u.sr)), obstruction=0.1, obstructor_temp=300 * u.K, obstructor_emissivity=1) def test_calcSignal(self): - self.assertEqual(self.comp.calcSignal(), SpectralQty(self.wl, [1.25575776e-17, 5.50570557e-18, 2.77637739e-18, - 1.54664415e-18] << u.W / (u.m ** 2 * u.nm))) + self.assertEqual(self.comp.calcSignal(), + SpectralQty(self.wl, np.array([1.25575776e-17, 5.50570557e-18, 2.77637739e-18, + 1.54664415e-18]) << u.W / (u.m ** 2 * u.nm))) def test_calcNoise(self): self.assertEqual(self.comp.calcNoise(), - SpectralQty(self.wl, [8.21976423e-05, 2.70268340e-04, 5.27503292e-04, - 7.60597616e-04] << u.W / (u.m ** 2 * u.nm * u.sr))) - comp = OpticalComponent(self.comp, SpectralQty(self.wl, [0.5] * 4), - SpectralQty(self.wl, [0] * 4 << u.W / (u.m ** 2 * u.nm * u.sr)), + SpectralQty(self.wl, np.array([8.21976423e-05, 2.70268340e-04, 5.27503292e-04, + 7.60597616e-04]) << u.W / (u.m ** 2 * u.nm * u.sr))) + comp = OpticalComponent(self.comp, SpectralQty(self.wl, np.repeat(0.5, 4) << u.dimensionless_unscaled), + SpectralQty(self.wl, np.repeat(0, 4) << u.W / (u.m ** 2 * u.nm * u.sr)), obstruction=0.1, obstructor_temp=300 * u.K, obstructor_emissivity=1) - self.assertEqual(comp.calcNoise(), SpectralQty(self.wl, [1.09186581e-04, 3.81889092e-04, 7.54879773e-04, - 10.92866544e-04] << u.W / (u.m ** 2 * u.nm * u.sr))) + self.assertEqual(comp.calcNoise(), + SpectralQty(self.wl, np.array([1.09186581e-04, 3.81889092e-04, 7.54879773e-04, + 10.92866544e-04]) << u.W / (u.m ** 2 * u.nm * u.sr))) diff --git a/tests/optical_component/test_Filter.py b/tests/optical_component/test_Filter.py index ebb5c02..a046a45 100644 --- a/tests/optical_component/test_Filter.py +++ b/tests/optical_component/test_Filter.py @@ -6,16 +6,18 @@ import astropy.units as u class TestFilter(TestCase): def test_fromBand(self): - wl = [400, 500, 501, 545, 589, 590, 600] << u.nm + 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, [0.0, 0.0, 5.46516556e-15, 5.37748512e-15, 5.15313966e-15, - 0.0, 0.0] << u.W / (u.m ** 2 * u.nm))) + self.assertEqual(filt.calcSignal(), SpectralQty(wl, np.array([0.0, 0.0, 5.46516556e-15, 5.37748512e-15, + 5.15313966e-15, 0.0, 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(), SpectralQty(np.arange(200, 210, 1) << u.nm, - [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 / ( - u.m ** 2 * u.nm))) + self.assertEqual(filt.calcSignal(), + 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 / + (u.m ** 2 * u.nm))) diff --git a/tests/optical_component/test_StrayLight.py b/tests/optical_component/test_StrayLight.py index 2d7f0f2..1f5025d 100644 --- a/tests/optical_component/test_StrayLight.py +++ b/tests/optical_component/test_StrayLight.py @@ -11,12 +11,13 @@ class TestStrayLight(TestCase): def test_calcSignal(self): self.assertEqual(self.zodiac.calcSignal(), - SpectralQty(np.arange(200, 210) << u.nm, [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))) + 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))) def test_calcNoise(self): self.assertEqual(self.zodiac.calcNoise(), - SpectralQty(np.arange(200, 210) << u.nm, [1.1e-16, 1.2e-16, 1.3e-16, 1.4e-16, 1.5e-16, 1.6e-16, - 1.7e-16, 1.8e-16, 1.9e-16, 2.0e-16] << u.W / + SpectralQty(np.arange(200, 210) << u.nm, np.array([1.1e-16, 1.2e-16, 1.3e-16, 1.4e-16, 1.5e-16, + 1.6e-16, 1.7e-16, 1.8e-16, 1.9e-16, + 2.0e-16]) << u.W / (u.m ** 2 * u.nm * u.sr))) diff --git a/tests/target/test_BlackBodyTarget.py b/tests/target/test_BlackBodyTarget.py index 2c68cf2..57e2f43 100644 --- a/tests/target/test_BlackBodyTarget.py +++ b/tests/target/test_BlackBodyTarget.py @@ -11,12 +11,10 @@ class TestBlackBodyTarget(TestCase): 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)) + signal = SpectralQty(np.arange(400, 800, 100) << u.nm, np.array([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.] * 4 << u.W / (u.m ** 2 * u.nm * u.sr)) + noise = SpectralQty(np.arange(400, 800, 100) << u.nm, np.repeat(0, 4) << u.W / (u.m ** 2 * u.nm * u.sr)) self.assertEqual(self.target.calcNoise(), noise) diff --git a/tests/target/test_FileTarget.py b/tests/target/test_FileTarget.py index ec174db..27776d9 100644 --- a/tests/target/test_FileTarget.py +++ b/tests/target/test_FileTarget.py @@ -16,5 +16,5 @@ class TestFileTarget(TestCase): def test_noise(self): noise = SpectralQty(np.arange(200, 210, 1) << u.nm, - [0.] * 10 << u.W / (u.m ** 2 * u.nm * u.sr)) + np.repeat(0, 10) << u.W / (u.m ** 2 * u.nm * u.sr)) self.assertEqual(self.target.calcNoise(), noise)