Skip to content

Commit

Permalink
Initial reorganization for new Instrument base class
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Sep 11, 2019
1 parent 0ce3019 commit ce84327
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 119 deletions.
85 changes: 34 additions & 51 deletions python/lsst/obs/lsst/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,37 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np

from lsst.afw.image.utils import defineFilter


__all__ = ("FilterDefinition", "getFilterDefinitions")


class FilterDefinition:
"""A temporary stand-in for the afw.image Filter classes used to
share initialization between Gen2 Mappers and Gen3 Instruments.
"""

def __init__(self, name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=()):
self.name = name
self.lambdaEff = lambdaEff
self.lambdaMin = lambdaMin
self.lambdaMax = lambdaMax
self.alias = alias

def declare(self):
"""Declare the filter to via afw.image.Filter.
"""
defineFilter(self.name, lambdaEff=self.lambdaEff,
lambdaMin=self.lambdaMin, lambdaMax=self.lambdaMax,
alias=self.alias)

def __str__(self):
return self.name


def getFilterDefinitions():
"""Return a list of FilterDefinition objects for the main LSST camera.
The order of the filters matters as their IDs are used to generate at
least some object IDs (e.g. on coadds) and changing the order will
invalidate old IDs.
"""
return [
FilterDefinition('NONE', 0.0, alias=['no_filter', "OPEN"]),
FilterDefinition('275CutOn', 0.0, alias=[]),
FilterDefinition('550CutOn', 0.0, alias=[]),
# The LSST Filters from L. Jones 04/07/10
FilterDefinition('u', lambdaEff=364.59, lambdaMin=324.0, lambdaMax=395.0),
FilterDefinition('g', lambdaEff=476.31, lambdaMin=405.0, lambdaMax=552.0),
FilterDefinition('r', lambdaEff=619.42, lambdaMin=552.0, lambdaMax=691.0),
FilterDefinition('i', lambdaEff=752.06, lambdaMin=818.0, lambdaMax=921.0),
FilterDefinition('z', lambdaEff=866.85, lambdaMin=922.0, lambdaMax=997.0),
# official y filter
FilterDefinition('y', lambdaEff=971.68, lambdaMin=975.0, lambdaMax=1075.0, alias=['y4']),
]
__all__ = ()

from lsst.obs.base import FilterDefinition, FilterDefinitionCollection


LSSTCAM_FILTER_DEFINITIONS = FilterDefinitionCollection(
FilterDefinition(physical_filter="NONE",
lambdaEff=0.0,
alias={"no_filter", "OPEN"}),
FilterDefinition(physical_filter="275CutOn",
lambdaEff=0.0),
FilterDefinition(physical_filter="550CutOn",
lambdaEff=0.0),
# The LSST Filters from L. Jones 04/07/10
FilterDefinition(physical_filter="u",
abstract_filter="u",
lambdaEff=364.59, lambdaMin=324.0, lambdaMax=395.0),
FilterDefinition(physical_filter="g",
abstract_filter="g",
lambdaEff=476.31, lambdaMin=405.0, lambdaMax=552.0),
FilterDefinition(physical_filter="r",
abstract_filter="r",
lambdaEff=619.42, lambdaMin=552.0, lambdaMax=691.0),
FilterDefinition(physical_filter="i",
abstract_filter="i",
lambdaEff=752.06, lambdaMin=818.0, lambdaMax=921.0),
FilterDefinition(physical_filter="z",
abstract_filter="z",
lambdaEff=866.85, lambdaMin=922.0, lambdaMax=997.0),
# official y filter
FilterDefinition(physical_filter="y",
abstract_filter="y",
lambdaEff=971.68, lambdaMin=975.0, lambdaMax=1075.0, alias=['y4']),
)
84 changes: 25 additions & 59 deletions python/lsst/obs/lsst/gen3/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__all__ = ("LsstCamInstrument", "ImsimInstrument", "PhosimInstrument", "Ts8Instrument",
"LatissInstrument", "Ts3Instrument", "UcdCamInstrument", "LsstComCamInstrument")

import os.path
from dateutil import parser

from lsst.utils import getPackageDir
from lsst.daf.butler.instrument import Instrument, addUnboundedCalibrationLabel
from lsst.daf.butler import DatasetType, DataId
from lsst.pipe.tasks.read_defects import read_all_defects

from ..filters import getFilterDefinitions
from ..filters import LSSTCAM_FILTER_DEFINITIONS
from ..lsstCamMapper import LsstCamMapper
from ..comCam import LsstComCamMapper
from ..phosim import PhosimMapper
Expand All @@ -37,9 +39,7 @@
from ..ts3 import Ts3Mapper
from ..ucd import UcdMapper


__all__ = ("LsstCamInstrument", "ImsimInstrument", "PhosimInstrument", "Ts8Instrument",
"LatissInstrument", "Ts3Instrument", "UcdCamInstrument", "LsstComCamInstrument")
PACKAGE_DIR = getPackageDir("obs_lsst")


class LsstCamInstrument(Instrument):
Expand Down Expand Up @@ -78,30 +78,11 @@ class LsstCamInstrument(Instrument):
do not provide a way to add new physical_filters, they will in the
future.
"""

instrument = "LSST"
filterDefinitions = LSSTCAM_FILTER_DEFINITIONS
instrument = "LSSTGeneric"
policyName = None

def __init__(self, camera=None, filters=None):
if camera is None:
camera = LsstCamMapper().camera
self.camera = camera
if filters is None:
filters = getFilterDefinitions()
self.detectors = [self.extractDetectorEntry(camGeomDetector)
for camGeomDetector in camera]
self.physicalFilters = []
for filterDef in filters:
# For the standard broadband filters, we use the smae
# single-letter name for both the PhysicalFilter and the
# associated AbstractFilter. For other filters we don't
# assign an abstract_filter.
self.physicalFilters.append(
dict(
physical_filter=filterDef.name,
abstract_filter=filterDef.name if filterDef.name in "ugrizy" else None
)
)
configPaths = [os.path.join(PACKAGE_DIR, "config"),
os.path.join(PACKAGE_DIR, "config", policyName)]

@classmethod
def getName(cls):
Expand All @@ -123,19 +104,13 @@ def register(self, registry):
"visit_max": obsMax,
"exposure_max": obsMax})

for detector in self.camera:
for detector in self.getCamera():
detInfo = self.extractDetectorEntry(detector)
registry.addDimensionEntry(
"detector", dataId, **detInfo
)

for physical in self.physicalFilters:
registry.addDimensionEntry(
"physical_filter",
dataId,
physical_filter=physical["physical_filter"],
abstract_filter=physical["abstract_filter"]
)
self._registerFilters(registry)

def extractDetectorEntry(self, camGeomDetector):
"""Create a Gen3 Detector entry dict from a cameraGeom.Detector.
Expand All @@ -160,15 +135,6 @@ def extractDetectorEntry(self, camGeomDetector):
raft=group,
)

def applyConfigOverrides(self, name, config):
# Docstring inherited from Instrument.applyConfigOverrides
packageDir = getPackageDir("obs_lsst")
roots = [os.path.join(packageDir, "config"), os.path.join(packageDir, "config", self.policyName)]
for root in roots:
path = os.path.join(root, f"{name}.py")
if os.path.exists(path):
config.load(path)

def writeCuratedCalibrations(self, butler):
"""Write human-curated calibration Datasets to the given Butler with
the appropriate validity ranges.
Expand Down Expand Up @@ -220,8 +186,8 @@ class LsstComCamInstrument(LsstCamInstrument):
instrument = "LSST-ComCam"
policyName = "comCam"

def __init__(self):
super().__init__(camera=LsstComCamMapper().camera)
def getCamera(self):
return LsstComCamMapper().camera


class ImsimInstrument(LsstCamInstrument):
Expand All @@ -231,8 +197,8 @@ class ImsimInstrument(LsstCamInstrument):
instrument = "LSST-ImSim"
policyName = "imsim"

def __init__(self):
super().__init__(camera=ImsimMapper().camera)
def getCamera(self):
return ImsimMapper().camera


class PhosimInstrument(LsstCamInstrument):
Expand All @@ -242,8 +208,8 @@ class PhosimInstrument(LsstCamInstrument):
instrument = "LSST-PhoSim"
policyName = "phosim"

def __init__(self):
super().__init__(camera=PhosimMapper().camera)
def getCamera(self):
return PhosimMapper().camera


class Ts8Instrument(LsstCamInstrument):
Expand All @@ -253,8 +219,8 @@ class Ts8Instrument(LsstCamInstrument):
instrument = "LSST-TS8"
policyName = "ts8"

def __init__(self):
super().__init__(camera=Ts8Mapper().camera)
def getCamera(self):
return Ts8Mapper().camera


class UcdCamInstrument(LsstCamInstrument):
Expand All @@ -264,8 +230,8 @@ class UcdCamInstrument(LsstCamInstrument):
instrument = "UCDCam"
policyName = "ucd"

def __init__(self):
super().__init__(camera=UcdMapper().camera)
def getCamera(self):
return UcdMapper().camera


class Ts3Instrument(LsstCamInstrument):
Expand All @@ -275,8 +241,8 @@ class Ts3Instrument(LsstCamInstrument):
instrument = "LSST-TS3"
policyName = "ts3"

def __init__(self):
super().__init__(camera=Ts3Mapper().camera)
def getCamera(self):
return Ts3Mapper().camera


class LatissInstrument(LsstCamInstrument):
Expand All @@ -286,8 +252,8 @@ class LatissInstrument(LsstCamInstrument):
instrument = "LATISS"
policyName = "latiss"

def __init__(self):
super().__init__(camera=LatissMapper().camera)
def getCamera(self):
return LatissMapper().camera

def extractDetectorEntry(self, camGeomDetector):
# Override to remove group (raft) name, because LATISS only has one
Expand Down
11 changes: 2 additions & 9 deletions python/lsst/obs/lsst/lsstCamMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import lsst.log
import lsst.geom
import lsst.utils as utils
import lsst.afw.image.utils as afwImageUtils
import lsst.afw.image as afwImage
from lsst.afw.fits import readMetadata
from lsst.obs.base import CameraMapper, MakeRawVisitInfoViaObsInfo
Expand All @@ -36,7 +35,7 @@
from .translators import LsstCamTranslator
from astro_metadata_translator import fix_header

from .filters import getFilterDefinitions
from .filters import LSSTCAM_FILTER_DEFINITIONS
from .assembly import attachRawWcsFromBoresight, fixAmpGeometry, assembleUntrimmedCcd

__all__ = ["LsstCamMapper", "LsstCamMakeRawVisitInfo"]
Expand Down Expand Up @@ -159,7 +158,7 @@ def __init__(self, inputPolicy=None, **kwargs):
for d in (self.mappings, self.exposures):
d['raw'] = d['_raw']

self.defineFilters()
LSSTCAM_FILTER_DEFINITIONS.defineFilters()

LsstCamMapper._nbit_tract = 16
LsstCamMapper._nbit_patch = 5
Expand Down Expand Up @@ -197,12 +196,6 @@ def _makeCamera(cls, policy=None, repositoryDir=None, cameraYamlFile=None):

return yamlCamera.makeCamera(cameraYamlFile)

@classmethod
def defineFilters(cls):
afwImageUtils.resetFilters()
for filterDef in getFilterDefinitions():
filterDef.declare()

def _getRegistryValue(self, dataId, k):
"""Return a value from a dataId, or look it up in the registry if it
isn't present."""
Expand Down

0 comments on commit ce84327

Please sign in to comment.