Skip to content

Commit

Permalink
Merge pull request #229 from lsst/tickets/DM-35035
Browse files Browse the repository at this point in the history
DM-35035: Remove gen2to3 code from instrument class
  • Loading branch information
timj committed Jul 26, 2022
2 parents 845e7a1 + 4027c58 commit fa057e3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 58 deletions.
45 changes: 0 additions & 45 deletions python/lsst/obs/decam/_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from lsst.afw.cameraGeom import makeCameraFromPath, CameraConfig
from lsst.obs.base import Instrument, VisitSystem
from lsst.obs.base.gen2to3 import BandToPhysicalFilterKeyHandler, TranslatorFactory
from lsst.obs.decam.decamFilters import DECAM_FILTER_DEFINITIONS

from lsst.utils.introspection import get_full_type_name
Expand Down Expand Up @@ -111,47 +110,3 @@ def getRawFormatter(self, dataId):
# local import to prevent circular dependency
from .rawFormatter import DarkEnergyCameraRawFormatter
return DarkEnergyCameraRawFormatter

def makeDataIdTranslatorFactory(self) -> TranslatorFactory:
# Docstring inherited from lsst.obs.base.Instrument.
factory = TranslatorFactory()
factory.addGenericInstrumentRules(self.getName(), calibFilterType="band",
detectorKey="ccdnum")
# 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")
factory.addRule(_DecamBandToPhysicalFilterKeyHandler(self.filterDefinitions),
instrument=self.getName(),
gen2keys=("filter",),
consume=("filter",),
datasetTypeName="fringe")
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: 0 additions & 13 deletions tests/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ 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 fa057e3

Please sign in to comment.