Coverage for python/lsst/obs/cfht/megacamMapper.py : 26%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # LSST Data Management System # Copyright 2012 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
# Solely to get boost serialization registrations for Measurement subclasses
"""Camera Mapper for CFHT MegaCam."""
policyFile = Policy.defaultPolicyFile("obs_cfht", "MegacamMapper.yaml", "policy") policy = Policy(policyFile) super(MegacamMapper, self).__init__(policy, os.path.dirname(policyFile), **kwargs)
# The "ccd" provided by the user is translated through the registry into an extension name for the "raw" # template. The template therefore doesn't include "ccd", so we need to ensure it's explicitly included # so the ArgumentParser can recognise and accept it.
self.exposures['raw'].keyDict['ccd'] = int
afwImageUtils.defineFilter('u', lambdaEff=374, alias="u.MP9301") afwImageUtils.defineFilter('u2', lambdaEff=354, alias="u.MP9302") afwImageUtils.defineFilter('g', lambdaEff=487, alias="g.MP9401") afwImageUtils.defineFilter('g2', lambdaEff=472, alias="g.MP9402") afwImageUtils.defineFilter('r', lambdaEff=628, alias="r.MP9601") afwImageUtils.defineFilter('r2', lambdaEff=640, alias="r.MP9602") afwImageUtils.defineFilter('i', lambdaEff=778, alias="i.MP9701") afwImageUtils.defineFilter('i2', lambdaEff=764, alias="i.MP9702") afwImageUtils.defineFilter('i3', lambdaEff=776, alias="i.MP9703") afwImageUtils.defineFilter('z', lambdaEff=1170, alias="z.MP9801") afwImageUtils.defineFilter('z2', lambdaEff=926, alias="z.MP9901")
# define filters? self.filterIdMap = dict(u=0, g=1, r=2, i=3, z=4, i2=5, u2=6, g2=7, r2=8, i3=9, z2=10)
# Ensure each dataset type of interest knows about the full range of keys available from the registry keys = {'runId': str, 'object': str, 'visit': int, 'ccd': int, 'extension': int, 'state': str, 'filter': str, 'date': str, 'taiObs': str, 'expTime': float, } for name in ("raw", "calexp", "postISRCCD", "src", "icSrc", "icMatch"): self.mappings[name].keyDict.update(keys)
"""Return a defect based on the butler location returned by map_defects.
Parameters ---------- butlerLocation : `lsst.daf.persistence.ButlerLocation` A ButlerLocation with locationList = path to defects FITS file. dataId : `dict` The usual data ID; "ccd" must be set.
Notes ----- The name "bypass_XXX" means the butler makes no attempt to convert the ButlerLocation into an object, which is what we want for now, since that conversion is a bit tricky. """ (ccdKey, ccdSerial) = self._getCcdKeyVal(dataId) defectsFitsPath = butlerLocation.locationList[0] with pyfits.open(defectsFitsPath) as hduList: for hdu in hduList[1:]: if str(hdu.header["SERIAL"]) != ccdSerial: continue
defectList = [] for data in hdu.data: bbox = afwGeom.Box2I( afwGeom.Point2I(int(data['x0']), int(data['y0'])), afwGeom.Extent2I(int(data['width']), int(data['height'])), ) defectList.append(afwImage.DefectBase(bbox)) return defectList
raise RuntimeError("No defects for ccdSerial %s in %s" % (ccdSerial, defectsFitsPath))
"""Find the defects for a given CCD.
Parameters ---------- dataId : `dict` Dataset identifier.
Returns ------- `str` or None Path to the defects file or None if not available. """
if self.registry is None: raise RuntimeError("No registry for defect lookup")
rows = self.registry.executeQuery( ("defects",), ("raw",), [("visit", "?"), ("ccd", "?")], None, (dataId['visit'], dataId['ccd']), ) if len(rows) == 0: return None
if len(rows) == 1: return os.path.join(self.defectPath, rows[0][0]) else: raise RuntimeError("Querying for defects (%s) returns %d files: %s" % (dataId['id'], len(rows), ", ".join([_[0] for _ in rows])))
ccdName = self._extractDetectorName(dataId) return ("ccdSerial", self.camera[ccdName].getSerial())
return "ccd%02d" % dataId['ccd']
"""Compute the 64-bit (long) identifier for a CCD exposure.
Parameters ---------- dataId : `dict` Data identifier with visit, ccd. """ pathId = self._transformId(dataId) visit = int(pathId['visit']) ccd = int(pathId['ccd']) return visit * 36 + ccd
"""Hook to retrieve identifier for CCD""" return self._computeCcdExposureId(dataId)
"""Hook to retrieve number of bits in identifier for CCD""" return 32
"""Compute the 64-bit (long) identifier for a coadd.
Parameters ---------- dataId : `dict` Data identifier with tract and patch. singleFilter : `bool` True means the desired ID is for a single-filter coadd, in which case dataId must contain filter. """ tract = int(dataId['tract']) if tract < 0 or tract >= 128: raise RuntimeError('tract not in range [0,128)') patchX, patchY = list(map(int, dataId['patch'].split(','))) for p in (patchX, patchY): if p < 0 or p >= 2**13: raise RuntimeError('patch component not in range [0, 8192)') id = (tract * 2**13 + patchX) * 2**13 + patchY if singleFilter: return id * 8 + self.filterIdMap[dataId['filter']] return id
return 1 + 7 + 13*2 + 3
return self._computeCoaddExposureId(dataId, True)
return self._computeCoaddExposureId(dataId, False)
"""Compute the 64-bit (long) identifier for a Stack exposure.
Parameters ---------- dataId : `dict` Data identifier with stack, patch, filter """ nPatches = 1000000 return (int(dataId["stack"]) * nPatches + int(dataId["patch"]))
"""Hack up detrend images to remove troublesome keyword""" md = image.getMetadata() removeKeyword(md, 'RADECSYS') # Irrelevant, and use of "GAPPT" breaks wcslib md.set('TELAZ', 0) # Irrelevant, -9999 value breaks VisitInfo, and absence generates a warning md.set('TELALT', 0) # Irrelevant, -9999 value breaks VisitInfo, and absence generates a warning exp = exposureFromImage(image, logger=self.log) return self._standardizeExposure(self.calibrations[detrend], exp, dataId, filter=filter, trimmed=False)
return self._standardizeDetrend("bias", image, dataId, filter=False)
return self._standardizeDetrend("dark", image, dataId, filter=False)
return self._standardizeDetrend("flat", image, dataId, filter=True)
return self._standardizeDetrend("fringe", image, dataId, filter=True)
"""Remove a keyword from a header without raising an exception if it doesn't exist""" if md.exists(key): md.remove(key) |