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# 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 os 

27import numpy as np 

28 

29from lsst.utils import getPackageDir 

30from lsst.afw.table import SimpleCatalog 

31from lsst.faro.utils.tex import (TraceSize, PsfTraceSizeDiff, 

32 E1, E2, E1Resids, E2Resids, 

33 RhoStatistics) 

34 

35 

36DATADIR = os.path.join(getPackageDir('faro'), 'tests', 'data') 

37 

38 

39class TEXUtilTest(unittest.TestCase): 

40 """Test TEX utility functions.""" 

41 

42 def loadData(self): 

43 """Helper to load data to process.""" 

44 cat_file = 'src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits' 

45 cat = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file)) 

46 

47 # selection = np.isfinite(cat.get('e1')) & np.isfinite(cat.get('e2')) 

48 selection = np.tile(True, len(cat)) 

49 

50 return cat.subset(selection).copy(deep=True) 

51 

52 def testEllipticityDefinitions(self): 

53 """Test ellipticity functors.""" 

54 

55 cat = self.loadData() 

56 

57 column = 'slot_Shape' 

58 columnPsf = 'slot_PsfShape' 

59 

60 trace = TraceSize(column) 

61 result = np.nanmean(trace(cat)) 

62 expected = 4.36377821335775 

63 self.assertEqual(result, expected) 

64 

65 traceDiff = PsfTraceSizeDiff(column, columnPsf) 

66 result = np.nanmean(traceDiff(cat)) 

67 expected = 25.301812428201995 

68 self.assertEqual(result, expected) 

69 

70 e1 = E1(column) 

71 result = np.nanmean(e1(cat)) 

72 expected = 0.0012636175684993878 

73 self.assertEqual(result, expected) 

74 

75 e1 = E1(column, shearConvention=True) 

76 result = np.nanmean(e1(cat)) 

77 expected = 0.00043009504274617235 

78 self.assertEqual(result, expected) 

79 

80 e2 = E2(column) 

81 result = np.nanmean(e2(cat)) 

82 expected = 0.080076033827269 

83 self.assertEqual(result, expected) 

84 

85 e2 = E2(column, shearConvention=True) 

86 result = np.nanmean(e2(cat)) 

87 expected = 0.04194134295796996 

88 self.assertEqual(result, expected) 

89 

90 e1Resids = E1Resids(column, columnPsf) 

91 result = np.nanmean(e1Resids(cat)) 

92 expected = -0.0009098947676481413 

93 self.assertEqual(result, expected) 

94 

95 e2Resids = E2Resids(column, columnPsf) 

96 result = np.nanmean(e2Resids(cat)) 

97 expected = -0.02280606766168935 

98 self.assertEqual(result, expected) 

99 

100 def testRhoStats(self): 

101 """Compute six Rho statistics.""" 

102 

103 cat = self.loadData() 

104 column = 'slot_Shape' 

105 columnPsf = 'slot_PsfShape' 

106 

107 treecorrKwargs = dict(nbins=5, 

108 min_sep=0.25, 

109 max_sep=1, 

110 sep_units='arcmin', 

111 brute=True) 

112 rhoStatistics = RhoStatistics(column, columnPsf, **treecorrKwargs) 

113 result = rhoStatistics(cat) 

114 

115 expected = [0.2344471639428089, 

116 0.0010172306766334468, 

117 -0.0021045081490440086, 

118 0.0028001762296714734, 

119 -0.0013278190624450364, 

120 0.005010295952053786] 

121 

122 self.assertAlmostEqual(np.mean(result[0].xi), expected[0], places=7) 

123 self.assertAlmostEqual(np.mean(result[1].xip), expected[1], places=7) 

124 self.assertAlmostEqual(np.mean(result[2].xip), expected[2], places=7) 

125 self.assertAlmostEqual(np.mean(result[3].xip), expected[3], places=7) 

126 self.assertAlmostEqual(np.mean(result[4].xip), expected[4], places=7) 

127 self.assertAlmostEqual(np.mean(result[5].xip), expected[5], places=7) 

128 

129 

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

131 unittest.main()