Skip to content

Commit

Permalink
Merge branch 'tickets/DM-28439'
Browse files Browse the repository at this point in the history
  • Loading branch information
kfindeisen committed Mar 24, 2021
2 parents c0d59e3 + 2adeebe commit bfe4b77
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
31 changes: 28 additions & 3 deletions python/lsst/obs/decam/_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,36 @@ def makeDataIdTranslatorFactory(self) -> TranslatorFactory:
factory = TranslatorFactory()
factory.addGenericInstrumentRules(self.getName(), calibFilterType="band",
detectorKey="ccdnum")
# DECam calibRegistry entries are bands, but we need physical_filter
# in the gen3 registry.
factory.addRule(BandToPhysicalFilterKeyHandler(self.filterDefinitions),
# DECam calibRegistry entries are bands or aliases, but we need
# physical_filter in the gen3 registry.
factory.addRule(_DecamBandToPhysicalFilterKeyHandler(self.filterDefinitions),
instrument=self.getName(),
gen2keys=("filter",),
consume=("filter",),
datasetTypeName="cpFlat")
return factory


class _DecamBandToPhysicalFilterKeyHandler(BandToPhysicalFilterKeyHandler):
"""A specialization of `~lsst.obs.base.gen2to3.BandToPhysicalKeyHandler`
that allows filter aliases to be used as alternative band names.
Parameters
----------
filterDefinitions : `lsst.obs.base.FilterDefinitionCollection`
The filters to translate from Gen 2 to Gen 3.
"""

__slots__ = ("_aliasMap",)

def __init__(self, filterDefinitions):
super().__init__(filterDefinitions)
self._aliasMap = {alias: d.physical_filter for d in filterDefinitions for alias in d.alias}

def extract(self, gen2id, *args, **kwargs):
# Expect _aliasMap to be small, so try it first
gen2Filter = gen2id["filter"]
if gen2Filter in self._aliasMap:
return self._aliasMap[gen2Filter]
else:
return super().extract(gen2id, *args, **kwargs)
13 changes: 13 additions & 0 deletions tests/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ def setUp(self):
self.instrument = lsst.obs.decam.DarkEnergyCamera()


class TestDecamTranslators(lsst.utils.tests.TestCase):
def setUp(self):
super().setUp()
self.filters = lsst.obs.decam.DarkEnergyCamera().filterDefinitions

def testDecamBandToPhysicalFilter(self):
translator = lsst.obs.decam._instrument._DecamBandToPhysicalFilterKeyHandler(self.filters)
self.assertEqual(translator.extract({"filter": "g"}), "g DECam SDSS c0001 4720.0 1520.0")
self.assertEqual(translator.extract({"filter": "y"}), "Y DECam c0005 10095.0 1130.0")
self.assertEqual(translator.extract({"filter": "Y"}), "Y DECam c0005 10095.0 1130.0")
self.assertEqual(translator.extract({"filter": "fake"}), "fake")


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass

Expand Down

0 comments on commit bfe4b77

Please sign in to comment.