Coverage for python/lsst/analysis/tools/analysisMetrics/analysisMetrics.py: 54%

50 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-18 03:07 -0800

1# This file is part of analysis_tools. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21from __future__ import annotations 

22 

23__all__ = ( 

24 "WPerpPSFMetric", 

25 "WPerpCModelMetric", 

26 "XPerpPSFMetric", 

27 "XPerpCModelMetric", 

28 "YPerpPSFMetric", 

29 "YPerpCModelMetric", 

30 "ValidFracColumnMetric", 

31) 

32 

33from lsst.pex.config import Field 

34 

35from ..actions.scalar import FracInRange, FracNan 

36from ..actions.vector import LoadVector 

37from ..analysisParts.stellarLocus import WPerpCModel, WPerpPSF, XPerpCModel, XPerpPSF, YPerpCModel, YPerpPSF 

38from ..interfaces import AnalysisMetric 

39 

40 

41class WPerpPSFMetric(WPerpPSF, AnalysisMetric): 

42 parameterizedBand: bool = False 

43 

44 def setDefaults(self): 

45 super().setDefaults() 

46 

47 self.produce.units = { # type: ignore 

48 "wPerp_psfFlux_sigmaMAD": "mmag", 

49 "wPerp_psfFlux_median": "mmag", 

50 } 

51 

52 

53class WPerpCModelMetric(WPerpCModel, AnalysisMetric): 

54 def setDefaults(self): 

55 super().setDefaults() 

56 

57 self.produce.units = { # type: ignore 

58 "wPerp_cmodelFlux_sigmaMAD": "mmag", 

59 "wPerp_cmodelFlux_median": "mmag", 

60 } 

61 

62 

63class XPerpPSFMetric(XPerpPSF, AnalysisMetric): 

64 parameterizedBand: bool = False 

65 

66 def setDefaults(self): 

67 super().setDefaults() 

68 

69 self.produce.units = { # type: ignore 

70 "xPerp_psfFlux_sigmaMAD": "mmag", 

71 "xPerp_psfFlux_median": "mmag", 

72 } 

73 

74 

75class XPerpCModelMetric(XPerpCModel, AnalysisMetric): 

76 def setDefaults(self): 

77 super().setDefaults() 

78 

79 self.produce.units = { # type: ignore 

80 "xPerp_cmodelFlux_sigmaMAD": "mmag", 

81 "xPerp_cmodelFlux_median": "mmag", 

82 } 

83 

84 

85class YPerpPSFMetric(YPerpPSF, AnalysisMetric): 

86 def setDefaults(self): 

87 super().setDefaults() 

88 

89 self.produce.units = { # type: ignore 

90 "yPerp_psfFlux_sigmaMAD": "mmag", 

91 "yPerp_psfFlux_median": "mmag", 

92 } 

93 

94 

95class YPerpCModelMetric(YPerpCModel, AnalysisMetric): 

96 def setDefaults(self): 

97 super().setDefaults() 

98 

99 self.produce.units = { # type: ignore 

100 "yPerp_cmodelFlux_sigmaMAD": "mmag", 

101 "yPerp_cmodelFlux_median": "mmag", 

102 } 

103 

104 

105class ValidFracColumnMetric(AnalysisMetric): 

106 """Calculate the fraction of values in a column that have valid 

107 numerical values (i.e., not NaN), and that fall within the specified 

108 "reasonable" range for the values. 

109 """ 

110 

111 vectorKey = Field[str](doc="Key of column to validate", default="psfFlux") 

112 

113 def visitContext(self) -> None: 

114 self.process.buildActions.loadVector = LoadVector() 

115 self.process.buildActions.loadVector.vectorKey = f"{self.vectorKey}" 

116 self._setActions(f"{self.vectorKey}") 

117 

118 def coaddContext(self) -> None: 

119 self.process.buildActions.loadVector = LoadVector() 

120 self.process.buildActions.loadVector.vectorKey = "{band}_" + f"{self.vectorKey}" 

121 self._setActions("{band}_" + f"{self.vectorKey}") 

122 

123 # Need to pass a mapping of new names so the default names get the 

124 # band prepended. Otherwise, each subsequent band's metric will 

125 # overwrite the current one. 

126 self.produce.newNames = { 

127 "validFracColumn": "{band}_validFracColumn", 

128 "nanFracColumn": "{band}_nanFracColumn", 

129 } 

130 

131 def _setActions(self, name: str) -> None: 

132 # The default flux limits of 1e-1 < flux < 1e9 correspond to a 

133 # magnitude range of 34 < mag < 9 (i.e., reasonably well-measured) 

134 # objects should all be within this range). 

135 self.process.calculateActions.validFracColumn = FracInRange( 

136 vectorKey=name, 

137 minimum=1.0e-1, 

138 maximum=1.0e9, 

139 percent=True, 

140 ) 

141 self.process.calculateActions.nanFracColumn = FracNan( 

142 vectorKey=name, 

143 percent=True, 

144 ) 

145 

146 def setDefaults(self): 

147 super().setDefaults() 

148 

149 self.produce.units = { # type: ignore 

150 "validFracColumn": "percent", 

151 "nanFracColumn": "percent", 

152 }