Skip to content

Commit

Permalink
Add map_defects to MegacamMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKrughoff committed May 31, 2019
1 parent 2d25786 commit acf03aa
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion python/lsst/obs/cfht/megacamMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import lsst.afw.geom as afwGeom
import lsst.afw.image.utils as afwImageUtils
import lsst.meas.algorithms as measAlg
import lsst.daf.persistence as dafPersist

from lsst.daf.persistence import Policy
from lsst.obs.base import CameraMapper, exposureFromImage
Expand All @@ -44,7 +45,16 @@ class MegacamMapper(CameraMapper):
def __init__(self, **kwargs):
policyFile = Policy.defaultPolicyFile("obs_cfht", "MegacamMapper.yaml", "policy")
policy = Policy(policyFile)
super(MegacamMapper, self).__init__(policy, os.path.dirname(policyFile), **kwargs)
repositoryDir = os.path.dirname(policyFile)
super(MegacamMapper, self).__init__(policy, repositoryDir, **kwargs)

# Defect registry and root. Defects are stored with the camera and the registry is loaded from the
# camera package, which is on the local filesystem.
self.defectRegistry = None
if 'defects' in policy:
self.defectPath = os.path.join(repositoryDir, policy['defects'])
defectRegistryLocation = os.path.join(self.defectPath, "defectRegistry.sqlite3")
self.defectRegistry = dafPersist.Registry.create(defectRegistryLocation)

# The "ccd" provided by the user is translated through the registry
# into an extension name for the "raw" template. The template
Expand Down Expand Up @@ -85,6 +95,23 @@ def __init__(self, **kwargs):
for name in ("raw", "calexp", "postISRCCD", "src", "icSrc", "icMatch"):
self.mappings[name].keyDict.update(keys)

def map_defects(self, dataId, write=False):
"""Map defects dataset.
Returns
-------
`lsst.daf.butler.ButlerLocation`
Minimal ButlerLocation containing just the locationList field
(just enough information that bypass_defects can use it).
"""
defectFitsPath = self._defectLookup(dataId=dataId)
if defectFitsPath is None:
raise RuntimeError("No defects available for dataId=%s" % (dataId,))

return dafPersist.ButlerLocation(None, None, None, defectFitsPath,
dataId, self,
storage=self.rootStorage)

def bypass_defects(self, datasetType, pythonType, butlerLocation, dataId):
"""Return a defect based on the butler location returned by
map_defects.
Expand Down

0 comments on commit acf03aa

Please sign in to comment.