Coverage for python/lsst/analysis/tools/atools/diaSourceMetrics.py: 48%
33 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 02:33 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 02:33 -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/>.
21from __future__ import annotations
23__all__ = (
24 "NumDiaSourcesMetric",
25 "NumDipolesMetric",
26 "NumDiaSourcesSelectionMetric",
27 "DiaSourcesGoodVsBadRatioMetric",
28)
30from lsst.pex.config import Field
32from ..actions.scalar import CountAction, DivideScalar
33from ..actions.vector import FlagSelector, GoodDiaSourceSelector
34from ..interfaces import AnalysisTool
37class NumDiaSourcesMetric(AnalysisTool):
38 """Calculate the number of DIA Sources that do not have known
39 bad/quality flags set to true.
40 """
42 def setDefaults(self):
43 super().setDefaults()
45 # select dia sources that do not have bad flags
46 self.prep.selectors.goodDiaSourceSelector = GoodDiaSourceSelector()
48 # Count the number of dia sources left after filtering
49 self.process.calculateActions.numDiaSources = CountAction(vectorKey="diaSourceId")
51 # the units for the quantity (count, an astropy quantity)
52 self.produce.metric.units = {"numDiaSources": "ct"}
55class NumDipolesMetric(AnalysisTool):
56 """Calculate the number of dipoles with NaN values excluded."""
58 def setDefaults(self):
59 super().setDefaults()
61 # select all diaSources flagged as dipole
62 self.prep.selectors.flags = FlagSelector(selectWhenTrue=["isDipole"])
64 # count the number of dipoles
65 self.process.buildActions.numDipoles = CountAction(vectorKey="isDipole")
67 # the units for the quantity (count, an astropy quantity)
68 self.produce.metric.units = {"numDipoles": "ct"}
71class NumDiaSourcesSelectionMetric(AnalysisTool):
72 """Count the number of DIA Sources for a given threshold."""
74 metricName = Field[str](doc="Name to use for output metric")
76 def setDefaults(self):
77 super().setDefaults()
79 # Count dia sources with reliability lower than the threshold
80 self.process.calculateActions.countingAction = CountAction
82 # The units for the quantity (count, an astropy quantity)
83 self.produce.metric.units = {"countingAction": "ct"}
85 def finalize(self):
86 self.produce.metric.newNames = {"countingAction": self.metricName}
89class DiaSourcesGoodVsBadRatioMetric(AnalysisTool):
90 """Calculate the ratio of 'good' vs 'bad' DIA Sources."""
92 def setDefaults(self):
93 super().setDefaults()
95 # Count dia sources with reliability higher than the threshold
96 self.process.buildActions.numDiaSourcesHighReliability = CountAction(
97 op="gt", threshold=0.9, vectorKey="reliability"
98 )
100 # Count dia sources with reliability lower than the threshold
101 self.process.buildActions.numDiaSourcesLowReliability = CountAction(
102 op="lt", threshold=0.1, vectorKey="reliability"
103 )
105 # Calculate ratio of good vs bad DIA Sources
106 self.process.calculateActions.DiaSourcesGoodVsBadRatio = DivideScalar(
107 actionA=self.process.buildActions.numDiaSourcesHighReliability,
108 actionB=self.process.buildActions.numDiaSourcesLowReliability,
109 )
111 # The units for the quantity (dimensionless, an astropy quantity)
112 self.produce.metric.units = {"DiaSourcesGoodVsBadRatio": ""}