/FilterDefinitionSketch.py Secret
Last active
October 1, 2020 18:29
-
-
Save kfindeisen/2cad44303e70ef9648ca04c721dac564 to your computer and use it in GitHub Desktop.
Sketch of FilterDefinition and some examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FilterDefinitionCollection(collections.abc.Sequence): | |
"""A list of multiple `FilterDefinition`. | |
Parameters | |
---------- | |
filters : `~collections.abc.Sequence` [`FilterDefinition`] | |
The filters in this collection. | |
""" | |
def __init__(self, *filters): | |
self._filters = list(filters) | |
def __getitem__(self, key): | |
return self._filters[key] | |
def __len__(self): | |
return len(self._filters) | |
def __repr__(self): | |
return "FilterDefinitionCollection(" + ', '.join(repr(f) for f in self._filters) + ')' | |
@dataclasses.dataclass(frozen=True) | |
class FilterDefinition: | |
"""The definition of an instrument's physical filters. | |
This class is used as the "source of truth" for an instrument's filter | |
defintions, including the information stored in `~lsst.afw.image.FilterLabel`, | |
in the Gen 2 `~lsst.daf.persistence.CameraMapper`, and the Gen3 | |
``physical_filter``/``abstract_filter`` `~lsst.daf.butler.Dimension`. | |
""" | |
physical_filter: str | |
band: str = None | |
# NOTE: I don't have an immediate use for this, other than providing | |
# useful information for those trying to understand what's in a Collection. | |
# It could also be handled by inline comments in the FilterDefinitionCollection, but that seems less reliable? | |
# Providing `doc` at least gives people a place to write notes? | |
doc: str = None | |
"""Additional reference information about this filter.""" | |
def __repr__(self): | |
labels = [] | |
if self.physical_filter is not None: | |
labels.append(f"physical_filter={self.physical_filter!r}") | |
if self.band is not None: | |
labels.append(f"band={self.band!r}") | |
return f"FilterDefinition({", ".join(labels)})" | |
# NOTE: No more `defineFilter()` calls, as there's no longer an afw registry | |
# Examples | |
HSC_FILTER_DEFINITIONS = FilterDefinitionCollection( | |
FilterDefintion(physical_filter="HSC-G", band="g"), | |
FilterDefintion(physical_filter="HSC-R", band="r"), | |
FilterDefintion(physical_filter="HSC-R2", band="r"), | |
FilterDefintion(physical_filter="HSC-NB0387", band="N387"), | |
# These two will require header remapping in astro_metadata_translator, at minimum to prepend "HSC-" | |
FilterDefintion(physical_filter="UNRECOGNISED", doc="filter unknown during observation"), | |
FilterDefintion(physical_filter="None", band="none", doc="No filter in use"), | |
) | |
DECAM_FILTER_DEFINITIONS = FilterDefinitionCollection( | |
FilterDefintion(physical_filter="u DECam c0006 3500.0 1000.0", band="u"), | |
FilterDefintion(physical_filter="g DECam SDSS c0001 4720.0 1520.0", band="g"), | |
FilterDefintion(physical_filter="solid plate 0.0 0.0"), | |
FilterDefintion(physical_filter="VR DECam c0007 6300.0 2600.0", band="VR", doc="very wide visible filter"), | |
) | |
# These are the names currently in obs_lsst; almost certainly not final | |
LSST_FILTER_DEFINITIONS = FilterDefinitionCollection( | |
FilterDefintion(physical_filter="u", band="u"), | |
FilterDefintion(physical_filter="g", band="g"), | |
FilterDefintion(physical_filter="r", band="r"), | |
FilterDefintion(physical_filter="i", band="i"), | |
FilterDefintion(physical_filter="z", band="z"), | |
FilterDefintion(physical_filter="y", band="y"), | |
FilterDefintion(physical_filter="NONE", band="none", doc="No filter in use"), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment