Coverage for python / lsst / multiprofit / observationconfig.py: 60%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-30 08:48 +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__ = ["CoordinateSystemConfig", "ObservationConfig", "PsfObservationConfig"] 

23 

24import lsst.gauss2d as g2 

25import lsst.gauss2d.fit as g2f 

26import lsst.pex.config as pexConfig 

27 

28 

29class CoordinateSystemConfig(pexConfig.Config): 

30 """Configuration for an lsst.gauss2d.CoordinateSystem.""" 

31 

32 dx1 = pexConfig.Field[float](doc="The x-axis pixel scale", optional=False, default=1.0) 

33 dy2 = pexConfig.Field[float](doc="The y-axis pixel scale", optional=False, default=1.0) 

34 x_min = pexConfig.Field[float]( 

35 doc="The x-axis coordinate of the bottom left corner", 

36 optional=False, 

37 default=0.0, 

38 ) 

39 y_min = pexConfig.Field[float]( 

40 doc="The y-axis coordinate of the bottom left corner", 

41 optional=False, 

42 default=0.0, 

43 ) 

44 

45 def make_coordinate_system(self) -> g2.CoordinateSystem: 

46 return g2.CoordinateSystem(dx1=self.dx1, dy2=self.dy2, x_min=self.x_min, y_min=self.y_min) 

47 

48 

49class ObservationConfig(pexConfig.Config): 

50 """Configuration for an lsst.gauss2d.fit.Observation.""" 

51 

52 band = pexConfig.Field[str](doc="The name of the band", optional=False, default="None") 

53 coordsys = pexConfig.ConfigField[CoordinateSystemConfig](doc="The coordinate system config") 

54 n_rows = pexConfig.Field[int](doc="The number of rows in the image") 

55 n_cols = pexConfig.Field[int](doc="The number of columns in the image") 

56 

57 def make_observation(self) -> g2f.ObservationD: 

58 coordsys = self.coordsys.make_coordinate_system() if self.coordsys else None 

59 image = g2.ImageD(n_rows=self.n_rows, n_cols=self.n_cols, coordsys=coordsys) 

60 sigma_inv = g2.ImageD(n_rows=self.n_rows, n_cols=self.n_cols, coordsys=coordsys) 

61 mask = g2.ImageB(n_rows=self.n_rows, n_cols=self.n_cols, coordsys=coordsys) 

62 observation = g2f.ObservationD( 

63 image=image, 

64 sigma_inv=sigma_inv, 

65 mask_inv=mask, 

66 channel=g2f.Channel.get(self.band), 

67 ) 

68 return observation 

69 

70 

71class PsfObservationConfig(ObservationConfig): 

72 """Configuration for an lsst.gauss2d.fit.Observation used for 

73 PSF fitting. 

74 """ 

75 

76 def validate(self) -> None: 

77 super().validate() 

78 if self.band != "None": 

79 raise ValueError("band must be None for PSF fitting")