Coverage for python / lsst / multiprofit / priors.py: 55%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-17 08:58 +0000

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/>. 

21 

22__all__ = ["ShapePriorConfig", "get_hst_size_prior"] 

23 

24import lsst.gauss2d.fit as g2f 

25import lsst.pex.config as pexConfig 

26import numpy as np 

27 

28from .transforms import transforms_ref 

29 

30 

31class ShapePriorConfig(pexConfig.Config): 

32 """Configuration for a shape prior.""" 

33 

34 prior_axrat_mean = pexConfig.Field[float]( 

35 default=0.7, 

36 doc="Prior mean for axis ratio (prior ignored if not >0)", 

37 ) 

38 prior_axrat_stddev = pexConfig.Field[float]( 

39 default=0, 

40 doc="Prior std. dev. on axis ratio", 

41 ) 

42 prior_size_mean = pexConfig.Field[float]( 

43 default=1, 

44 doc="Prior mean for size_major", 

45 ) 

46 prior_size_stddev = pexConfig.Field[float]( 

47 default=0, 

48 doc="Prior std. dev. on size_major (prior ignored if not >0)", 

49 ) 

50 

51 def make_shape_prior(self, ellipse: g2f.ParametricEllipse) -> g2f.ShapePrior | None: 

52 """Make a prior on ellipse (shape) parameters. 

53 

54 Parameters 

55 ---------- 

56 ellipse 

57 The ellipse to make a prior for. 

58 

59 Returns 

60 ------- 

61 prior 

62 The prior, or None if no positive stddev configured. 

63 """ 

64 use_prior_axrat = (self.prior_axrat_stddev > 0) and np.isfinite(self.prior_axrat_stddev) 

65 use_prior_size = (self.prior_size_stddev > 0) and np.isfinite(self.prior_size_stddev) 

66 

67 if use_prior_axrat or use_prior_size: 

68 prior_size = ( 

69 g2f.ParametricGaussian1D( 

70 g2f.MeanParameterD(self.prior_size_mean, transform=transforms_ref["log10"]), 

71 g2f.StdDevParameterD(self.prior_size_stddev), 

72 ) 

73 if use_prior_size 

74 else None 

75 ) 

76 prior_axrat = ( 

77 g2f.ParametricGaussian1D( 

78 g2f.MeanParameterD(self.prior_axrat_mean, transform=transforms_ref["logit_axrat_prior"]), 

79 g2f.StdDevParameterD(self.prior_axrat_stddev), 

80 ) 

81 if use_prior_axrat 

82 else None 

83 ) 

84 return g2f.ShapePrior(ellipse, prior_size, prior_axrat) 

85 return None 

86 

87 

88def get_hst_size_prior(mag_psf_i: float) -> float: 

89 """Return the mean and stddev for an HST-based size prior. 

90 

91 The size is major axis half-light radius. 

92 

93 Parameters 

94 ---------- 

95 mag_psf_i 

96 The i-band PSF magnitudes of the source(s). 

97 

98 Notes 

99 ----- 

100 Return values are log10 scaled in units of arcseconds. 

101 The input should be a PSF mag because other magnitudes - even Gaussian - 

102 can be unreliable for low S/N (non-)detections. 

103 """ 

104 return 0.75 * (19 - np.clip(mag_psf_i, 10, 30)) / 6.5, 0.2