Coverage for python / lsst / analysis / tools / atools / diaSourceTableTractMetrics.py: 34%

53 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-30 09:27 +0000

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/>. 

21 

22__all__ = ( 

23 "NumDiaSourcesMetric", 

24 "NumStreakDiaSourcesMetric", 

25 "NumStreakCenterDiaSourcesMetric", 

26 "PlotStreakDiaSources", 

27) 

28 

29from ..actions.keyedData import KeyedDataSelectorAction 

30from ..actions.plot.diaSkyPlot import DiaSkyPanel, DiaSkyPlot 

31from ..actions.scalar import CountAction 

32from ..actions.vector import FlagSelector, GoodDiaSourceSelector, LoadVector 

33from ..interfaces import AnalysisTool 

34 

35 

36class NumDiaSourcesMetric(AnalysisTool): 

37 """Count all DiaSources that do not have known bad/quality flags.""" 

38 

39 parameterizedBand: bool = False 

40 

41 def setDefaults(self): 

42 super().setDefaults() 

43 

44 # Select "good" DiaSources that are not obvious garbage 

45 self.prep.selectors.goodDiaSourceSelector = GoodDiaSourceSelector() 

46 # Count them 

47 self.process.calculateActions.numDiaSources = CountAction(vectorKey="parentDiaSourceId") 

48 # Set the units for the resulting astropy quantity (ct is count) 

49 self.produce.metric.units = {"numDiaSources": "ct"} 

50 

51 

52class NumStreakDiaSourcesMetric(AnalysisTool): 

53 """Count DiaSources that fall in a STREAK flag footprint region.""" 

54 

55 parameterizedBand: bool = False 

56 

57 def setDefaults(self): 

58 super().setDefaults() 

59 

60 # First, select "good" DiaSources that are not obvious garbage 

61 self.prep.selectors.goodDiaSourceSelector = GoodDiaSourceSelector() 

62 # Second, select DiaSources with STREAK flag set in the footprint 

63 self.prep.selectors.flags = FlagSelector(selectWhenTrue=["pixelFlags_streak"]) 

64 # Count them 

65 self.process.calculateActions.numStreakDiaSources = CountAction(vectorKey="parentDiaSourceId") 

66 # Set the units for the resulting astropy quantity (ct is count) 

67 self.produce.metric.units = {"numStreakDiaSources": "ct"} 

68 

69 

70class NumStreakCenterDiaSourcesMetric(AnalysisTool): 

71 """Count DiaSources that have the STREAK flag in the center 

72 of the source.""" 

73 

74 parameterizedBand: bool = False 

75 

76 def setDefaults(self): 

77 super().setDefaults() 

78 

79 # First, select "good" DiaSources that are not obvious garbage 

80 self.prep.selectors.goodDiaSourceSelector = GoodDiaSourceSelector() 

81 # Second, select DiaSources with STREAK flag set in the source center 

82 self.prep.selectors.flags = FlagSelector(selectWhenTrue=["pixelFlags_streakCenter"]) 

83 # Count them 

84 self.process.calculateActions.numStreakCenterDiaSources = CountAction(vectorKey="parentDiaSourceId") 

85 # Set the units for the resulting astropy quantity (ct is count) 

86 self.produce.metric.units = {"numStreakCenterDiaSources": "ct"} 

87 

88 

89class PlotStreakDiaSources(AnalysisTool): 

90 """Plot all good DiaSources, and indicate which coincide with a streak.""" 

91 

92 parameterizedBand: bool = False 

93 

94 def setDefaults(self): 

95 super().setDefaults() 

96 

97 self.process.buildActions.rasAll = LoadVector() 

98 self.process.buildActions.rasAll.vectorKey = "ra" 

99 self.process.buildActions.decsAll = LoadVector() 

100 self.process.buildActions.decsAll.vectorKey = "dec" 

101 

102 # First, select "good" DiaSources that are not obvious garbage 

103 self.process.buildActions.coordsGood = KeyedDataSelectorAction(vectorKeys=["ra", "dec"]) 

104 self.process.buildActions.coordsGood.selectors.selectorGood = GoodDiaSourceSelector() 

105 

106 # Second, select DiaSources with STREAK flag set in the footprint 

107 self.process.buildActions.coordsStreak = KeyedDataSelectorAction(vectorKeys=["ra", "dec"]) 

108 self.process.buildActions.coordsStreak.selectors.selectorStreak = FlagSelector( 

109 selectWhenTrue=["pixelFlags_streak"] 

110 ) 

111 

112 # Finally, select DiaSources with STREAK flag set in the source center 

113 self.process.buildActions.coordsStreakCenter = KeyedDataSelectorAction(vectorKeys=["ra", "dec"]) 

114 self.process.buildActions.coordsStreakCenter.selectors.selectorStreakCenter = FlagSelector( 

115 selectWhenTrue=["pixelFlags_streakCenter"] 

116 ) 

117 

118 # Use the DRP column names for all of the above, and generate the plot 

119 self.produce.plot = DiaSkyPlot() 

120 

121 self.produce.plot.panels["panel_main"] = DiaSkyPanel() 

122 self.produce.plot.panels["panel_main"].xlabel = "RA (deg)" 

123 self.produce.plot.panels["panel_main"].ylabel = "Dec (deg)" 

124 self.produce.plot.panels["panel_main"].subplot2gridRowspan = 10 

125 self.produce.plot.panels["panel_main"].subplot2gridColspan = 10 

126 self.produce.plot.panels["panel_main"].ras = [ 

127 "rasAll", 

128 "coordsGood_ra", 

129 "coordsStreak_ra", 

130 "coordsStreakCenter_ra", 

131 ] 

132 self.produce.plot.panels["panel_main"].decs = [ 

133 "decsAll", 

134 "coordsGood_dec", 

135 "coordsStreak_dec", 

136 "coordsStreakCenter_dec", 

137 ] 

138 self.produce.plot.panels["panel_main"].legendLabels = [ 

139 "All DiaSources", 

140 "Good DiaSources", 

141 "Streak footprint DiaSources", 

142 "Streak center DiaSources", 

143 ] 

144 self.produce.plot.panels["panel_main"].rightSpinesVisible = False