Coverage for tests/test_coord_util.py: 26%

56 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-14 04:41 -0800

1# This file is part of faro. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

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 GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22"""Unit tests for the metrics measurement system. 

23""" 

24 

25import unittest 

26import numpy as np 

27 

28import lsst.afw.table as afwTable 

29 

30from lsst.faro.utils.coord_util import (averageRaFromCat, 

31 averageDecFromCat, 

32 averageRaDecFromCat, 

33 averageRaDec, 

34 sphDist) 

35 

36 

37class CoordUtilTest(unittest.TestCase): 

38 """Test coordinate utility functions.""" 

39 

40 def makeDataDiagonal(self): 

41 """Make minimal sythetic catalog with simple values.""" 

42 ra_test = np.radians(np.linspace(-10., 10., 101)) 

43 dec_test = np.radians(np.linspace(-10., 10., 101)) 

44 schema = afwTable.SourceTable.makeMinimalSchema() 

45 cat = afwTable.SimpleCatalog(schema) 

46 cat.resize(len(ra_test)) 

47 cat = cat.copy(deep=True) 

48 cat['coord_ra'][:] = ra_test 

49 cat['coord_dec'][:] = dec_test 

50 return cat 

51 

52 def makeDataHorizontal(self): 

53 """Make minimal sythetic catalog with simple values.""" 

54 ra_test = np.linspace(np.radians(-10.), np.radians(10.), 101) 

55 dec_test = np.tile(0., 101) 

56 schema = afwTable.SourceTable.makeMinimalSchema() 

57 cat = afwTable.SimpleCatalog(schema) 

58 cat.resize(len(ra_test)) 

59 cat = cat.copy(deep=True) 

60 cat['coord_ra'][:] = ra_test 

61 cat['coord_dec'][:] = dec_test 

62 return cat 

63 

64 def test_averageRaFromCat(self): 

65 """Test average RA calculation.""" 

66 expected = 0. 

67 cat = self.makeDataDiagonal() 

68 result = averageRaFromCat(cat) 

69 self.assertAlmostEqual(result, expected, places=15) 

70 

71 def test_averageDecFromCat(self): 

72 """Test average declination calculation.""" 

73 expected = 0. 

74 cat = self.makeDataDiagonal() 

75 result = averageDecFromCat(cat) 

76 self.assertAlmostEqual(result, expected, places=15) 

77 

78 def test_averageRaDecFromCat(self): 

79 """Test average RA and declination calculation.""" 

80 expected = (0., 0.) 

81 cat = self.makeDataDiagonal() 

82 result = averageRaDecFromCat(cat) 

83 self.assertAlmostEqual(result[0], expected[0], places=15) 

84 self.assertAlmostEqual(result[1], expected[1], places=15) 

85 

86 def test_averageRaDec(self): 

87 """Test average RA and declination calculation.""" 

88 expected = (0., 0.) 

89 cat = self.makeDataDiagonal() 

90 result = averageRaDec(cat['coord_ra'], cat['coord_dec']) 

91 self.assertAlmostEqual(result[0], expected[0], places=15) 

92 self.assertAlmostEqual(result[1], expected[1], places=15) 

93 

94 def test_sphDist(self): 

95 """Test great circle angular separation calculation.""" 

96 expected = np.fabs(np.radians(np.linspace(-10., 10., 101))) 

97 cat = self.makeDataHorizontal() 

98 ra_mean, dec_mean = (0., 0.) 

99 result = sphDist(ra_mean, dec_mean, cat['coord_ra'], cat['coord_dec']) 

100 self.assertTrue(np.allclose(result, expected, atol=1.e-15)) 

101 

102 

103if __name__ == "__main__": 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true

104 unittest.main()