22 """Classes to allow obs packages to define the filters used by an Instrument
23 and for use by `lsst.afw.image.Filter`, gen2 dataIds, and gen3 Dimensions.
26 __all__ = (
"FilterDefinition",
"FilterDefinitionCollection")
33 import lsst.afw.image.utils
37 """An order-preserving collection of multiple `FilterDefinition`.
41 filters : `~collections.abc.Sequence`
42 The filters in this collection.
46 """Whether these filters have been defined via
47 `~lsst.afw.image.utils.defineFilter`. If so, set to ``self`` to identify
48 the filter collection that defined them.
52 """A mapping from physical filter name to band name.
53 This is a convenience feature to allow file readers to create a FilterLabel
54 when reading a raw file that only has a physical filter name, without
55 iterating over the entire collection.
59 self.
_filters_filters = list(filters)
69 return "FilterDefinitions(" +
', '.join(str(f)
for f
in self.
_filters_filters) +
')'
72 """Define all the filters to `lsst.afw.image.Filter`.
74 `~lsst.afw.image.Filter` objects are singletons, so we protect against
75 filters being defined multiple times.
80 Raised if any other `FilterDefinitionCollection` has already called
87 FilterDefinitionCollection._defined = self
92 msg = f
"afw Filters were already defined on: {self._defined}"
93 raise RuntimeError(msg)
97 """Reset the afw Filter definitions and clear the `defined` singleton.
98 Use this in unittests that define different filters.
100 lsst.afw.image.utils.resetFilters()
104 """Return the FilterDefinitions that match a particular name.
106 This method makes no attempt to prioritize, e.g., band names over
107 physical filter names; any definition that makes *any* reference
108 to the name is returned.
113 The name to search for. May be any band, physical, or alias name.
117 matches : `set` [`FilterDefinition`]
118 All FilterDefinitions containing ``name`` as one of their
122 for filter
in self.
_filters_filters:
123 if name == filter.physical_filter
or name == filter.band
or name == filter.afw_name \
124 or name
in filter.alias:
129 @dataclasses.dataclass(frozen=True)
131 """The definition of an instrument's filter bandpass.
133 This class is used to interface between the `~lsst.afw.image.Filter` class
134 and the Gen2 `~lsst.daf.persistence.CameraMapper` and Gen3
135 `~lsst.obs.base.Instruments` and ``physical_filter``/``band``
136 `~lsst.daf.butler.Dimension`.
138 This class is likely temporary, until we have a better versioned filter
139 definition system that includes complete transmission information.
143 """The name of a filter associated with a particular instrument: unique for
144 each piece of glass. This should match the exact filter name used in the
145 observatory's metadata.
147 This name is used to define the ``physical_filter`` gen3 Butler Dimension.
149 If neither ``band`` or ``afw_name`` is defined, this is used
150 as the `~lsst.afw.image.Filter` ``name``, otherwise it is added to the
151 list of `~lsst.afw.image.Filter` aliases.
155 """The effective wavelength of this filter (nm)."""
158 """The generic name of a filter not associated with a particular instrument
159 (e.g. `r` for the SDSS Gunn r-band, which could be on SDSS, LSST, or HSC).
161 Not all filters have an abstract filter: engineering or test filters may
162 not have a genericly-termed filter name.
164 If specified and if `afw_name` is None, this is used as the
165 `~lsst.afw.image.Filter` ``name`` field, otherwise it is added to the list
166 of `~lsst.afw.image.Filter` aliases.
170 """If not None, the name of the `~lsst.afw.image.Filter` object.
172 This is distinct from physical_filter and band to maintain
173 backwards compatibility in some obs packages.
174 For example, for HSC there are two distinct ``r`` and ``i`` filters, named
175 ``r/r2`` and ``i/i2``.
178 lambdaMin: float = np.nan
179 """The minimum wavelength of this filter (nm; defined as 1% throughput)"""
180 lambdaMax: float = np.nan
181 """The maximum wavelength of this filter (nm; defined as 1% throughput)"""
183 alias: set = frozenset()
184 """Alternate names for this filter. These are added to the
185 `~lsst.afw.image.Filter` alias list.
190 if not isinstance(self.alias, frozenset):
191 object.__setattr__(self,
'alias', frozenset(self.alias))
194 txt = f
"FilterDefinition(physical_filter='{self.physical_filter}', lambdaEff='{self.lambdaEff}'"
195 if self.band
is not None:
196 txt += f
", band='{self.band}'"
197 if self.afw_name
is not None:
198 txt += f
", afw_name='{self.afw_name}'"
199 if not np.isnan(self.lambdaMin):
200 txt += f
", lambdaMin='{self.lambdaMin}'"
201 if not np.isnan(self.lambdaMax):
202 txt += f
", lambdaMax='{self.lambdaMax}'"
203 if len(self.alias) != 0:
204 txt += f
", alias='{self.alias}'"
208 """Declare the filters via afw.image.Filter.
210 aliases =
set(self.alias)
211 name = self.physical_filter
212 if self.band
is not None:
214 aliases.add(self.physical_filter)
215 if self.afw_name
is not None:
217 aliases.add(self.physical_filter)
219 if self.afw_name
is not None:
220 if self.band
is not None:
221 aliases.add(self.band)
222 lsst.afw.image.utils.defineFilter(name,
223 lambdaEff=self.lambdaEff,
224 lambdaMin=self.lambdaMin,
225 lambdaMax=self.lambdaMax,
226 alias=sorted(aliases))
229 """Create a complete FilterLabel for this filter.
231 return lsst.afw.image.FilterLabel(band=self.band, physical=self.physical_filter)
def __init__(self, *filters)
dictionary physical_to_band
def __getitem__(self, key)
def makeFilterLabel(self)