Coverage for tests/test_refraction.py: 30%
57 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-27 02:52 -0700
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-27 02:52 -0700
1#
2# LSST Data Management System
3# See COPYRIGHT file at the top of the source tree.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
24from astropy import units
25import numpy as np
26import unittest
28from lsst.geom import Angle, degrees
29from lsst.afw.coord import Observatory, Weather
30from lsst.afw.coord import refraction, differentialRefraction
31import lsst.utils.tests
34class RefractionTestSuite(lsst.utils.tests.TestCase):
35 """Test the refraction calculations."""
37 def setUp(self):
38 """Define parameters used by every test."""
39 lsstLat = -30.244639*degrees
40 lsstLon = -70.749417*degrees
41 lsstAlt = 2663.
42 lsstTemperature = 20.*units.Celsius # in degrees Celsius
43 lsstHumidity = 10. # in percent
44 lsstPressure = 73892.*units.pascal # 1 atmosphere.
45 np.random.seed(5)
47 self.weather = Weather(lsstTemperature/units.Celsius, lsstPressure/units.pascal, lsstHumidity)
48 self.observatory = Observatory(lsstLon, lsstLat, lsstAlt)
50 def testWavelengthRangeError(self):
51 """Refraction should raise an error if the wavelength is out of range."""
52 elevation = Angle(np.random.random()*np.pi/2.)
53 wl_low = 230.
54 wl_high = 2059.
55 self.assertRaises(ValueError, refraction, wl_low, elevation, self.observatory, weather=self.weather)
56 self.assertRaises(ValueError, refraction, wl_high, elevation, self.observatory, weather=self.weather)
58 def testZenithZero(self):
59 """There should be no refraction exactly at zenith."""
60 elevation = Angle(np.pi/2.)
61 wl = 505. # in nm
62 refractZen = refraction(wl, elevation, self.observatory, weather=self.weather)
63 self.assertAlmostEqual(refractZen.asDegrees(), 0.)
65 def testNoDifferential(self):
66 """There should be no differential refraction if the wavelength is the same as the reference."""
67 wl = 470. # in nm
68 wl_ref = wl
69 elevation = Angle(np.random.random()*np.pi/2.)
70 diffRefraction = differentialRefraction(wl, wl_ref, elevation, self.observatory, weather=self.weather)
71 self.assertFloatsAlmostEqual(diffRefraction.asDegrees(), 0.)
73 def testRefractHighAirmass(self):
74 """Compare the refraction calculation to precomputed values."""
75 elevation = Angle(np.pi/6.) # Airmass 2.0
76 wls = [370., 480., 620., 860., 960., 1025.] # in nm
77 refVals = [73.04868430514726,
78 71.74884360909664,
79 71.02058121935002,
80 70.51172189207065,
81 70.40446894800584,
82 70.35113687114644,
83 ]
84 for wl, refVal in zip(wls, refVals):
85 refract = refraction(wl, elevation, self.observatory, weather=self.weather)
86 self.assertFloatsAlmostEqual(refract.asArcseconds(), refVal, rtol=1e-3)
88 def testRefractWeatherNan(self):
89 """Test the values of refraction when no weather is supplied."""
90 elevation = Angle(np.random.random()*np.pi/2.)
91 elevation = Angle(np.pi/6.) # Airmass 2.0
92 wls = [370., 480., 620., 860., 960., 1025.] # in nm
93 refVals = [76.7339313496466,
94 75.36869048516252,
95 74.60378630142982,
96 74.06932963258161,
97 73.95668242959853,
98 73.9006681751504,
99 ]
100 for wl, refVal in zip(wls, refVals):
101 refract = refraction(wl, elevation, self.observatory)
102 self.assertFloatsAlmostEqual(refract.asArcseconds(), refVal, rtol=1e-3)
105class MemoryTester(lsst.utils.tests.MemoryTestCase):
106 pass
109def setup_module(module):
110 lsst.utils.tests.init()
113if __name__ == "__main__": 113 ↛ 114line 113 didn't jump to line 114, because the condition on line 113 was never true
114 lsst.utils.tests.init()
115 unittest.main()