Coverage for tests/test_positionRms.py: 23%
55 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
1#
2# LSST Data Management System
3# Copyright 2012-2017 LSST Corporation.
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#
24import unittest
26import numpy as np
28from numpy.testing import assert_almost_equal, assert_array_max_ulp
30import lsst.utils
31from lsst.validate.drp import util
34def test_empty_positionRms():
35 ra = np.deg2rad(np.array([]))
36 dec = np.deg2rad(np.array([]))
37 ra_avg = np.mean(ra)
38 dec_avg = np.mean(dec)
40 obs = util.positionRms(ra_avg, dec_avg, ra, dec)
42 assert np.isnan(obs)
45def test_single_positionRms():
46 ra = np.deg2rad(np.array([10.0010]))
47 dec = np.deg2rad(np.array([20.001]))
48 ra_avg = np.mean(ra)
49 dec_avg = np.mean(dec)
51 exp = 0
52 obs = util.positionRms(ra_avg, dec_avg, ra, dec)
54 assert_array_max_ulp(obs, exp)
57def test_basic_positionRms():
58 ra = np.deg2rad(np.array([10.0010, 10.0005, 10.0000, 10.0005]))
59 dec = np.deg2rad(np.array([20.001, 20.006, 20.002, 20.004]))
60 ra_avg = np.mean(ra)
61 dec_avg = np.mean(dec)
63 exp = 0.0019488135998463505 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec
64 obs = util.positionRms(ra_avg, dec_avg, ra, dec)
66 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec
69def test_north_pole_positionRms():
70 ra = np.deg2rad(np.array([10.0010, 10.0005, 190.0000, 190.0005]))
71 dec = np.deg2rad(np.array([89.999, 89.998, 89.999, 89.998]))
72 ra_avg = np.mean(ra)
73 dec_avg = np.mean(dec)
75 exp = 0.0021794464685958273 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec
76 obs = util.positionRms(ra_avg, dec_avg, ra, dec)
78 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec
81def test_south_pole_positionRms():
82 ra = np.deg2rad(np.array([10.0010, 10.0005, 190.0000, 190.0005]))
83 dec = -np.deg2rad(np.array([89.999, 89.998, 89.999, 89.998]))
84 ra_avg = np.mean(ra)
85 dec_avg = np.mean(dec)
87 exp = 0.0021794464685958273 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec
88 obs = util.positionRms(ra_avg, dec_avg, ra, dec)
90 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec
93def test_wrap_positionRms():
94 ra = np.deg2rad(np.array([10.0010, 10.0005, 370.0000, 370.0005]))
95 dec = np.deg2rad(np.array([20.001, 20.006, 20.002, 20.004]))
96 ra_avg = np.mean(ra % (2*np.pi))
97 dec_avg = np.mean(dec)
99 exp = 0.0019488135998463505 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec
100 obs = util.positionRms(ra_avg, dec_avg, ra, dec)
102 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec
105if __name__ == "__main__": 105 ↛ 106line 105 didn't jump to line 106, because the condition on line 105 was never true
106 lsst.utils.tests.init()
107 unittest.main()