Coverage for python/lsst/analysis/tools/atools/numericalValidity.py: 52%
23 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-04 03:35 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-04 03:35 -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__ = ("ValidFracColumnMetric",)
25from lsst.pex.config import Field
27from ..actions.scalar import FracInRange, FracNan
28from ..actions.vector import LoadVector
29from ..interfaces import AnalysisTool
32class ValidFracColumnMetric(AnalysisTool):
33 """Calculate the fraction of values in a column that have valid
34 numerical values (i.e., not NaN), and that fall within the specified
35 "reasonable" range for the values.
36 """
38 vectorKey = Field[str](doc="Key of column to validate", default="psfFlux")
40 def visitContext(self) -> None:
41 self.process.buildActions.loadVector = LoadVector()
42 self.process.buildActions.loadVector.vectorKey = f"{self.vectorKey}"
43 self._setActions(f"{self.vectorKey}")
45 def coaddContext(self) -> None:
46 self.process.buildActions.loadVector = LoadVector()
47 self.process.buildActions.loadVector.vectorKey = "{band}_" + f"{self.vectorKey}"
48 self._setActions("{band}_" + f"{self.vectorKey}")
50 # Need to pass a mapping of new names so the default names get the
51 # band prepended. Otherwise, each subsequent band's metric will
52 # overwrite the current one.
53 self.produce.metric.newNames = { # type: ignore
54 "validFracColumn": "{band}_validFracColumn",
55 "nanFracColumn": "{band}_nanFracColumn",
56 }
58 def _setActions(self, name: str) -> None:
59 # The default flux limits of 1e-1 < flux < 1e9 correspond to a
60 # magnitude range of 34 < mag < 9 (i.e., reasonably well-measured)
61 # objects should all be within this range).
62 self.process.calculateActions.validFracColumn = FracInRange(
63 vectorKey=name,
64 minimum=1.0e-1,
65 maximum=1.0e9,
66 percent=True,
67 )
68 self.process.calculateActions.nanFracColumn = FracNan(
69 vectorKey=name,
70 percent=True,
71 )
73 def setDefaults(self):
74 super().setDefaults()
76 self.produce.metric.units = {
77 "validFracColumn": "percent",
78 "nanFracColumn": "percent",
79 }