253 def getColorterm(self, physicalFilter, photoCatName, doRaise=True):
254 """Get the appropriate Colorterm from the library
255
256 Use dict of color terms in the library that matches the photoCatName.
257 If the photoCatName exactly matches an entry in the library, that
258 dict is used; otherwise if the photoCatName matches a single glob (shell syntax,
259 e.g., "sdss-*" will match "sdss-dr8"), then that is used. If there is no
260 exact match and no unique match to the globs, raise an exception.
261
262 Parameters
263 ----------
264 physicalFilter : `str`
265 Label of physical filter to correct to.
266 photoCatName : `str`
267 Name of photometric reference catalog from which to retrieve the data.
268 This argument is not glob-expanded (but the catalog names in the library are,
269 if no exact match is found).
270 doRaise : `bool`
271 If True then raise ColortermNotFoundError if no suitable Colorterm found;
272 If False then return a null Colorterm with physicalFilter as the primary and secondary filter.
273
274 Returns
275 -------
276 ctDict : `Unknown`
277 The appropriate Colorterm.
278
279 Raises
280 ------
281 ColortermNotFoundError
282 If no suitable Colorterm found and doRaise true;
283 other exceptions may be raised for unexpected errors, regardless of the value of doRaise.
284 """
285 try:
286 trueRefCatName = None
287 ctDictConfig = self.data.get(photoCatName)
288 if ctDictConfig is None:
289
290 matchList = [libRefNameGlob for libRefNameGlob in self.data
291 if fnmatch.fnmatch(photoCatName, libRefNameGlob)]
292 if len(matchList) == 1:
293 trueRefCatName = matchList[0]
294 ctDictConfig = self.data[trueRefCatName]
295 elif len(matchList) > 1:
296 raise ColortermNotFoundError(
297 "Multiple library globs match photoCatName %r: %s" % (photoCatName, matchList))
298 else:
299 raise ColortermNotFoundError(
300 "No colorterm dict found with photoCatName %r" % photoCatName)
301 ctDict = ctDictConfig.data
302 if physicalFilter not in ctDict:
303 errMsg = "No colorterm found for filter %r with photoCatName %r" % (
304 physicalFilter, photoCatName)
305 if trueRefCatName is not None:
306 errMsg += " = catalog %r" % (trueRefCatName,)
307 raise ColortermNotFoundError(errMsg)
308 return ctDict[physicalFilter]
309 except ColortermNotFoundError:
310 if doRaise:
311 raise
312 else:
313 return Colorterm(physicalFilter, physicalFilter)