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