Coverage for src/ufig/plugins/multi_band_setup.py: 90%

110 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-12 19:08 +0000

1# Copyright (C) 2016 ETH Zurich, Institute for Astronomy 

2 

3""" 

4Created on May 3, 2016 

5author: Joerg Herbel 

6""" 

7 

8import warnings 

9 

10from ivy.plugin.base_plugin import BasePlugin 

11 

12NAME = "setup multi-band" 

13 

14 

15class Plugin(BasePlugin): 

16 """ 

17 Prepare for the rendering of multiple images. This plugin essentially allows to 

18 change the names of files used in the rendering of images in different bands by 

19 providing a format for the corresponding file names. This format specifies the way 

20 file names are obtained from the name of the tile in the sky and/or the filter band 

21 names. It contains '{}' where the tile name and/or the filter band name have to be 

22 inserted to obtain the correct file name(s). 

23 

24 :param filters: List of names of filter bands used to render images, optional. 

25 :param tile_name: Name of the tile in the sky corresponding to the images rendered 

26 in this run, optional. 

27 :param image_name_dict: Dictionary of image names for each filter band used to 

28 render an image, optional. 

29 :param image_name_format: Format of images names, used to obtain the image names 

30 from the name of the tile and the name(s) of the filter band(s), optional. 

31 :param galaxy_catalog_name_dict: Dictionary of galaxy catalog names for each filter 

32 band used to render an image, optional. 

33 :param galaxy_catalog_name_format: Format of galaxy catalog names, used to obtain 

34 the catalog names from the name of the tile and the name(s) of the filter 

35 band(s), optional. 

36 :param star_catalog_name_dict: Dictionary of star catalog names for each filter band 

37 used to render an image. 

38 :param star_catalog_name_format: Format of star catalog names, used to obtain the 

39 catalog names from the name of the tile and the name(s) of the filter 

40 band(s), optional. 

41 :param besancon_cat_name: Name of a catalog of stars drawn from the Besancon model 

42 of the galaxy, optional. 

43 :param besancon_cat_name_format: Format of the name of a catalog of stars drawn from 

44 the Besancon model, used to obtain the catalog name from the name of the 

45 tile, optional. 

46 :param exp_time_file_name_dict: Dictionary of file names of maps of exposure times 

47 for each filter band used to render an image, optional. 

48 :param exp_time_file_name_format: Format of file names of maps of exposure times, 

49 used to obtain the file names from the name of the tile and the name(s) of 

50 the filter band(s), optional. 

51 :param bkg_rms_file_name_dict: Dictionary of file names of maps of the standard 

52 deviation of the background for each filter band used to render an image, 

53 optional. 

54 :param bkg_rms_file_name_format: Format of file names of maps of the standard 

55 deviation of the background, used to obtain the file names from the name of 

56 the tile and the name(s) of the filter band(s), optional. 

57 :param psf_maps_dict: Dictionary of file names of PSF maps for each filter band used 

58 to render an image, optional. 

59 :param psf_maps_file_name_format: Format of file names of PSF maps, used to obtain 

60 the file names from the name of the tile and the name(s) of the filter 

61 band(s), optional. 

62 :param sextractor_catalog_name_dict: Dictionary of SExtractor catalog names for each 

63 filter band used to render an image, optional. 

64 :param sextractor_catalog_name_format: Format of SExtractor catalog names, used to 

65 obtain the catalog names from the name of the tile and the name(s) of the 

66 filter band(s), optional. 

67 :param weight_image_dict: Dictionary of weight image names used by SExtractor for 

68 each filter band used to render an image, optional. 

69 :param weight_image_format: Format of weight image names used by SExtractor, used to 

70 obtain the names from the name of the tile and the name(s) of the filter 

71 band(s), optional. 

72 

73 :return: ctx.parameters with multi-band dictionaries modified accordingly. 

74 """ 

75 

76 def __call__(self): 

77 par = self.ctx.parameters 

78 

79 # Ensure that reference band is rendered first 

80 try: 

81 # add emu_filters to match the order of the filters 

82 par.emu_filters = par.filters.copy() 

83 par.filters.remove(par.reference_band) 

84 par.filters.insert(0, par.reference_band) 

85 except AttributeError: 

86 pass 

87 except ValueError: 

88 warnings.warn( 

89 "Reference band is not in the list of filter bands for which" 

90 " images are rendered.", 

91 stacklevel=1, 

92 ) 

93 

94 # Ensure that the detection band is rendered first (in case of forced 

95 # photometry) 

96 if hasattr(par, "sextractor_forced_photo_detection_bands"): 

97 # check that all bands used for detection will be rendered 

98 for band in par.sextractor_forced_photo_detection_bands: 

99 if band not in par.filters: 99 ↛ 100line 99 didn't jump to line 100 because the condition on line 99 was never true

100 raise ValueError( 

101 f"Filter band {band} in sextractor_forced_photo_detection_bands" 

102 " but not in filters" 

103 ) 

104 

105 # in case of a single detection band, ensure that this band will be rendered 

106 # first 

107 if len(par.sextractor_forced_photo_detection_bands) == 1: 107 ↛ 120line 107 didn't jump to line 120 because the condition on line 107 was always true

108 par.filters.remove(par.sextractor_forced_photo_detection_bands[0]) 

109 par.filters.insert(0, par.sextractor_forced_photo_detection_bands[0]) 

110 

111 if hasattr(par, "reference_band") and ( 111 ↛ 114line 111 didn't jump to line 114 because the condition on line 111 was never true

112 par.reference_band != par.sextractor_forced_photo_detection_bands[0] 

113 ): 

114 warnings.warn( 

115 "Reference band is different from SExtractor forced-photometry" 

116 "detection band, this can lead to crashes.", 

117 stacklevel=1, 

118 ) 

119 

120 try: 

121 if not par.image_name_dict: 

122 par.image_name_dict = { 

123 f: par.image_name_format.format(par.tile_name, "{}").format(f) 

124 for f in par.filters 

125 } 

126 except (AttributeError, IndexError): 

127 pass 

128 

129 try: 

130 if not par.galaxy_catalog_name_dict: 

131 par.galaxy_catalog_name_dict = { 

132 f: par.galaxy_catalog_name_format.format( 

133 par.tile_name, "{}" 

134 ).format(f) 

135 for f in par.filters 

136 } 

137 except (AttributeError, IndexError): 

138 pass 

139 try: 

140 if not par.star_catalog_name_dict: 

141 par.star_catalog_name_dict = { 

142 f: par.star_catalog_name_format.format(par.tile_name, "{}").format( 

143 f 

144 ) 

145 for f in par.filters 

146 } 

147 except (AttributeError, IndexError): 

148 pass 

149 

150 try: 

151 if not par.besancon_cat_name: 

152 par.besancon_cat_name = par.besancon_cat_name_format.format( 

153 par.tile_name 

154 ) 

155 except AttributeError: 

156 pass 

157 

158 try: 

159 if not par.exp_time_file_name_dict: 

160 par.exp_time_file_name_dict = { 

161 f: par.exp_time_file_name_format.format(par.tile_name, "{}").format( 

162 f 

163 ) 

164 for f in par.filters 

165 } 

166 except (AttributeError, IndexError): 

167 pass 

168 try: 

169 if not par.bkg_rms_file_name_dict: 

170 par.bkg_rms_file_name_dict = { 

171 f: par.bkg_rms_file_name_format.format(par.tile_name, "{}").format( 

172 f 

173 ) 

174 for f in par.filters 

175 } 

176 except (AttributeError, IndexError): 

177 pass 

178 

179 try: 

180 if not par.psf_maps_dict: 

181 par.psf_maps_dict = { 

182 f: par.psf_maps_file_name_format.format(f) for f in par.filters 

183 } 

184 except AttributeError: 

185 pass 

186 

187 try: 

188 if not par.sextractor_catalog_name_dict: 

189 par.sextractor_catalog_name_dict = { 

190 f: par.sextractor_catalog_name_format.format( 

191 par.tile_name, "{}" 

192 ).format(f) 

193 for f in par.filters 

194 } 

195 except (AttributeError, IndexError): 

196 pass 

197 

198 try: 

199 if not par.sextractor_forced_photo_catalog_name_dict: 199 ↛ 208line 199 didn't jump to line 208 because the condition on line 199 was always true

200 par.sextractor_forced_photo_catalog_name_dict = { 

201 f: par.sextractor_forced_photo_catalog_name_format.format( 

202 par.tile_name, "{}" 

203 ).format(f) 

204 for f in par.filters 

205 } 

206 except (AttributeError, IndexError): 

207 pass 

208 try: 

209 if not par.weight_image_dict: 

210 par.weight_image_dict = { 

211 f: par.weight_image_format.format(par.tile_name, "{}").format(f) 

212 for f in par.filters 

213 } 

214 except (AttributeError, IndexError): 

215 pass 

216 

217 try: 

218 if not par.filepath_psfmodel_input_dict: 218 ↛ 225line 218 didn't jump to line 225 because the condition on line 218 was always true

219 par.filepath_psfmodel_input_dict = { 

220 f: par.filepath_psfmodel_input_format.format(f) for f in par.filters 

221 } 

222 except AttributeError: 

223 pass 

224 

225 try: 

226 if not par.filepath_psfmodel_output_dict: 226 ↛ 236line 226 didn't jump to line 236 because the condition on line 226 was always true

227 par.filepath_psfmodel_output_dict = { 

228 f: par.filepath_psfmodel_output_format.format( 

229 par.sextractor_catalog_name_dict[f] 

230 ) 

231 for f in par.filters 

232 } 

233 except (KeyError, AttributeError): 

234 pass 

235 

236 try: 

237 if not par.filepath_sysmaps_dict: 237 ↛ 244line 237 didn't jump to line 244 because the condition on line 237 was always true

238 par.filepath_sysmaps_dict = { 

239 f: par.filepath_sysmaps_format.format(f) for f in par.filters 

240 } # this somehow crashes 

241 except AttributeError: 

242 pass 

243 

244 try: 

245 if not par.det_clf_catalog_name_dict: 245 ↛ 255line 245 didn't jump to line 255 because the condition on line 245 was always true

246 par.det_clf_catalog_name_dict = { 

247 f: par.det_clf_catalog_name_format.format( 

248 par.tile_name, "{}" 

249 ).format(f) 

250 for f in par.filters 

251 } 

252 except (AttributeError, IndexError): 

253 pass 

254 

255 try: 

256 if not par.bkg_amp_variation_sigma_dict: 256 ↛ 263line 256 didn't jump to line 263 because the condition on line 256 was always true

257 par.bkg_amp_variation_sigma_dict = { 

258 f: par.bkg_amp_variation_sigma for f in par.filters 

259 } 

260 except AttributeError: 

261 pass 

262 

263 try: 

264 if not par.bkg_noise_variation_sigma_dict: 264 ↛ 271line 264 didn't jump to line 271 because the condition on line 264 was always true

265 par.bkg_noise_variation_sigma_dict = { 

266 f: par.bkg_noise_variation_sigma for f in par.filters 

267 } 

268 except AttributeError: 

269 pass 

270 

271 try: 

272 if not par.psf_fwhm_variation_sigma_dict: 272 ↛ exitline 272 didn't return from function '__call__' because the condition on line 272 was always true

273 par.psf_fwhm_variation_sigma_dict = { 

274 f: par.psf_fwhm_variation_sigma for f in par.filters 

275 } 

276 except AttributeError: 

277 pass 

278 

279 def __str__(self): 

280 return NAME