Coverage for tests / test_plotting.py: 37%

55 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 08:43 +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 

22import lsst.gauss2d.fit as g2f 

23from lsst.multiprofit.componentconfig import CentroidConfig, GaussianComponentConfig, ParameterConfig 

24from lsst.multiprofit.model_utils import make_psf_model_null 

25from lsst.multiprofit.modelconfig import ModelConfig 

26from lsst.multiprofit.observationconfig import CoordinateSystemConfig, ObservationConfig 

27from lsst.multiprofit.plotting import abs_mag_sol_lsst, bands_weights_lsst, plot_model_rgb 

28from lsst.multiprofit.sourceconfig import ComponentGroupConfig, SourceConfig 

29import numpy as np 

30import pytest 

31 

32sigma_inv = 1e4 

33 

34 

35@pytest.fixture(scope="module") 

36def channels() -> dict[str, g2f.Channel]: 

37 return {band: g2f.Channel.get(band) for band in bands_weights_lsst} 

38 

39 

40@pytest.fixture(scope="module") 

41def data(channels) -> g2f.DataD: 

42 n_rows, n_cols = 16, 21 

43 x_min, y_min = 0, 0 

44 

45 dn_rows, dn_cols = 1, -2 

46 dx_min, dy_min = -2, 1 

47 

48 observations = [] 

49 for idx, band in enumerate(channels): 

50 config = ObservationConfig( 

51 band=band, 

52 coordsys=CoordinateSystemConfig( 

53 x_min=x_min + idx * dx_min, 

54 y_min=y_min + idx * dy_min, 

55 ), 

56 n_rows=n_rows + idx * dn_rows, 

57 n_cols=n_cols + idx * dn_cols, 

58 ) 

59 observation = config.make_observation() 

60 observation.sigma_inv.fill(sigma_inv) 

61 observation.mask_inv.fill(1) 

62 observations.append(observation) 

63 return g2f.DataD(observations) 

64 

65 

66@pytest.fixture(scope="module") 

67def psf_model(): 

68 return make_psf_model_null() 

69 

70 

71@pytest.fixture(scope="module") 

72def psf_models(psf_model, channels) -> list[g2f.PsfModel]: 

73 return [psf_model] * len(channels) 

74 

75 

76@pytest.fixture(scope="module") 

77def model(channels, data, psf_models): 

78 fluxes_group = [{channels[band]: 10 ** (-0.4 * (mag - 8.9)) for band, mag in abs_mag_sol_lsst.items()}] 

79 

80 modelconfig = ModelConfig( 

81 sources={ 

82 "src": SourceConfig( 

83 component_groups={ 

84 "": ComponentGroupConfig( 

85 centroids={ 

86 "default": CentroidConfig( 

87 x=ParameterConfig(value_initial=6.0, fixed=True), 

88 y=ParameterConfig(value_initial=11.0, fixed=True), 

89 ) 

90 }, 

91 components_gauss={ 

92 "": GaussianComponentConfig( 

93 rho=ParameterConfig(value_initial=0.1), 

94 size_x=ParameterConfig(value_initial=3.8), 

95 size_y=ParameterConfig(value_initial=5.1), 

96 ) 

97 }, 

98 ) 

99 } 

100 ), 

101 }, 

102 ) 

103 model = modelconfig.make_model([[fluxes_group]], data=data, psf_models=psf_models) 

104 model.setup_evaluators(g2f.EvaluatorMode.image) 

105 model.evaluate() 

106 rng = np.random.default_rng(1) 

107 for output, obs in zip(model.outputs, model.data): 

108 img = obs.image.data 

109 img.flat = output.data.flat + rng.standard_normal(img.size) / sigma_inv 

110 return model 

111 

112 

113def test_plot_model_rgb(model): 

114 fig, ax, fig_gs, ax_gs, *_ = plot_model_rgb( 

115 model, 

116 minimum=0, 

117 stretch=0.15, 

118 Q=4, 

119 weights=bands_weights_lsst, 

120 plot_chi_hist=True, 

121 ) 

122 assert fig is not None 

123 assert ax is not None 

124 assert fig_gs is not None 

125 assert ax_gs is not None 

126 

127 

128def test_plot_model_rgb_auto(model): 

129 fig, ax, *_ = plot_model_rgb( 

130 model, 

131 Q=6, 

132 weights=bands_weights_lsst, 

133 rgb_min_auto=True, 

134 rgb_stretch_auto=True, 

135 plot_singleband=False, 

136 plot_chi_hist=False, 

137 ) 

138 assert fig is not None 

139 assert ax is not None