Coverage for python/lsst/analysis/tools/atools/refCatMatchPlots.py: 27%
234 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-05 14:03 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-05 14:03 +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__ = (
24 "TargetRefCatDeltaRAScatterPlot",
25 "TargetRefCatDeltaDecScatterPlot",
26 "TargetRefCatDeltaRASkyPlot",
27 "TargetRefCatDeltaDecSkyPlot",
28 "TargetRefCatDeltaScatterPhotom",
29 "TargetRefCatDeltaScatterAstrom",
30 "TargetRefCatDeltaSkyPlotPhotom",
31 "TargetRefCatDeltaPsfScatterPlot",
32 "TargetRefCatDeltaCModelScatterPlot",
33 "TargetRefCatDeltaCModelSkyPlot",
34 "TargetRefCatDeltaPsfSkyPlot",
35 "TargetRefCatDeltaRASkyVisitPlot",
36 "TargetRefCatDeltaAp09ScatterVisitPlot",
37 "TargetRefCatDeltaPsfScatterVisitPlot",
38 "TargetRefCatDeltaAp09SkyVisitPlot",
39 "TargetRefCatDeltaPsfSkyVisitPlot",
40 "TargetRefCatDeltaDecSkyVisitPlot",
41 "TargetRefCatDeltaRAScatterVisitPlot",
42 "TargetRefCatDeltaDecScatterVisitPlot",
43)
45from lsst.pex.config import Field
47from ..actions.plot.scatterplotWithTwoHists import ScatterPlotStatsAction, ScatterPlotWithTwoHists
48from ..actions.plot.skyPlot import SkyPlot
49from ..actions.vector import (
50 CoaddPlotFlagSelector,
51 ConvertFluxToMag,
52 ConvertUnits,
53 LoadVector,
54 MagDiff,
55 RAcosDec,
56 SnSelector,
57 StarSelector,
58 SubtractVector,
59 VisitPlotFlagSelector,
60)
61from ..contexts import CoaddContext, RefMatchContext, VisitContext
62from ..interfaces import AnalysisTool
65class TargetRefCatDelta(AnalysisTool):
66 """Plot the difference between a target catalog and a
67 reference catalog for the quantity set in `setDefaults`.
68 """
70 parameterizedBand = Field[bool](
71 doc="Does this AnalysisTool support band as a name parameter", default=True
72 )
74 def coaddContext(self) -> None:
75 """Apply coadd options for the ref cat plots.
76 Applies the coadd plot flag selector and sets
77 flux types.
78 """
79 self.prep.selectors.flagSelector = CoaddPlotFlagSelector()
80 self.prep.selectors.snSelector.fluxType = "{band}_psfFlux_target"
81 self.prep.selectors.snSelector.threshold = 200
82 self.prep.selectors.starSelector.vectorKey = "{band}_extendedness_target"
83 self.process.buildActions.starStatMask = SnSelector()
84 self.process.buildActions.starStatMask.fluxType = "{band}_psfFlux_target"
85 self.process.buildActions.patch = LoadVector()
86 self.process.buildActions.patch.vectorKey = "patch_target"
88 def visitContext(self) -> None:
89 """Apply visit options for the ref cat plots.
90 Applies the visit plot flag selector and sets
91 the flux types.
92 """
93 self.parameterizedBand = False
94 self.prep.selectors.flagSelector = VisitPlotFlagSelector()
95 self.prep.selectors.starSelector.vectorKey = "extendedness_target"
96 self.prep.selectors.snSelector.fluxType = "psfFlux_target"
97 self.prep.selectors.snSelector.threshold = 50
99 self.process.buildActions.starStatMask = SnSelector()
100 self.process.buildActions.starStatMask.fluxType = "psfFlux_target"
101 self.process.buildActions.starStatMask.threshold = 200
103 def setDefaults(self):
104 super().setDefaults()
106 self.prep.selectors.snSelector = SnSelector()
107 self.prep.selectors.starSelector = StarSelector()
110class TargetRefCatDeltaScatterAstrom(TargetRefCatDelta):
111 """Plot the difference in milliseconds between a target catalog and a
112 reference catalog for the coordinate set in `setDefaults`. Plot it on
113 a scatter plot.
114 """
116 def setDefaults(self):
117 super().setDefaults()
119 self.process.buildActions.yStars = ConvertUnits(
120 buildAction=SubtractVector, inUnit="degree", outUnit="milliarcsecond"
121 )
122 self.process.buildActions.xStars = ConvertFluxToMag()
123 self.process.buildActions.xStars.vectorKey = "{band}_psfFlux_target"
124 self.process.calculateActions.stars = ScatterPlotStatsAction(vectorKey="yStars")
125 self.process.calculateActions.stars.lowSNSelector.fluxType = "{band}_psfFlux_target"
126 self.process.calculateActions.stars.highSNSelector.fluxType = "{band}_psfFlux_target"
127 self.process.calculateActions.stars.fluxType = "{band}_psfFlux_target"
129 self.produce = ScatterPlotWithTwoHists()
130 self.produce.plotTypes = ["stars"]
131 self.produce.magLabel = "PSF Magnitude (mag)"
132 self.produce.xAxisLabel = "PSF Magnitude (mag)"
133 self.applyContext(CoaddContext)
134 self.applyContext(RefMatchContext)
137class TargetRefCatDeltaScatterAstromVisit(TargetRefCatDelta):
138 """Plot the difference in milliseconds between a target catalog and a
139 reference catalog for the coordinate set in `setDefaults`. Plot it on
140 a scatter plot.
141 """
143 def setDefaults(self):
144 super().setDefaults()
146 self.process.buildActions.yStars = ConvertUnits(
147 buildAction=SubtractVector, inUnit="degree", outUnit="milliarcsecond"
148 )
149 self.process.buildActions.xStars = ConvertFluxToMag()
150 self.process.buildActions.xStars.vectorKey = "psfFlux_target"
151 self.process.calculateActions.stars = ScatterPlotStatsAction(vectorKey="yStars")
152 self.process.calculateActions.stars.lowSNSelector.fluxType = "psfFlux_target"
153 self.process.calculateActions.stars.highSNSelector.fluxType = "psfFlux_target"
154 self.process.calculateActions.stars.fluxType = "psfFlux_target"
156 self.produce = ScatterPlotWithTwoHists()
157 self.produce.addSummaryPlot = False
158 self.produce.plotTypes = ["stars"]
159 self.produce.magLabel = "PSF Magnitude (mag)"
160 self.produce.xAxisLabel = "PSF Magnitude (mag)"
161 self.applyContext(VisitContext)
162 self.applyContext(RefMatchContext)
165class TargetRefCatDeltaScatterPhotom(TargetRefCatDelta):
166 """Plot the difference in millimags between a target catalog and a
167 reference catalog for the flux type set in `setDefaults`.
168 """
170 def setDefaults(self):
171 super().setDefaults()
173 self.process.buildActions.yStars = MagDiff()
174 self.process.buildActions.yStars.col2 = "{band}_mag_ref"
175 self.process.buildActions.yStars.fluxUnits2 = "mag(AB)"
177 self.process.buildActions.xStars = ConvertFluxToMag()
178 self.process.buildActions.xStars.vectorKey = "{band}_psfFlux_target"
180 self.process.calculateActions.stars = ScatterPlotStatsAction(vectorKey="yStars")
181 self.process.calculateActions.stars.lowSNSelector.fluxType = "{band}_psfFlux_target"
182 self.process.calculateActions.stars.highSNSelector.fluxType = "{band}_psfFlux_target"
183 self.process.calculateActions.stars.fluxType = "{band}_psfFlux_target"
185 self.produce = ScatterPlotWithTwoHists()
186 self.produce.plotTypes = ["stars"]
187 self.produce.magLabel = "PSF Magnitude (mag)"
188 self.produce.xAxisLabel = "PSF Magnitude (mag)"
189 self.produce.yAxisLabel = "Output Mag - Ref Mag (mmag)"
190 self.applyContext(CoaddContext)
191 self.applyContext(RefMatchContext)
194class TargetRefCatDeltaScatterPhotomVisit(TargetRefCatDelta):
195 """Plot the difference in millimags between a target catalog and a
196 reference catalog for the flux type set in `setDefaults`.
197 """
199 def setDefaults(self):
200 super().setDefaults()
202 self.process.buildActions.yStars = MagDiff()
203 self.process.buildActions.yStars.col2 = "mag_ref"
204 self.process.buildActions.yStars.fluxUnits2 = "mag(AB)"
206 self.process.buildActions.xStars = ConvertFluxToMag()
207 self.process.buildActions.xStars.vectorKey = "psfFlux_target"
209 self.process.calculateActions.stars = ScatterPlotStatsAction(vectorKey="yStars")
210 self.process.calculateActions.stars.lowSNSelector.fluxType = "psfFlux_target"
211 self.process.calculateActions.stars.highSNSelector.fluxType = "psfFlux_target"
212 self.process.calculateActions.stars.fluxType = "psfFlux_target"
214 self.produce = ScatterPlotWithTwoHists()
215 self.produce.addSummaryPlot = False
216 self.produce.plotTypes = ["stars"]
217 self.produce.magLabel = "PSF Magnitude (mag)"
218 self.produce.xAxisLabel = "PSF Magnitude (mag)"
219 self.produce.yAxisLabel = "Output Mag - Ref Mag (mmag)"
220 self.applyContext(VisitContext)
221 self.applyContext(RefMatchContext)
224class TargetRefCatDeltaPsfScatterPlot(TargetRefCatDeltaScatterPhotom):
225 """Plot the difference in millimags between the PSF flux
226 of a target catalog and a reference catalog
227 """
229 def setDefaults(self):
230 super().setDefaults()
232 self.process.buildActions.yStars.col1 = "{band}_psfFlux_target"
235class TargetRefCatDeltaCModelScatterPlot(TargetRefCatDeltaScatterPhotom):
236 """Plot the difference in millimags between the CModel flux
237 of a target catalog and a reference catalog.
238 """
240 def setDefaults(self):
241 super().setDefaults()
243 self.process.buildActions.yStars.col1 = "{band}_cModelFlux_target"
246class TargetRefCatDeltaPsfScatterVisitPlot(TargetRefCatDeltaScatterPhotomVisit):
247 """Plot the difference in millimags between the PSF flux
248 of a target catalog and a reference catalog
249 """
251 def setDefaults(self):
252 super().setDefaults()
254 self.process.buildActions.yStars.col1 = "psfFlux_target"
257class TargetRefCatDeltaAp09ScatterVisitPlot(TargetRefCatDeltaScatterPhotomVisit):
258 """Plot the difference in millimags between the aper 09 flux
259 of a target catalog and a reference catalog.
260 """
262 def setDefaults(self):
263 super().setDefaults()
265 self.process.buildActions.yStars.col1 = "ap09Flux_target"
268class TargetRefCatDeltaRAScatterPlot(TargetRefCatDeltaScatterAstrom):
269 """Plot the difference in milliseconds between the RA of a target catalog
270 and a reference catalog
271 """
273 def setDefaults(self):
274 super().setDefaults()
275 self.process.buildActions.yStars.buildAction.actionA = RAcosDec(
276 raKey="coord_ra_target", decKey="coord_dec_target"
277 )
278 self.process.buildActions.yStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref")
280 self.produce.yAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)"
283class TargetRefCatDeltaRAScatterVisitPlot(TargetRefCatDeltaScatterAstromVisit):
284 """Plot the difference in milliseconds between the RA of a target catalog
285 and a reference catalog
286 """
288 def setDefaults(self):
289 super().setDefaults()
290 self.process.buildActions.yStars.buildAction.actionA = RAcosDec(
291 raKey="coord_ra_target", decKey="coord_dec_target"
292 )
293 self.process.buildActions.yStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref")
295 self.produce.yAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)"
298class TargetRefCatDeltaDecScatterVisitPlot(TargetRefCatDeltaScatterAstromVisit):
299 """Plot the difference in milliseconds between the Decs of a target catalog
300 and a reference catalog
301 """
303 def setDefaults(self):
304 super().setDefaults()
305 self.process.buildActions.yStars.buildAction.actionA = LoadVector(vectorKey="coord_dec_target")
306 self.process.buildActions.yStars.buildAction.actionB = LoadVector(vectorKey="dec_ref")
308 self.produce.yAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)"
311class TargetRefCatDeltaDecScatterPlot(TargetRefCatDeltaScatterAstrom):
312 """Plot the difference in milliseconds between the Dec of a target catalog
313 and a reference catalog
314 """
316 def setDefaults(self):
317 super().setDefaults()
318 self.process.buildActions.yStars.buildAction.actionA = LoadVector(vectorKey="coord_dec_target")
319 self.process.buildActions.yStars.buildAction.actionB = LoadVector(vectorKey="dec_ref")
321 self.produce.yAxisLabel = "Dec$_{{target}}$ - Dec$_{{ref}}$ (marcsec)"
324class TargetRefCatDeltaSkyPlot(TargetRefCatDelta):
325 """Base class for plotting the RA/Dec distribution of stars, with the
326 difference of the quantity defined in the vector key parameter between
327 the target and reference catalog as the color.
328 """
330 parameterizedBand = Field[bool](
331 doc="Does this AnalysisTool support band as a name parameter", default=True
332 )
334 def setDefaults(self):
335 super().setDefaults()
337 self.process.buildActions.xStars = LoadVector()
338 self.process.buildActions.xStars.vectorKey = "coord_ra_target"
339 self.process.buildActions.yStars = LoadVector()
340 self.process.buildActions.yStars.vectorKey = "coord_dec_target"
342 self.produce = SkyPlot()
343 self.produce.plotTypes = ["stars"]
344 self.produce.xAxisLabel = "R.A. (degrees)"
345 self.produce.yAxisLabel = "Dec. (degrees)"
346 self.produce.plotOutlines = False
349class TargetRefCatDeltaSkyPlotAstrom(TargetRefCatDeltaSkyPlot):
350 """Base class for plotting the RA/Dec distribution of stars, with the
351 difference between the RA or Dec of the target and reference catalog as
352 the color.
353 """
355 def setDefaults(self):
356 super().setDefaults()
358 self.process.buildActions.zStars = ConvertUnits(
359 buildAction=SubtractVector, inUnit="degree", outUnit="milliarcsecond"
360 )
362 self.applyContext(CoaddContext)
363 self.applyContext(RefMatchContext)
365 self.process.buildActions.starStatMask.fluxType = "{band}_psfFlux_target"
368class TargetRefCatDeltaSkyPlotAstromVisit(TargetRefCatDeltaSkyPlot):
369 """Base class for plotting the RA/Dec distribution of stars at
370 the visit level, with the difference between the RA or Dec of
371 the target and reference catalog as the color.
372 """
374 def setDefaults(self):
375 super().setDefaults()
377 self.process.buildActions.zStars = ConvertUnits(
378 buildAction=SubtractVector, inUnit="degree", outUnit="milliarcsecond"
379 )
381 self.applyContext(VisitContext)
382 self.applyContext(RefMatchContext)
385class TargetRefCatDeltaSkyPlotPhotomVisit(TargetRefCatDeltaSkyPlot):
386 """Base class for plotting the RA/Dec distribution of stars, with the
387 difference between the photometry of the target and reference catalog as
388 the color.
389 """
391 def setDefaults(self):
392 super().setDefaults()
394 self.process.buildActions.zStars = MagDiff()
395 self.process.buildActions.zStars.col2 = "mag_ref"
396 self.process.buildActions.zStars.fluxUnits2 = "mag(AB)"
398 self.produce.plotName = "photomDiffSky"
399 self.produce.zAxisLabel = "Output Mag - Ref Mag (mmag)"
400 self.applyContext(VisitContext)
401 self.applyContext(RefMatchContext)
404class TargetRefCatDeltaSkyPlotPhotom(TargetRefCatDeltaSkyPlot):
405 """Base class for plotting the RA/Dec distribution of stars, with the
406 difference between the photometry of the target and reference catalog as
407 the color.
408 """
410 def setDefaults(self):
411 super().setDefaults()
413 self.process.buildActions.zStars = MagDiff()
414 self.process.buildActions.zStars.col2 = "{band}_mag_ref"
415 self.process.buildActions.zStars.fluxUnits2 = "mag(AB)"
417 self.produce.plotName = "photomDiffSky_{band}"
418 self.produce.zAxisLabel = "Output Mag - Ref Mag (mmag)"
419 self.applyContext(CoaddContext)
420 self.applyContext(RefMatchContext)
423class TargetRefCatDeltaPsfSkyPlot(TargetRefCatDeltaSkyPlotPhotom):
424 """Plot the RA/Dec distribution of stars, with the
425 difference between the PSF photometry of the target and reference
426 catalog as the color.
427 """
429 def setDefaults(self):
430 super().setDefaults()
432 self.process.buildActions.zStars.col1 = "{band}_psfFlux_target"
435class TargetRefCatDeltaPsfSkyVisitPlot(TargetRefCatDeltaSkyPlotPhotomVisit):
436 """Plot the RA/Dec distribution of stars, with the
437 difference between the PSF photometry of the target and reference
438 catalog as the color.
439 """
441 def setDefaults(self):
442 super().setDefaults()
444 self.process.buildActions.zStars.col1 = "psfFlux_target"
447class TargetRefCatDeltaAp09SkyVisitPlot(TargetRefCatDeltaSkyPlotPhotomVisit):
448 """Plot the RA/Dec distribution of stars, with the
449 difference between the Ap09 photometry of the target and reference
450 catalog as the color.
451 """
453 def setDefaults(self):
454 super().setDefaults()
456 self.process.buildActions.zStars.col1 = "ap09Flux_target"
459class TargetRefCatDeltaCModelSkyPlot(TargetRefCatDeltaSkyPlotPhotom):
460 """Plot the RA/Dec distribution of stars, with the
461 difference between the CModel photometry of the target and reference
462 catalog as the color.
463 """
465 def setDefaults(self):
466 super().setDefaults()
468 self.process.buildActions.zStars.col1 = "{band}_cModelFlux_target"
471class TargetRefCatDeltaRASkyPlot(TargetRefCatDeltaSkyPlotAstrom):
472 """Plot the RA/Dec distribution of stars, with the
473 difference between the RA of the target and reference catalog as
474 the color.
475 """
477 def setDefaults(self):
478 super().setDefaults()
479 self.process.buildActions.zStars.buildAction.actionA = RAcosDec(
480 raKey="coord_ra_target", decKey="coord_dec_target"
481 )
482 self.process.buildActions.zStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref")
484 self.produce.plotName = "astromDiffSky_RA"
485 self.produce.zAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)"
488class TargetRefCatDeltaRASkyVisitPlot(TargetRefCatDeltaSkyPlotAstromVisit):
489 """Plot the RA/Dec distribution of stars, with the
490 difference between the RA of the target and reference catalog as
491 the color.
492 """
494 def setDefaults(self):
495 super().setDefaults()
496 self.process.buildActions.zStars.buildAction.actionA = RAcosDec(
497 raKey="coord_ra_target", decKey="coord_dec_target"
498 )
499 self.process.buildActions.zStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref")
500 self.produce.plotName = "astromDiffSky_RA"
501 self.produce.zAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)"
504class TargetRefCatDeltaDecSkyVisitPlot(TargetRefCatDeltaSkyPlotAstromVisit):
505 """Plot the RA/Dec distribution of stars, with the
506 difference between the RA of the target and reference catalog as
507 the color.
508 """
510 def setDefaults(self):
511 super().setDefaults()
512 self.process.buildActions.zStars.buildAction.actionA = LoadVector(vectorKey="coord_dec_target")
513 self.process.buildActions.zStars.buildAction.actionB = LoadVector(vectorKey="dec_ref")
515 self.produce.plotName = "astromDiffSky_Dec"
516 self.produce.zAxisLabel = "Dec$_{{target}}$ - Dec$_{{ref}}$ (marcsec)"
519class TargetRefCatDeltaDecSkyPlot(TargetRefCatDeltaSkyPlotAstrom):
520 """Plot the RA/Dec distribution of stars, with the
521 difference between the Dec of the target and reference catalog as
522 the color.
523 """
525 def setDefaults(self):
526 super().setDefaults()
527 self.process.buildActions.zStars.buildAction.actionA = LoadVector(vectorKey="coord_dec_target")
528 self.process.buildActions.zStars.buildAction.actionB = LoadVector(vectorKey="dec_ref")
530 self.produce.plotName = "astromDiffSky_Dec"
531 self.produce.zAxisLabel = "Dec$_{{target}}$ - Dec$_{{ref}}$ (marcsec)"