Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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# 

22 

23 

24import unittest 

25 

26import numpy as np 

27 

28from numpy.testing import assert_almost_equal, assert_array_max_ulp 

29 

30import lsst.utils 

31from lsst.validate.drp import util 

32 

33 

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) 

39 

40 obs = util.positionRms(ra_avg, dec_avg, ra, dec) 

41 

42 assert np.isnan(obs) 

43 

44 

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) 

50 

51 exp = 0 

52 obs = util.positionRms(ra_avg, dec_avg, ra, dec) 

53 

54 assert_array_max_ulp(obs, exp) 

55 

56 

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) 

62 

63 exp = 0.0019488135998463505 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec 

64 obs = util.positionRms(ra_avg, dec_avg, ra, dec) 

65 

66 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec 

67 

68 

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) 

74 

75 exp = 0.0021794464685958273 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec 

76 obs = util.positionRms(ra_avg, dec_avg, ra, dec) 

77 

78 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec 

79 

80 

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) 

86 

87 exp = 0.0021794464685958273 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec 

88 obs = util.positionRms(ra_avg, dec_avg, ra, dec) 

89 

90 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec 

91 

92 

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) 

98 

99 exp = 0.0019488135998463505 * 3600 * 1000 # degrees * arcsec/degree * milliarcsec/arcsec 

100 obs = util.positionRms(ra_avg, dec_avg, ra, dec) 

101 

102 assert_almost_equal(obs, exp, decimal=7) # 1e-7 rad == 5.73e-6 deg == 36 milliarcsec 

103 

104 

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()