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")
29 import collections.abc
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.
61 return "FilterDefinitions(" +
', '.join(str(f)
for f
in self.
_filters) +
')'
64 """Define all the filters to `lsst.afw.image.Filter`.
66 `~lsst.afw.image.Filter` objects are singletons, so we protect against
67 filters being defined multiple times.
72 Raised if any other `FilterDefinitionCollection` has already called
79 FilterDefinitionCollection._defined = self
84 msg = f
"afw Filters were already defined on: {self._defined}"
85 raise RuntimeError(msg)
89 """Reset the afw Filter definitions and clear the `defined` singleton.
90 Use this in unittests that define different filters.
92 lsst.afw.image.utils.resetFilters()
96 """Return the FilterDefinitions that match a particular name.
98 This method makes no attempt to prioritize, e.g., band names over
99 physical filter names; any definition that makes *any* reference
100 to the name is returned.
105 The name to search for. May be any band, physical, or alias name.
109 matches : `set` [`FilterDefinition`]
110 All FilterDefinitions containing ``name`` as one of their
115 if name == filter.physical_filter
or name == filter.band
or name == filter.afw_name \
116 or name
in filter.alias:
121 @dataclasses.dataclass(frozen=
True)
123 """The definition of an instrument's filter bandpass.
125 This class is used to interface between the `~lsst.afw.image.Filter` class
126 and the Gen2 `~lsst.daf.persistence.CameraMapper` and Gen3
127 `~lsst.obs.base.Instruments` and ``physical_filter``/``band``
128 `~lsst.daf.butler.Dimension`.
130 This class is likely temporary, until we have a better versioned filter
131 definition system that includes complete transmission information.
135 """The name of a filter associated with a particular instrument: unique for
136 each piece of glass. This should match the exact filter name used in the
137 observatory's metadata.
139 This name is used to define the ``physical_filter`` gen3 Butler Dimension.
141 If neither ``band`` or ``afw_name`` is defined, this is used
142 as the `~lsst.afw.image.Filter` ``name``, otherwise it is added to the
143 list of `~lsst.afw.image.Filter` aliases.
147 """The effective wavelength of this filter (nm)."""
150 """The generic name of a filter not associated with a particular instrument
151 (e.g. `r` for the SDSS Gunn r-band, which could be on SDSS, LSST, or HSC).
153 Not all filters have an abstract filter: engineering or test filters may
154 not have a genericly-termed filter name.
156 If specified and if `afw_name` is None, this is used as the
157 `~lsst.afw.image.Filter` ``name`` field, otherwise it is added to the list
158 of `~lsst.afw.image.Filter` aliases.
162 """If not None, the name of the `~lsst.afw.image.Filter` object.
164 This is distinct from physical_filter and band to maintain
165 backwards compatibility in some obs packages.
166 For example, for HSC there are two distinct ``r`` and ``i`` filters, named
167 ``r/r2`` and ``i/i2``.
170 lambdaMin: float = np.nan
171 """The minimum wavelength of this filter (nm; defined as 1% throughput)"""
172 lambdaMax: float = np.nan
173 """The maximum wavelength of this filter (nm; defined as 1% throughput)"""
175 alias: set = frozenset()
176 """Alternate names for this filter. These are added to the
177 `~lsst.afw.image.Filter` alias list.
182 if not isinstance(self.alias, frozenset):
183 object.__setattr__(self,
'alias', frozenset(self.alias))
186 txt = f
"FilterDefinition(physical_filter='{self.physical_filter}', lambdaEff='{self.lambdaEff}'"
187 if self.band
is not None:
188 txt += f
", band='{self.band}'"
189 if self.afw_name
is not None:
190 txt += f
", afw_name='{self.afw_name}'"
191 if not np.isnan(self.lambdaMin):
192 txt += f
", lambdaMin='{self.lambdaMin}'"
193 if not np.isnan(self.lambdaMax):
194 txt += f
", lambdaMax='{self.lambdaMax}'"
195 if len(self.alias) != 0:
196 txt += f
", alias='{self.alias}'"
200 """Declare the filters via afw.image.Filter.
202 aliases =
set(self.alias)
203 name = self.physical_filter
204 if self.band
is not None:
206 aliases.add(self.physical_filter)
207 if self.afw_name
is not None:
209 aliases.add(self.physical_filter)
211 if self.afw_name
is not None:
212 if self.band
is not None:
213 aliases.add(self.band)
214 lsst.afw.image.utils.defineFilter(name,
215 lambdaEff=self.lambdaEff,
216 lambdaMin=self.lambdaMin,
217 lambdaMax=self.lambdaMax,
218 alias=sorted(aliases))
221 """Create a complete FilterLabel for this filter.
223 return lsst.afw.image.FilterLabel(band=self.band, physical=self.physical_filter)