Coverage for python/lsst/analysis/tools/atools/photometricRepeatability.py: 25%
44 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-04 11:09 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-04 11:09 +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__ = ("StellarPhotometricRepeatability",)
25from lsst.pex.config import Field
27from ..actions.plot.histPlot import HistPanel, HistPlot, HistStatsPanel
28from ..actions.scalar.scalarActions import CountAction, FracThreshold, MedianAction
29from ..actions.vector import (
30 BandSelector,
31 MagColumnNanoJansky,
32 MultiCriteriaDownselectVector,
33 PerGroupStatistic,
34 Sn,
35 ThresholdSelector,
36)
37from ..interfaces import AnalysisTool
40class StellarPhotometricRepeatability(AnalysisTool):
41 """Compute photometric repeatability from multiple measurements of a set of
42 stars. First, a set of per-source quality criteria are applied. Second,
43 the individual source measurements are grouped together by object index
44 and per-group quantities are computed (e.g., a representative S/N for the
45 group based on the median of associated per-source measurements). Third,
46 additional per-group criteria are applied. Fourth, summary statistics are
47 computed for the filtered groups.
48 """
50 fluxType = Field[str](doc="Flux type to calculate repeatability with", default="psfFlux")
51 PA2Value = Field[float](
52 doc="Used to compute the percent of individual measurements that deviate by more than PA2Value"
53 "from the mean of each measurement (PF1). Units of PA2Value are mmag.",
54 default=15.0,
55 )
57 def setDefaults(self):
58 super().setDefaults()
60 # Apply per-source selection criteria
61 self.prep.selectors.bandSelector = BandSelector()
63 # Compute per-group quantities
64 self.process.buildActions.perGroupSn = PerGroupStatistic()
65 self.process.buildActions.perGroupSn.buildAction = Sn(fluxType=f"{self.fluxType}")
66 self.process.buildActions.perGroupSn.func = "median"
67 self.process.buildActions.perGroupExtendedness = PerGroupStatistic()
68 self.process.buildActions.perGroupExtendedness.buildAction.vectorKey = "extendedness"
69 self.process.buildActions.perGroupExtendedness.func = "median"
70 self.process.buildActions.perGroupCount = PerGroupStatistic()
71 self.process.buildActions.perGroupCount.buildAction.vectorKey = f"{self.fluxType}"
72 self.process.buildActions.perGroupCount.func = "count"
73 # Use mmag units
74 self.process.buildActions.perGroupStdev = PerGroupStatistic()
75 self.process.buildActions.perGroupStdev.buildAction = MagColumnNanoJansky(
76 vectorKey=f"{self.fluxType}",
77 returnMillimags=True,
78 )
79 self.process.buildActions.perGroupStdev.func = "std"
81 # Filter on per-group quantities
82 self.process.filterActions.perGroupStdevFiltered = MultiCriteriaDownselectVector(
83 vectorKey="perGroupStdev"
84 )
85 self.process.filterActions.perGroupStdevFiltered.selectors.count = ThresholdSelector(
86 vectorKey="perGroupCount",
87 op="ge",
88 threshold=3,
89 )
90 self.process.filterActions.perGroupStdevFiltered.selectors.sn = ThresholdSelector(
91 vectorKey="perGroupSn",
92 op="ge",
93 threshold=200,
94 )
95 self.process.filterActions.perGroupStdevFiltered.selectors.extendedness = ThresholdSelector(
96 vectorKey="perGroupExtendedness",
97 op="le",
98 threshold=0.5,
99 )
101 # Compute summary statistics on filtered groups
102 self.process.calculateActions.photRepeatStdev = MedianAction(vectorKey="perGroupStdevFiltered")
103 self.process.calculateActions.photRepeatOutlier = FracThreshold(
104 vectorKey="perGroupStdevFiltered",
105 op="ge",
106 threshold=self.PA2Value,
107 percent=True,
108 )
109 self.process.calculateActions.photRepeatNsources = CountAction(vectorKey="perGroupStdevFiltered")
111 self.produce.plot = HistPlot()
113 self.produce.plot.panels["panel_rms"] = HistPanel()
115 self.produce.plot.panels["panel_rms"].statsPanel = HistStatsPanel()
116 self.produce.plot.panels["panel_rms"].statsPanel.statsLabels = ["N", "PA1", "PF1 %"]
117 self.produce.plot.panels["panel_rms"].statsPanel.stat1 = ["photRepeatNsources"]
118 self.produce.plot.panels["panel_rms"].statsPanel.stat2 = ["photRepeatStdev"]
119 self.produce.plot.panels["panel_rms"].statsPanel.stat3 = ["photRepeatOutlier"]
121 self.produce.plot.panels["panel_rms"].referenceValue = self.PA2Value
122 self.produce.plot.panels["panel_rms"].label = "rms (mmag)"
123 self.produce.plot.panels["panel_rms"].hists = dict(perGroupStdevFiltered="Filtered per group rms")
125 self.produce.metric.units = { # type: ignore
126 "photRepeatStdev": "mmag",
127 "photRepeatOutlier": "percent",
128 "photRepeatNsources": "ct",
129 }
130 self.produce.metric.newNames = {
131 "photRepeatStdev": "{band}_stellarPhotRepeatStdev",
132 "photRepeatOutlier": "{band}_stellarPhotRepeatOutlierFraction",
133 "photRepeatNsources": "{band}_ct",
134 }