Coverage for python/lsst/analysis/tools/analysisParts/shapeSizeFractional.py: 35%
46 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-07 02:34 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-07 02:34 -0800
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/>.
22from __future__ import annotations
24__all__ = (
25 "ShapeSizeFractionalScalars",
26 "BasePsfResidualMixin",
27)
29from lsst.pex.config import Field
30from lsst.pipe.tasks.configurableActions import ConfigurableActionField
32from ..actions.keyedData import KeyedScalars
33from ..actions.plot.scatterplotWithTwoHists import ScatterPlotStatsAction
34from ..actions.scalar import CountAction, MedianAction, SigmaMadAction
35from ..actions.vector import (
36 CalcE,
37 CalcEDiff,
38 CalcShapeSize,
39 CoaddPlotFlagSelector,
40 DownselectVector,
41 FractionalDifference,
42 MagColumnNanoJansky,
43 SnSelector,
44 StarSelector,
45 VectorSelector,
46)
47from ..interfaces import AnalysisTool, KeyedData, VectorAction
50class ShapeSizeFractionalScalars(KeyedScalars):
51 vectorKey = Field[str](doc="Column key to compute scalars")
53 snFluxType = Field[str](doc="column key for the flux type used in SN selection")
55 selector = ConfigurableActionField[VectorAction](doc="Selector to use before computing Scalars")
57 def setDefaults(self):
58 super().setDefaults()
59 self.scalarActions.median = MedianAction(vectorKey=self.vectorKey) # type: ignore
60 self.scalarActions.sigmaMad = SigmaMadAction(vectorKey=self.vectorKey) # type: ignore
61 self.scalarActions.count = CountAction(vectorKey=self.vectorKey) # type: ignore
62 self.scalarActions.approxMag = MedianAction(vectorKey=self.snFluxType) # type: ignore
64 def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
65 mask = kwargs.get("mask")
66 selection = self.selector(data, **kwargs)
67 if mask is not None:
68 mask &= selection
69 else:
70 mask = selection
71 return super().__call__(data, **kwargs | dict(mask=mask))
74class BasePsfResidualMixin(AnalysisTool):
75 """Shared configuration for `prep` and `process` stages of PSF residuals.
77 This is a mixin class used by `BasePsfResidualScatterPlot` and
78 `BasePsfResidualMetric` to share common default configuration.
79 """
81 def setDefaults(self):
82 super().setDefaults()
83 self.prep.selectors.flagSelector = CoaddPlotFlagSelector()
84 self.prep.selectors.snSelector = SnSelector(fluxType="{band}_psfFlux", threshold=100)
86 self.process.buildActions.mags = MagColumnNanoJansky(vectorKey="{band}_psfFlux")
87 self.process.buildActions.fracDiff = FractionalDifference(
88 actionA=CalcShapeSize(colXx="{band}_ixx", colYy="{band}_iyy", colXy="{band}_ixy"),
89 actionB=CalcShapeSize(colXx="{band}_ixxPSF", colYy="{band}_iyyPSF", colXy="{band}_ixyPSF"),
90 )
91 # Define an eDiff action and let e1Diff and e2Diff differ only in
92 # component.
93 self.process.buildActions.eDiff = CalcEDiff(
94 colA=CalcE(colXx="{band}_ixx", colYy="{band}_iyy", colXy="{band}_ixy"),
95 colB=CalcE(colXx="{band}_ixxPSF", colYy="{band}_iyyPSF", colXy="{band}_ixyPSF"),
96 )
97 self.process.buildActions.e1Diff = self.process.buildActions.eDiff
98 self.process.buildActions.e1Diff.component = "1"
99 self.process.buildActions.e2Diff = self.process.buildActions.eDiff
100 self.process.buildActions.e2Diff.component = "2"
101 # pre-compute a stellar selector mask so it can be used in the filter
102 # actions while only being computed once, alternatively the stellar
103 # selector could be calculated and applied twice in the filter stage
104 self.process.buildActions.starSelector = StarSelector()
106 self.process.filterActions.xStars = DownselectVector(
107 vectorKey="mags", selector=VectorSelector(vectorKey="starSelector")
108 )
109 # downselect the psfFlux as well
110 self.process.filterActions.psfFlux = DownselectVector(
111 vectorKey="{band}_psfFlux", selector=VectorSelector(vectorKey="starSelector")
112 )
113 self.process.filterActions.psfFluxErr = DownselectVector(
114 vectorKey="{band}_psfFluxErr", selector=VectorSelector(vectorKey="starSelector")
115 )
117 self.process.calculateActions.stars = ScatterPlotStatsAction(
118 vectorKey="yStars",
119 )
120 # use the downselected psfFlux
121 self.process.calculateActions.stars.highSNSelector.fluxType = "psfFlux"
122 self.process.calculateActions.stars.lowSNSelector.fluxType = "psfFlux"
123 self.process.calculateActions.stars.fluxType = "psfFlux"