Coverage for python / lsst / analysis / tools / atools / columnMagnitudeScatterPlot.py: 46%

49 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-08 01:16 -0700

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/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ("ColumnMagnitudeScatterPlot",) 

25 

26import logging 

27 

28from deprecated.sphinx import deprecated 

29 

30from lsst.pex.config import Field 

31 

32from ..actions.vector import DownselectVector, LoadVector, Log10Vector 

33from ..actions.vector.selectors import CoaddPlotFlagSelector, VectorSelector, VisitPlotFlagSelector 

34from .genericProduce import MagnitudeScatterPlot 

35 

36logging.basicConfig() 

37_LOG = logging.getLogger(__name__) 

38_LOG.setLevel(logging.WARNING) 

39 

40 

41class ColumnMagnitudeScatterPlot(MagnitudeScatterPlot): 

42 """A MagnitudeScatterPlot with a single column value on the y axis.""" 

43 

44 _parameterizedBand: bool = True 

45 

46 # TODO: Remove the getter and setting in DM-54864. 

47 # Instead, just convert _parameterizedBand to parameterizedBand. 

48 @property 

49 def parameterizedBand(self) -> bool: 

50 return self._parameterizedBand 

51 

52 @parameterizedBand.setter 

53 def parameterizedBand(self, value: bool) -> None: 

54 _LOG.info( 

55 "Setting 'parameterizedBand' of a `ColumnMagnitudeScatterPlot' is a no-op. " 

56 "If you see this message, it is likely because you are trying " 

57 "to read older version of configs with newer versions of the " 

58 "LSST Science Pipelines." 

59 ) 

60 

61 # TODO: Remove the getter and setter in DM-54864. 

62 @property 

63 @deprecated(reason="This is no longer used.", version="v31") 

64 def extendedness(self) -> None: 

65 """A config-like attribute for backward compatibility. 

66 

67 This does not do anything but enable reading old configs. 

68 """ 

69 

70 @extendedness.setter 

71 def extendedness(self, value: str) -> None: 

72 _LOG.info( 

73 "Setting 'extendedness' of a `ColumnMagnitudeScatterPlot' is a no-op. " 

74 "If you see this message, it is likely because you are trying " 

75 "to read older version of configs with newer versions of the " 

76 "LSST Science Pipelines." 

77 ) 

78 

79 key_y = Field[str](default=None, doc="Key of column to plot on the y axis") 

80 log10_y = Field[bool](default=False, doc="Whether to plot log10 of the values on the y axis") 

81 

82 def coaddContext(self) -> None: 

83 self.prep.selectors.flagSelector = CoaddPlotFlagSelector() 

84 self.prep.selectors.flagSelector.bands = [] 

85 

86 def visitContext(self) -> None: 

87 self.prep.selectors.flagSelector = VisitPlotFlagSelector() 

88 

89 def finalize(self): 

90 # A lazy check for whether finalize has already been called 

91 classes = self.get_classes() 

92 if hasattr(self.process.filterActions, self.get_name_attr_values(classes[0])): 

93 return 

94 super().finalize() 

95 if not self.key_y: 

96 raise ValueError("Must specify key to plot on y axis") 

97 

98 action = LoadVector(vectorKey=self.key_y) 

99 if self.log10_y: 

100 action = Log10Vector(action=action) 

101 

102 attr_column = f"get_{self.key_y}" 

103 setattr(self.process.buildActions, attr_column, action) 

104 

105 classes = self.get_classes() 

106 for object_class in classes: 

107 setattr( 

108 self.process.filterActions, 

109 self.get_name_attr_values(object_class), 

110 DownselectVector( 

111 vectorKey=attr_column, 

112 selector=VectorSelector(vectorKey=self.get_name_attr_selector(object_class)), 

113 ), 

114 ) 

115 

116 if not self.produce.plot.yAxisLabel: 

117 self.produce.plot.yAxisLabel = f"log10({self.key_y})" if self.log10_y else self.key_y