Coverage for python/lsst/meas/extensions/multiprofit/analysis_tools.py: 83%

51 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-10 09:46 +0000

1# This file is part of meas_extensions_multiprofit. 

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 

22 

23try: 

24 from lsst.analysis.tools.atools.genericBuild import FluxConfig, MomentsConfig, SizeConfig 

25 from lsst.analysis.tools.atools.sizeMagnitude import SizeMagnitudePlot 

26 from lsst.analysis.tools.contexts import CoaddContext 

27 

28 has_atools = True 

29except ImportError: 

30 has_atools = False 

31 

32from .pipetasks_fit import ( 

33 MultiProFitCoaddDeVFitConfig, 

34 MultiProFitCoaddExpDeVFitConfig, 

35 MultiProFitCoaddExpFitConfig, 

36 MultiProFitCoaddSersicFitConfig, 

37 component_names_default, 

38) 

39 

40if has_atools: 40 ↛ exitline 40 didn't exit the module because the condition on line 40 was always true

41 moments_sersic = MomentsConfig(xx="reff_x", yy="reff_y", xy="rho") 

42 

43 class MultiProFitSizeMagnitudePlot(SizeMagnitudePlot): 

44 """A size-magnitude plot with default MultiProFit column names.""" 

45 

46 def _get_flags_default(self, name_model: str): 

47 """Get the default MultiProFit flags for a given model. 

48 

49 Parameters 

50 ---------- 

51 name_model 

52 The short name of the model in table columns. 

53 

54 Returns 

55 ------- 

56 flags_false 

57 The flags that must be false for the fit to be good. 

58 flags_true 

59 The flags that must be true for the fit to be good. 

60 """ 

61 flags_false = [ 

62 f"mpf_{name_model}_{flag}_flag" for flag in ("unknown", "is_parent", "not_primary", "psf_fit") 

63 ] 

64 flags_true = [] 

65 return flags_false, flags_true 

66 

67 def _set_model_defaults( 

68 self, name_model: str, label_model: str, name_component: str, label_component: str 

69 ) -> None: 

70 """Set default values for a given model. 

71 

72 Parameters 

73 ---------- 

74 name_model 

75 The short name of the model in table columns. 

76 label_model 

77 The label for the model in plots. 

78 name_component 

79 The shortname of the component in table columns. 

80 label_component 

81 The label for the component in plots. 

82 """ 

83 flags_false, flags_true = self._get_flags_default(name_model) 

84 self.prep.selectors.flagSelector.selectWhenFalse = flags_false 

85 self.prep.selectors.flagSelector.selectWhenTrue = flags_true 

86 

87 name_full = f"{name_model}_{name_component}" 

88 flux_config = FluxConfig( 

89 key_flux=f"mpf_{name_full}_{{band}}_flux", 

90 key_flux_error=f"mpf_{name_full}_{{band}}_flux_err", 

91 name_flux=label_model, 

92 name_flux_short=name_model, 

93 ) 

94 size_config = SizeConfig( 

95 key_size=f"mpf_{name_full}_{{suffix}}", 

96 name_size=f"{label_component} {'$R_{eff}$'}", 

97 ) 

98 self.fluxes = {name_full: flux_config} 

99 self.mag_x = name_full 

100 self.sizes = {name_full: size_config} 

101 self.size_y = name_full 

102 

103 def setDefaults(self): 

104 super().setDefaults() 

105 self.applyContext(CoaddContext) 

106 self.size_type = "determinantRadius" 

107 self.is_covariance = False 

108 self.produce.plot.xLims = (17, 29) 

109 self.produce.plot.yLims = (-4, 3) 

110 

111 class MultiProFitExpDevSizeMagnitudePlot(MultiProFitSizeMagnitudePlot): 

112 """A size-magnitude plot for the MultiProFit Exp.Dev. model.""" 

113 

114 def setDefaults(self): 

115 super().setDefaults() 

116 self.config_moments = moments_sersic 

117 

118 class MultiProFitExpDevBulgeSizeMagnitudePlot(MultiProFitExpDevSizeMagnitudePlot): 

119 """A size-magnitude plot for the bulge (de Vaucouleurs) component of a 

120 MultiProFit ExpDev model. 

121 """ 

122 

123 def setDefaults(self): 

124 super().setDefaults() 

125 self._set_model_defaults( 

126 name_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_default(), 

127 label_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_full(), 

128 name_component=component_names_default.deV, 

129 label_component=MultiProFitCoaddDeVFitConfig.get_model_name_full(), 

130 ) 

131 

132 class MultiProFitExpDevDiskSizeMagnitudePlot(MultiProFitExpDevSizeMagnitudePlot): 

133 """A size-magnitude plot for the disk (exponential) component of a 

134 MultiProFit ExpDev model. 

135 """ 

136 

137 def setDefaults(self): 

138 super().setDefaults() 

139 self._set_model_defaults( 

140 name_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_default(), 

141 label_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_full(), 

142 name_component=component_names_default.exp, 

143 label_component=MultiProFitCoaddExpFitConfig.get_model_name_full(), 

144 ) 

145 

146 class MultiProFitSersicSizeMagnitudePlot(MultiProFitSizeMagnitudePlot): 

147 """A size-magnitude plot for the MultiProFit Sersic model.""" 

148 

149 def setDefaults(self): 

150 super().setDefaults() 

151 self.config_moments = moments_sersic 

152 name_full_sersic = MultiProFitCoaddSersicFitConfig.get_model_name_full() 

153 self._set_model_defaults( 

154 name_model=MultiProFitCoaddSersicFitConfig.get_model_name_default(), 

155 label_model=name_full_sersic, 

156 name_component=component_names_default.sersic, 

157 label_component=name_full_sersic, 

158 )