Coverage for python / lsst / meas / extensions / multiprofit / analysis_tools.py: 40%
51 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-06 09:09 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-06 09:09 +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/>.
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
28 has_atools = True
29except ImportError:
30 has_atools = False
32from .pipetasks_fit import (
33 MultiProFitCoaddDeVFitConfig,
34 MultiProFitCoaddExpDeVFitConfig,
35 MultiProFitCoaddExpFitConfig,
36 MultiProFitCoaddSersicFitConfig,
37 component_names_default,
38)
40if has_atools: 40 ↛ exitline 40 didn't exit the module because the condition on line 40 was always true
42 moments_sersic = MomentsConfig(xx="reff_x", yy="reff_y", xy="rho")
44 class MultiProFitSizeMagnitudePlot(SizeMagnitudePlot):
45 """A size-magnitude plot with default MultiProFit column names."""
47 def _get_flags_default(self, name_model: str):
48 """Get the default MultiProFit flags for a given model.
50 Parameters
51 ----------
52 name_model
53 The short name of the model in table columns.
55 Returns
56 -------
57 flags_false
58 The flags that must be false for the fit to be good.
59 flags_true
60 The flags that must be true for the fit to be good.
61 """
62 flags_false = [
63 f"mpf_{name_model}_{flag}_flag" for flag in ("unknown", "is_parent", "not_primary", "psf_fit")
64 ]
65 flags_true = []
66 return flags_false, flags_true
68 def _set_model_defaults(
69 self, name_model: str, label_model: str, name_component: str, label_component: str
70 ) -> None:
71 """Set default values for a given model.
73 Parameters
74 ----------
75 name_model
76 The short name of the model in table columns.
77 label_model
78 The label for the model in plots.
79 name_component
80 The shortname of the component in table columns.
81 label_component
82 The label for the component in plots.
83 """
84 flags_false, flags_true = self._get_flags_default(name_model)
85 self.prep.selectors.flagSelector.selectWhenFalse = flags_false
86 self.prep.selectors.flagSelector.selectWhenTrue = flags_true
88 name_full = f"{name_model}_{name_component}"
89 flux_config = FluxConfig(
90 key_flux=f"mpf_{name_full}_{{band}}_flux",
91 key_flux_error=f"mpf_{name_full}_{{band}}_flux_err",
92 name_flux=label_model,
93 name_flux_short=name_model,
94 )
95 size_config = SizeConfig(
96 key_size=f"mpf_{name_full}_{{suffix}}",
97 name_size=f"{label_component} {'$R_{eff}$'}",
98 )
99 self.fluxes = {name_full: flux_config}
100 self.mag_x = name_full
101 self.sizes = {name_full: size_config}
102 self.size_y = name_full
104 def setDefaults(self):
105 super().setDefaults()
106 self.applyContext(CoaddContext)
107 self.size_type = "determinantRadius"
108 self.is_covariance = False
109 self.produce.plot.xLims = (17, 29)
110 self.produce.plot.yLims = (-4, 3)
112 class MultiProFitExpDevSizeMagnitudePlot(MultiProFitSizeMagnitudePlot):
113 """A size-magnitude plot for the MultiProFit Exp.Dev. model."""
115 def setDefaults(self):
116 super().setDefaults()
117 self.config_moments = moments_sersic
119 class MultiProFitExpDevBulgeSizeMagnitudePlot(MultiProFitExpDevSizeMagnitudePlot):
120 """A size-magnitude plot for the bulge (de Vaucouleurs) component of a
121 MultiProFit ExpDev model.
122 """
124 def setDefaults(self):
125 super().setDefaults()
126 self._set_model_defaults(
127 name_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_default(),
128 label_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_full(),
129 name_component=component_names_default.deV,
130 label_component=MultiProFitCoaddDeVFitConfig.get_model_name_full(),
131 )
133 class MultiProFitExpDevDiskSizeMagnitudePlot(MultiProFitExpDevSizeMagnitudePlot):
134 """A size-magnitude plot for the disk (exponential) component of a
135 MultiProFit ExpDev model.
136 """
138 def setDefaults(self):
139 super().setDefaults()
140 self._set_model_defaults(
141 name_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_default(),
142 label_model=MultiProFitCoaddExpDeVFitConfig.get_model_name_full(),
143 name_component=component_names_default.exp,
144 label_component=MultiProFitCoaddExpFitConfig.get_model_name_full(),
145 )
147 class MultiProFitSersicSizeMagnitudePlot(MultiProFitSizeMagnitudePlot):
148 """A size-magnitude plot for the MultiProFit Sersic model."""
150 def setDefaults(self):
151 super().setDefaults()
152 self.config_moments = moments_sersic
153 name_full_sersic = MultiProFitCoaddSersicFitConfig.get_model_name_full()
154 self._set_model_defaults(
155 name_model=MultiProFitCoaddSersicFitConfig.get_model_name_default(),
156 label_model=name_full_sersic,
157 name_component=component_names_default.sersic,
158 label_component=name_full_sersic,
159 )