Coverage for python / lsst / pipe / tasks / rgb2hips / _properties.py: 0%

56 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-30 09:11 +0000

1# This file is part of pipe_tasks. 

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 

22from __future__ import annotations 

23 

24__all__ = ("HipsPropertiesSpectralTerm", "HipsPropertiesConfig", "_write_property") 

25 

26import re 

27from lsst.pex.config import Config, Field, ListField, ConfigDictField 

28 

29 

30class HipsPropertiesSpectralTerm(Config): 

31 lambda_min = Field[float]( 

32 doc="Minimum wavelength (nm)", 

33 ) 

34 lambda_max = Field[float]( 

35 doc="Maximum wavelength (nm)", 

36 ) 

37 

38 

39class HipsPropertiesConfig(Config): 

40 """Configuration parameters for writing a HiPS properties file.""" 

41 

42 creator_did_template = Field[str]( 

43 doc=("Unique identifier of the HiPS - Format: IVOID. Use ``{band}`` to substitute the band name."), 

44 dtype=str, 

45 optional=False, 

46 ) 

47 obs_collection = Field[str]( 

48 doc="Short name of original data set - Format: one word", 

49 optional=True, 

50 ) 

51 obs_description_template = Field[str]( 

52 doc=( 

53 "Data set description - Format: free text, longer free text " 

54 "description of the dataset. Use ``{band}`` to substitute " 

55 "the band name." 

56 ), 

57 ) 

58 prov_progenitor = ListField[str]( 

59 doc="Provenance of the original data - Format: free text", 

60 default=[], 

61 ) 

62 obs_title_template = Field[str]( 

63 doc=( 

64 "Data set title format: free text, but should be short. " 

65 "Use ``{band}`` to substitute the band name." 

66 ), 

67 optional=False, 

68 ) 

69 spectral_ranges = ConfigDictField( 

70 doc=("Mapping from band to lambda_min, lamba_max (nm). May be approximate."), 

71 keytype=str, 

72 itemtype=HipsPropertiesSpectralTerm, 

73 default={}, 

74 ) 

75 initial_ra = Field[float]( 

76 doc="Initial RA (deg) (default for HiPS viewer). If not set will use a point in MOC.", 

77 optional=True, 

78 ) 

79 initial_dec = Field[float]( 

80 doc="Initial Declination (deg) (default for HiPS viewer). If not set will use a point in MOC.", 

81 optional=True, 

82 ) 

83 initial_fov = Field[float]( 

84 doc="Initial field-of-view (deg). If not set will use ~1 healpix tile.", 

85 optional=True, 

86 ) 

87 obs_ack = Field[str]( 

88 doc="Observation acknowledgements (free text).", 

89 optional=True, 

90 ) 

91 t_min = Field[float]( 

92 doc="Time (MJD) of earliest observation included in HiPS", 

93 optional=True, 

94 ) 

95 t_max = Field[float]( 

96 doc="Time (MJD) of latest observation included in HiPS", 

97 optional=True, 

98 ) 

99 

100 def validate(self): 

101 super().validate() 

102 

103 if self.obs_collection is not None: 

104 if re.search(r"\s", self.obs_collection): 

105 raise ValueError("obs_collection cannot contain any space characters.") 

106 

107 def setDefaults(self): 

108 # Values here taken from 

109 # https://github.com/lsst-dm/dax_obscore/blob/44ac15029136e2ec15/configs/dp02.yaml#L46 

110 u_term = HipsPropertiesSpectralTerm() 

111 u_term.lambda_min = 330.0 

112 u_term.lambda_max = 400.0 

113 self.spectral_ranges["u"] = u_term 

114 g_term = HipsPropertiesSpectralTerm() 

115 g_term.lambda_min = 402.0 

116 g_term.lambda_max = 552.0 

117 self.spectral_ranges["g"] = g_term 

118 r_term = HipsPropertiesSpectralTerm() 

119 r_term.lambda_min = 552.0 

120 r_term.lambda_max = 691.0 

121 self.spectral_ranges["r"] = r_term 

122 i_term = HipsPropertiesSpectralTerm() 

123 i_term.lambda_min = 691.0 

124 i_term.lambda_max = 818.0 

125 self.spectral_ranges["i"] = i_term 

126 z_term = HipsPropertiesSpectralTerm() 

127 z_term.lambda_min = 818.0 

128 z_term.lambda_max = 922.0 

129 self.spectral_ranges["z"] = z_term 

130 y_term = HipsPropertiesSpectralTerm() 

131 y_term.lambda_min = 970.0 

132 y_term.lambda_max = 1060.0 

133 self.spectral_ranges["y"] = y_term 

134 

135 

136# WARNING: In general PipelineTasks are not allowed to do any outputs 

137# outside of the butler. This task has been given (temporary) 

138# Special Dispensation because of the nature of HiPS outputs until 

139# a more controlled solution can be found. 

140def _write_property(fh, name, value): 

141 """Write a property name/value to a file handle. 

142 

143 Parameters 

144 ---------- 

145 fh : file handle (blah) 

146 Open for writing. 

147 name : `str` 

148 Name of property 

149 value : `str` 

150 Value of property 

151 """ 

152 # This ensures that the name has no spaces or space-like characters, 

153 # per the HiPS standard. 

154 if re.search(r"\s", name): 

155 raise ValueError(f"``{name}`` cannot contain any space characters.") 

156 if "=" in name: 

157 raise ValueError(f"``{name}`` cannot contain an ``=``") 

158 

159 fh.write(f"{name:25}= {value}\n")