Coverage for python / lsst / analysis / tools / atools / actionMagnitudeScatterPlot.py: 43%

39 statements  

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

21 

22from __future__ import annotations 

23 

24__all__ = ("ActionMagnitudeScatterPlot", "SingleColumnMagnitudeScatterPlot") 

25 

26import logging 

27 

28from lsst.pex.config import Field 

29from lsst.pex.config.configurableActions import ConfigurableActionField 

30 

31from ..actions.vector import DownselectVector, LoadVector 

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

33from ..interfaces import VectorAction 

34from .genericProduce import MagnitudeScatterPlot 

35 

36_LOG = logging.getLogger(__name__) 

37 

38 

39class ActionMagnitudeScatterPlot(MagnitudeScatterPlot): 

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

41 

42 action_vector = ConfigurableActionField[VectorAction]( 

43 default=None, 

44 doc="The VectorAction returning data to plot", 

45 ) 

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

47 

48 def coaddContext(self) -> None: 

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

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

51 

52 def visitContext(self) -> None: 

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

54 

55 def finalize(self): 

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

57 classes = self.get_classes() 

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

59 return 

60 super().finalize() 

61 self.validate() 

62 

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

64 setattr(self.process.buildActions, attr_column, self.action_vector) 

65 

66 for object_class in classes: 

67 setattr( 

68 self.process.filterActions, 

69 self.get_name_attr_values(object_class), 

70 DownselectVector( 

71 vectorKey=attr_column, 

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

73 ), 

74 ) 

75 

76 

77class SingleColumnMagnitudeScatterPlot(ActionMagnitudeScatterPlot): 

78 """A magnitude scatter plot loading a single column.""" 

79 

80 _default_vectorKey = "__SingleColumnMagnitudeScatterPlot__default" 

81 

82 def setDefaults(self): 

83 super().setDefaults() 

84 # Unfortunately, this can't be left None because validate will get 

85 # called before finalize 

86 self.action_vector = LoadVector(vectorKey=self._default_vectorKey) 

87 

88 def finalize(self): 

89 if not isinstance(self.action_vector, LoadVector): 

90 _LOG.warning( 

91 f"{self.action_vector=} should be an instance of LoadVector but is not; if it has no " 

92 f"vectorKey attribute, this action may fail." 

93 ) 

94 if self.action_vector.vectorKey == self._default_vectorKey: 

95 self.action_vector.vectorKey = self.key_y 

96 super().finalize()