Coverage for python/lsst/analysis/tools/atools/genericProduce.py: 13%

44 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-05 14:05 +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__ = ("MagnitudeScatterPlot",) 

24 

25from ..actions.plot.scatterplotWithTwoHists import ScatterPlotStatsAction, ScatterPlotWithTwoHists 

26from ..actions.vector.vectorActions import DownselectVector, VectorSelector 

27from .genericBuild import MagnitudeXTool 

28 

29 

30class MagnitudeScatterPlot(MagnitudeXTool): 

31 """A scatter plot with a magnitude on the x-axis.""" 

32 

33 def setDefaults(self): 

34 super().setDefaults() 

35 

36 # init with placeholders 

37 self.produce.plot = ScatterPlotWithTwoHists(xAxisLabel="", yAxisLabel="", magLabel="") 

38 self.produce.plot.plotTypes = ["galaxies", "stars"] 

39 self.produce.plot.addSummaryPlot = False 

40 

41 def finalize(self): 

42 super().finalize() 

43 config_x = self.config_mag_x 

44 label_x = f"{config_x.name_flux} (mag)" 

45 # Hacky way to check if setup is complete 

46 if self.produce.plot.xAxisLabel == label_x: 

47 return 

48 self.produce.plot.xAxisLabel = label_x 

49 self.produce.plot.magLabel = self.produce.plot.xAxisLabel 

50 

51 # Can't compute S/N of magnitude with no errors (e.g. true mag) 

52 # Try to find another or give up 

53 key_err = config_x.key_flux_error 

54 if key_err is None: 

55 for key, config in self.fluxes.items(): 

56 if config.key_flux_error is not None: 

57 key_err = key 

58 break 

59 # Try to add PSF flux if all else fails 

60 if key_err is None: 

61 config_err = self.fluxes_default.psf_err 

62 key_err = config_err.key_flux_error 

63 self.fluxes["flux_sn"] = config_err 

64 else: 

65 key_err = self.mag_x 

66 

67 keys_filter = [("", "flux_", self.mag_x), ("Err", "flux_err_", key_err)] 

68 if key_err != self.mag_x: 

69 keys_filter.append(("", "flux_", key_err)) 

70 

71 for prefix, plural in (("star", "Stars"), ("galaxy", "Galaxies")): 

72 for suffix, prefix_vec, key in keys_filter: 

73 setattr( 

74 self.process.filterActions, 

75 f"{prefix}_{key}_flux{suffix}", 

76 DownselectVector( 

77 vectorKey=f"{prefix_vec}{key}", 

78 selector=VectorSelector(vectorKey=f"{prefix}Selector"), 

79 ), 

80 ) 

81 

82 statAction = ScatterPlotStatsAction(vectorKey=f"y{plural.capitalize()}") 

83 fluxType = f"{prefix}_{key_err}_flux" 

84 statAction.highSNSelector.fluxType = fluxType 

85 statAction.highSNSelector.threshold = 200 

86 statAction.lowSNSelector.fluxType = fluxType 

87 statAction.lowSNSelector.threshold = 10 

88 statAction.fluxType = fluxType 

89 setattr(self.process.calculateActions, plural, statAction)