Coverage for python/lsst/analysis/tools/atools/skyFluxStatisticMetrics.py: 50%
26 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-24 09:44 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-24 09:44 +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/>.
21from __future__ import annotations
23__all__ = ("SkyFluxStatisticMetric",)
25from lsst.pex.config import Field
27from ..actions.scalar.scalarActions import MeanAction, MedianAction, SigmaMadAction, StdevAction
28from ..actions.vector.selectors import SkyObjectSelector, SkySourceSelector
29from ..interfaces import AnalysisTool
32class SkyFluxStatisticMetric(AnalysisTool):
33 """Calculate sky flux statistics. This uses the 9-pixel aperture flux for
34 sky sources/objects, and returns multiple statistics on the measured
35 fluxes. Note that either visitContext (measurement on sourceTable) or
36 coaddContext (measurement on objectTable) must be specified.
37 """
39 fluxType = Field[str](doc="Key to use to retrieve flux column", default="ap09Flux")
41 def visitContext(self) -> None:
42 self.prep.selectors.skySourceSelector = SkySourceSelector()
44 def coaddContext(self) -> None:
45 self.prep.selectors.skyObjectSelector = SkyObjectSelector()
46 self.prep.selectors.skyObjectSelector.bands = []
47 self.fluxType = f"{{band}}_{self.fluxType}"
49 # Need to pass a mapping of new names so the default names get the
50 # band prepended. Otherwise, each subsequent band's metric will
51 # overwrite the current one (e.g., running with g, r bands without
52 # this, you would get "meanSky," "meanSky"; with it: "g_meanSky,"
53 # "r_meanSky").
54 self.produce.metric.newNames = { # type: ignore
55 "medianSky": "{band}_medianSky",
56 "meanSky": "{band}_meanSky",
57 "stdevSky": "{band}_stdevSky",
58 "sigmaMADSky": "{band}_sigmaMADSky",
59 }
61 def _setActions(self, name: str) -> None:
62 self.process.calculateActions.medianSky = MedianAction(vectorKey=name)
63 self.process.calculateActions.meanSky = MeanAction(vectorKey=name)
64 self.process.calculateActions.stdevSky = StdevAction(vectorKey=name)
65 self.process.calculateActions.sigmaMADSky = SigmaMadAction(vectorKey=name)
67 def finalize(self) -> None:
68 super().finalize()
69 self._setActions(self.fluxType)
71 def setDefaults(self):
72 super().setDefaults()
74 self.produce.metric.units = {
75 "medianSky": "nJy",
76 "meanSky": "nJy",
77 "stdevSky": "nJy",
78 "sigmaMADSky": "nJy",
79 }