Coverage for python/lsst/faro/utils/filter_map.py: 23%
41 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 09:11 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 09:11 +0000
1# This file is part of faro.
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/>.
22import fnmatch
24from lsst.pex.config import Config, DictField, ConfigDictField
26__all__ = ("FilterMapDict", "FilterMap")
29class FilterMapNotFoundError(LookupError):
30 """Exception class indicating we couldn't find a filter map
31 """
32 pass
35class ColortermNotFoundError(LookupError):
36 """Exception class indicating we couldn't find the color term
37 """
38 pass
41class FilterMapDict(Config):
42 """A mapping of band to physical filter label.
43 """
44 data = DictField(
45 doc="Mapping of band to physical filter label",
46 keytype=str,
47 itemtype=str,
48 default={},
49 )
52class FilterMap(Config):
53 """Config for mapping of band to physical filter label."""
54 data = ConfigDictField(
55 doc="Mapping of band to physical filter label.",
56 keytype=str,
57 itemtype=FilterMapDict,
58 default={},
59 )
61 def __init__(self, filename=None):
62 if filename is None:
63 filename = "resource://lsst.faro/resources/config/filterMap.py"
64 self.load(filename)
66 def getFilters(self, instName, bands, doRaise=True):
67 """Get the physical filters that correspond with input bands."""
68 try:
69 trueInstName = None
70 filterDictConfig = self.data.get(instName)
71 if filterDictConfig is None:
72 # try glob expression
73 matchList = [libInstNameGlob for libInstNameGlob in self.data
74 if fnmatch.fnmatch(instName, libInstNameGlob)]
75 if len(matchList) == 1:
76 trueInstName = matchList[0]
77 filterDictConfig = self.data[trueInstName]
78 elif len(matchList) > 1:
79 raise FilterMapNotFoundError(
80 "Multiple library globs match instName %r: %s" % (instName, matchList))
81 else:
82 raise FilterMapNotFoundError(
83 "No filer map dict found with instName %r" % instName)
85 filterDict = filterDictConfig.data
87 filters = []
88 for band in bands:
89 if band not in filterDict:
90 errMsg = "No filter found for band %r with instName %r" % (
91 band, instName)
92 if trueInstName is not None:
93 errMsg += " = catalog %r" % (trueInstName,)
94 raise ColortermNotFoundError(errMsg)
96 filters.append(filterDict[band])
97 return filters
98 except FilterMapNotFoundError:
99 if doRaise:
100 raise
101 else:
102 return bands