Coverage for python/lsst/analysis/tools/atools/diaSourceTableTractMetrics.py: 33%
58 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-03 02:49 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-03 02:49 -0700
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/>.
22__all__ = (
23 "NumDiaSourcesMetric",
24 "NumStreakDiaSourcesMetric",
25 "NumStreakCenterDiaSourcesMetric",
26 "PlotStreakDiaSources",
27)
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 ..contexts import DrpContext
34from ..interfaces import AnalysisTool
37class NumDiaSourcesMetric(AnalysisTool):
38 """Count all DiaSources that do not have known bad/quality flags."""
40 parameterizedBand: bool = False
42 def setDefaults(self):
43 super().setDefaults()
45 # Select "good" DiaSources that are not obvious garbage
46 self.prep.selectors.goodDiaSourceSelector = GoodDiaSourceSelector()
47 # Count them
48 self.process.calculateActions.numDiaSources = CountAction(vectorKey="parentDiaSourceId")
49 # Set the units for the resulting astropy quantity (ct is count)
50 self.produce.metric.units = {"numDiaSources": "ct"}
51 # Use, e.g., `pixelFlags_thing`, not `base_PixelFlags_flag_thing`
52 self.applyContext(DrpContext)
55class NumStreakDiaSourcesMetric(AnalysisTool):
56 """Count DiaSources that fall in a STREAK flag footprint region."""
58 parameterizedBand: bool = False
60 def setDefaults(self):
61 super().setDefaults()
63 # First, select "good" DiaSources that are not obvious garbage
64 self.prep.selectors.goodDiaSourceSelector = GoodDiaSourceSelector()
65 # Second, select DiaSources with STREAK flag set in the footprint
66 self.prep.selectors.flags = FlagSelector(selectWhenTrue=["pixelFlags_streak"])
67 # Count them
68 self.process.calculateActions.numStreakDiaSources = CountAction(vectorKey="parentDiaSourceId")
69 # Set the units for the resulting astropy quantity (ct is count)
70 self.produce.metric.units = {"numStreakDiaSources": "ct"}
71 # Use, e.g., `pixelFlags_thing`, not `base_PixelFlags_flag_thing`
72 self.applyContext(DrpContext)
75class NumStreakCenterDiaSourcesMetric(AnalysisTool):
76 """Count DiaSources that have the STREAK flag in the center
77 of the source."""
79 parameterizedBand: bool = False
81 def setDefaults(self):
82 super().setDefaults()
84 # First, select "good" DiaSources that are not obvious garbage
85 self.prep.selectors.goodDiaSourceSelector = GoodDiaSourceSelector()
86 # Second, select DiaSources with STREAK flag set in the source center
87 self.prep.selectors.flags = FlagSelector(selectWhenTrue=["pixelFlags_streakCenter"])
88 # Count them
89 self.process.calculateActions.numStreakCenterDiaSources = CountAction(vectorKey="parentDiaSourceId")
90 # Set the units for the resulting astropy quantity (ct is count)
91 self.produce.metric.units = {"numStreakCenterDiaSources": "ct"}
92 # Use, e.g., `pixelFlags_thing`, not `base_PixelFlags_flag_thing`
93 self.applyContext(DrpContext)
96class PlotStreakDiaSources(AnalysisTool):
97 """Plot all good DiaSources, and indicate which coincide with a streak."""
99 parameterizedBand: bool = False
101 def setDefaults(self):
102 super().setDefaults()
104 self.process.buildActions.rasAll = LoadVector()
105 self.process.buildActions.rasAll.vectorKey = "ra"
106 self.process.buildActions.decsAll = LoadVector()
107 self.process.buildActions.decsAll.vectorKey = "dec"
109 # First, select "good" DiaSources that are not obvious garbage
110 self.process.buildActions.coordsGood = KeyedDataSelectorAction(vectorKeys=["ra", "dec"])
111 self.process.buildActions.coordsGood.selectors.selectorGood = GoodDiaSourceSelector()
113 # Second, select DiaSources with STREAK flag set in the footprint
114 self.process.buildActions.coordsStreak = KeyedDataSelectorAction(vectorKeys=["ra", "dec"])
115 self.process.buildActions.coordsStreak.selectors.selectorStreak = FlagSelector(
116 selectWhenTrue=["pixelFlags_streak"]
117 )
119 # Finally, select DiaSources with STREAK flag set in the source center
120 self.process.buildActions.coordsStreakCenter = KeyedDataSelectorAction(vectorKeys=["ra", "dec"])
121 self.process.buildActions.coordsStreakCenter.selectors.selectorStreakCenter = FlagSelector(
122 selectWhenTrue=["pixelFlags_streakCenter"]
123 )
125 # Use the DRP column names for all of the above, and generate the plot
126 self.applyContext(DrpContext)
127 self.produce.plot = DiaSkyPlot()
129 self.produce.plot.panels["panel_main"] = DiaSkyPanel()
130 self.produce.plot.panels["panel_main"].xlabel = "RA (deg)"
131 self.produce.plot.panels["panel_main"].ylabel = "Dec (deg)"
132 self.produce.plot.panels["panel_main"].subplot2gridRowspan = 10
133 self.produce.plot.panels["panel_main"].subplot2gridColspan = 10
134 self.produce.plot.panels["panel_main"].ras = [
135 "rasAll",
136 "coordsGood_ra",
137 "coordsStreak_ra",
138 "coordsStreakCenter_ra",
139 ]
140 self.produce.plot.panels["panel_main"].decs = [
141 "decsAll",
142 "coordsGood_dec",
143 "coordsStreak_dec",
144 "coordsStreakCenter_dec",
145 ]
146 self.produce.plot.panels["panel_main"].legendLabels = [
147 "All DiaSources",
148 "Good DiaSources",
149 "Streak footprint DiaSources",
150 "Streak center DiaSources",
151 ]
152 self.produce.plot.panels["panel_main"].rightSpinesVisible = False