Coverage for python / lsst / analysis / tools / atools / calexpMetrics.py: 58%

24 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-22 09:32 +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 

22 

23__all__ = ( 

24 "CalexpSummaryMetrics", 

25 "CalexpMetricHists", 

26) 

27 

28from lsst.pex.config import DictField 

29 

30from ..actions.plot import HistPanel, HistPlot 

31from ..actions.vector import BandSelector, LoadVector 

32from ..interfaces import AnalysisTool 

33 

34 

35class CalexpSummaryMetrics(AnalysisTool): 

36 """ 

37 Class to load statistics from the summary stats contained with a calexp's 

38 metadata and write them to metrics. 

39 """ 

40 

41 propagateData: bool = True 

42 

43 # raCorners and decCorners statistics cannot be written to a metric, 

44 # as metrics can only be single-valued (i.e., scalars). 

45 # Units in comments are to indicate compound units, which are currently 

46 # unsupported. 

47 _units = { 

48 "psfSigma": "pixel", 

49 "psfArea": "", # pixel**2 

50 "psfIxx": "", # pixel**2 

51 "psfIyy": "", # pixel**2 

52 "psfIxy": "", # pixel**2 

53 "ra": "degree", 

54 "dec": "degree", 

55 "pixelScale": "", # arcsec/pixel. 

56 "zenithDistance": "degree", 

57 "expTime": "s", 

58 "zeroPoint": "mag", 

59 "skyBg": "electron", 

60 "skyNoise": "electron", 

61 "meanVar": "", # electron**2 

62 "astromOffsetMean": "arcsec", 

63 "astromOffsetStd": "arcsec", 

64 "nPsfStar": "ct", 

65 "psfStarDeltaE1Median": "", 

66 "psfStarDeltaE2Median": "", 

67 "psfStarDeltaE1Scatter": "", 

68 "psfStarDeltaE2Scatter": "", 

69 "psfStarDeltaSizeMedian": "pixel", 

70 "psfStarDeltaSizeScatter": "pixel", 

71 "psfStarScaledDeltaSizeScatter": "", 

72 "psfTraceRadiusDelta": "pixel", 

73 "psfApFluxDelta": "", 

74 "psfApCorrSigmaScaledDelta": "", 

75 "maxDistToNearestPsf": "pixel", 

76 "starEMedian": "", 

77 "starUnNormalizedEMedian": "", # pixel**2 

78 "effTime": "s", 

79 "effTimePsfSigmaScale": "", 

80 "effTimeSkyBgScale": "", 

81 "effTimeZeroPointScale": "", 

82 "magLim": "mag", 

83 } 

84 

85 def setDefaults(self): 

86 super().setDefaults() 

87 

88 self.prep.keysToLoad = list(self._units.keys()) 

89 self.produce.metric.units = self._units 

90 

91 

92class CalexpMetricHists(AnalysisTool): 

93 """ 

94 Class to generate histograms of metrics extracted from a Metrics Table. 

95 One plot per band. 

96 """ 

97 

98 parameterizedBand: bool = False 

99 metrics = DictField[str, str](doc="The metrics to plot and their respective labels.") 

100 

101 def setDefaults(self): 

102 super().setDefaults() 

103 

104 # Band is passed as a kwarg from the calling task. 

105 self.prep.selectors.bandSelector = BandSelector() 

106 self.produce.plot = HistPlot() 

107 

108 def finalize(self): 

109 

110 for metric, label in self.metrics.items(): 

111 setattr(self.process.buildActions, metric, LoadVector(vectorKey=metric)) 

112 self.produce.plot.panels[metric] = HistPanel(hists={metric: "Number of calexps"}, label=label)