Coverage for tests/test_makeTransmissionCurves.py: 13%
89 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-21 10:02 +0000
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-21 10:02 +0000
1#
2# LSST Data Management System
3#
4# Copyright 2018 AURA/LSST.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <https://www.lsstcorp.org/LegalNotices/>.
22#
23import unittest
24import numpy as np
26import lsst.utils.tests
27from lsst.geom import Point2D
28from lsst.obs.hsc import makeTransmissionCurves
31class MakeTransmissionCurvesTest(lsst.utils.tests.TestCase):
33 def testOptics(self):
34 wavelengths = np.linspace(4000, 10000, 100)
35 point = Point2D(1000, -500)
36 for curve in makeTransmissionCurves.getOpticsTransmission().values():
37 if curve is None:
38 continue
39 throughputs = curve.sampleAt(point, wavelengths)
40 self.assertTrue((throughputs > 0.70).all())
42 def testAtmosphere(self):
43 wavelengths = np.linspace(4000, 12000, 100)
44 point = Point2D(1000, -500)
45 for curve in makeTransmissionCurves.getAtmosphereTransmission().values():
46 if curve is None:
47 continue
48 throughputs = curve.sampleAt(point, wavelengths)
49 ohAbsorption = np.logical_and(wavelengths > 11315, wavelengths < 11397)
50 midR = np.logical_and(wavelengths > 6000, wavelengths < 6300)
51 self.assertTrue((throughputs[ohAbsorption] < throughputs[midR]).all())
53 def testSensors(self):
54 wavelengths = np.linspace(4000, 12000, 100)
55 point = Point2D(200, 10)
56 for sensors in makeTransmissionCurves.getSensorTransmission().values():
57 for i in range(112):
58 curve = sensors[i]
59 throughputs = curve.sampleAt(point, wavelengths)
60 siliconTransparent = wavelengths > 11000
61 self.assertTrue((throughputs[siliconTransparent] < 0.01).all())
62 midR = np.logical_and(wavelengths > 6000, wavelengths < 6300)
63 self.assertTrue((throughputs[midR] > 0.9).all())
65 def testFilters(self):
66 wavelengths = np.linspace(3000, 12000, 1000)
67 point = Point2D(1000, -500)
69 def check(curve, central, w1, w2):
70 # check that throughput within w1 of central is strictly greater
71 # than throughput outside w2 of central
72 throughput = curve.sampleAt(point, wavelengths)
73 mid = np.logical_and(wavelengths > central - w1, wavelengths < central + w1)
74 outer = np.logical_or(wavelengths < central - w2, wavelengths > central + w2)
75 self.assertGreater(throughput[mid].min(), throughput[outer].max())
77 for curves in makeTransmissionCurves.getFilterTransmission().values():
78 check(curves["NB0387"], 3870, 50, 100)
79 check(curves["NB0816"], 8160, 50, 100)
80 check(curves["NB0921"], 9210, 50, 100)
81 check(curves["HSC-G"], 4730, 500, 1500)
82 check(curves["HSC-R"], 6230, 500, 1500)
83 check(curves["HSC-R2"], 6230, 500, 1500)
84 check(curves["HSC-I"], 7750, 500, 1500)
85 check(curves["HSC-I2"], 7750, 500, 1500)
86 check(curves["HSC-Z"], 8923, 500, 1500)
87 check(curves["HSC-Y"], 10030, 500, 1500)
89 def testRadialDependence(self):
90 wavelengths = np.linspace(3000, 11000, 500)
91 radii = np.linspace(0, 20000, 50)
93 def computeMeanWavelengths(curve):
94 w = []
95 for radius in radii:
96 throughput = curve.sampleAt(Point2D(radius, 0), wavelengths)
97 w.append(np.dot(throughput, wavelengths)/throughput.sum())
98 return np.array(w)
100 for curves in makeTransmissionCurves.getFilterTransmission().values():
101 r = computeMeanWavelengths(curves['HSC-R'])
102 r2 = computeMeanWavelengths(curves['HSC-R2'])
103 i = computeMeanWavelengths(curves['HSC-I'])
104 i2 = computeMeanWavelengths(curves['HSC-I2'])
105 # i2 and r2 should have lower variance as a function of radius
106 self.assertLess(r2.std(), r.std())
107 self.assertLess(i2.std(), i.std())
108 # the mean wavelengths of the two r and two i filters should
109 # neverthess be close (within 100 angstroms)
110 self.assertLess(np.abs(r2.mean() - r.mean()), 100)
111 self.assertLess(np.abs(i2.mean() - i.mean()), 100)
112 # Ensure that the nb vary but not too much
113 n387 = computeMeanWavelengths(curves['NB0387'])
114 self.assertLess(np.abs(n387.mean() - 3870.0), 20.0)
115 self.assertGreater(n387.std(), 0.0)
116 n816 = computeMeanWavelengths(curves['NB0816'])
117 self.assertLess(np.abs(n816.mean() - 8160.0), 20.0)
118 self.assertGreater(n816.std(), 0.0)
119 n921 = computeMeanWavelengths(curves['NB0921'])
120 self.assertLess(np.abs(n921.mean() - 9210.0), 20.0)
121 self.assertGreater(n921.std(), 0.0)
122 n1010 = computeMeanWavelengths(curves['NB1010'])
123 self.assertLess(np.abs(n1010.mean() - 10100.0), 20.0)
124 self.assertGreater(n1010.std(), 0.0)
127def setup_module(module):
128 lsst.utils.tests.init()
131if __name__ == "__main__": 131 ↛ 132line 131 didn't jump to line 132, because the condition on line 131 was never true
132 lsst.utils.tests.init()
133 unittest.main()