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

32 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-07 08:53 +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__ = ("ColumnMagnitudeScatterPlot",) 

25 

26from lsst.pex.config import Field 

27 

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

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

30from .genericBuild import ExtendednessTool 

31from .genericProduce import MagnitudeScatterPlot 

32 

33 

34class ColumnMagnitudeScatterPlot(ExtendednessTool, MagnitudeScatterPlot): 

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

36 

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

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

39 

40 def coaddContext(self) -> None: 

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

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

43 

44 def visitContext(self) -> None: 

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

46 

47 def finalize(self): 

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

49 classes = self.get_classes() 

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

51 return 

52 super().finalize() 

53 if not self.key_y: 

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

55 

56 action = LoadVector(vectorKey=self.key_y) 

57 if self.log10_y: 

58 action = Log10Vector(action=action) 

59 

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

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

62 

63 classes = self.get_classes() 

64 for object_class in classes: 

65 setattr( 

66 self.process.filterActions, 

67 self.get_name_attr_values(object_class), 

68 DownselectVector( 

69 vectorKey=attr_column, 

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

71 ), 

72 ) 

73 

74 if not self.produce.plot.yAxisLabel: 

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