Coverage for python/lsst/multiprofit/priors.py: 95%
20 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-19 02:18 -0700
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-19 02:18 -0700
1# This file is part of 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/>.
22__all__ = ["ShapePriorConfig", "get_hst_size_prior"]
24import numpy as np
26import lsst.gauss2d.fit as g2f
27import lsst.pex.config as pexConfig
29from .transforms import transforms_ref
32class ShapePriorConfig(pexConfig.Config):
33 """Configuration for a shape prior."""
35 prior_axrat_mean = pexConfig.Field[float](
36 default=0.7,
37 doc="Prior mean for axis ratio (prior ignored if not >0)",
38 )
39 prior_axrat_stddev = pexConfig.Field[float](
40 default=0,
41 doc="Prior std. dev. on axis ratio",
42 )
43 prior_size_mean = pexConfig.Field[float](
44 default=1,
45 doc="Prior mean for size_major",
46 )
47 prior_size_stddev = pexConfig.Field[float](
48 default=0,
49 doc="Prior std. dev. on size_major (prior ignored if not >0)",
50 )
52 def make_shape_prior(self, ellipse: g2f.ParametricEllipse) -> g2f.ShapePrior | None:
53 """Make a prior on ellipse (shape) parameters.
55 Parameters
56 ----------
57 ellipse
58 The ellipse to make a prior for.
60 Returns
61 -------
62 prior
63 The prior, or None if no positive stddev configured.
64 """
65 use_prior_axrat = (self.prior_axrat_stddev > 0) and np.isfinite(self.prior_axrat_stddev)
66 use_prior_size = (self.prior_size_stddev > 0) and np.isfinite(self.prior_size_stddev)
68 if use_prior_axrat or use_prior_size:
69 prior_size = (
70 g2f.ParametricGaussian1D(
71 g2f.MeanParameterD(self.prior_size_mean, transform=transforms_ref["log10"]),
72 g2f.StdDevParameterD(self.prior_size_stddev),
73 )
74 if use_prior_size
75 else None
76 )
77 prior_axrat = (
78 g2f.ParametricGaussian1D(
79 g2f.MeanParameterD(self.prior_axrat_mean, transform=transforms_ref["logit_axrat_prior"]),
80 g2f.StdDevParameterD(self.prior_axrat_stddev),
81 )
82 if use_prior_axrat
83 else None
84 )
85 return g2f.ShapePrior(ellipse, prior_size, prior_axrat)
86 return None
89def get_hst_size_prior(mag_psf_i: float) -> float:
90 """Return the mean and stddev for an HST-based size prior.
92 The size is major axis half-light radius.
94 Parameters
95 ----------
96 mag_psf_i
97 The i-band PSF magnitudes of the source(s).
99 Notes
100 -----
101 Return values are log10 scaled in units of arcseconds.
102 The input should be a PSF mag because other magnitudes - even Gaussian -
103 can be unreliable for low S/N (non-)detections.
104 """
105 return 0.75 * (19 - np.clip(mag_psf_i, 10, 30)) / 6.5, 0.2