35 from .makeDecamRawVisitInfo
import MakeDecamRawVisitInfo
37 np.seterr(divide=
"ignore")
39 __all__ = [
"DecamMapper"]
43 packageName =
'obs_decam' 45 MakeRawVisitInfoClass = MakeDecamRawVisitInfo
48 1:
'S29', 2:
'S30', 3:
'S31', 4:
'S25', 5:
'S26', 6:
'S27', 7:
'S28', 8:
'S20', 9:
'S21',
49 10:
'S22', 11:
'S23', 12:
'S24', 13:
'S14', 14:
'S15', 15:
'S16', 16:
'S17', 17:
'S18',
50 18:
'S19', 19:
'S8', 20:
'S9', 21:
'S10', 22:
'S11', 23:
'S12', 24:
'S13', 25:
'S1', 26:
'S2',
51 27:
'S3', 28:
'S4', 29:
'S5', 30:
'S6', 31:
'S7', 32:
'N1', 33:
'N2', 34:
'N3', 35:
'N4',
52 36:
'N5', 37:
'N6', 38:
'N7', 39:
'N8', 40:
'N9', 41:
'N10', 42:
'N11', 43:
'N12', 44:
'N13',
53 45:
'N14', 46:
'N15', 47:
'N16', 48:
'N17', 49:
'N18', 50:
'N19', 51:
'N20', 52:
'N21',
54 53:
'N22', 54:
'N23', 55:
'N24', 56:
'N25', 57:
'N26', 58:
'N27', 59:
'N28', 60:
'N29',
57 def __init__(self, inputPolicy=None, **kwargs):
58 policyFile = Policy.defaultPolicyFile(self.
packageName,
"DecamMapper.yaml",
"policy")
59 policy =
Policy(policyFile)
61 super(DecamMapper, self).
__init__(policy, os.path.dirname(policyFile), **kwargs)
65 afwImageUtils.defineFilter(
'u', lambdaEff=350, lambdaMin=305, lambdaMax=403, 66 alias=['u DECam c0006 3500.0 1000.0'])
67 afwImageUtils.defineFilter(
'g', lambdaEff=450, lambdaMin=394, lambdaMax=555,
68 alias=[
'g DECam SDSS c0001 4720.0 1520.0'])
69 afwImageUtils.defineFilter(
'r', lambdaEff=600, lambdaMin=562, lambdaMax=725, 70 alias=['r DECam SDSS c0002 6415.0 1480.0'])
71 afwImageUtils.defineFilter(
'i', lambdaEff=750, lambdaMin=699, lambdaMax=870,
72 alias=[
'i DECam SDSS c0003 7835.0 1470.0'])
73 afwImageUtils.defineFilter(
'z', lambdaEff=900, lambdaMin=837, lambdaMax=1016,
74 alias=[
'z DECam SDSS c0004 9260.0 1520.0'])
75 afwImageUtils.defineFilter(
'y', lambdaEff=1000, lambdaMin=941, lambdaMax=1080,
76 alias=[
'Y DECam c0005 10095.0 1130.0',
'Y'])
77 afwImageUtils.defineFilter(
'VR', lambdaEff=630, lambdaMin=490, lambdaMax=765,
78 alias=[
'VR DECam c0007 6300.0 2600.0'])
79 afwImageUtils.defineFilter(
'N964', lambdaEff=964, alias=[
'N964 DECam c0008 9645.0 94.0'])
80 afwImageUtils.defineFilter(
'SOLID', lambdaEff=0, alias=[
'solid'])
86 for datasetType
in (
"raw",
"instcal",
"dqmask",
"wtmap"):
87 self.
mappings[datasetType].keyDict.update({
'ccdnum': int})
88 self.
mappings[
"raw"].keyDict.update({
'object': str})
92 DecamMapper._nbit_tract = 10
93 DecamMapper._nbit_patch = 10
94 DecamMapper._nbit_filter = 4
95 DecamMapper._nbit_id = 64 - (DecamMapper._nbit_tract +
96 2*DecamMapper._nbit_patch +
97 DecamMapper._nbit_filter)
99 def _extractDetectorName(self, dataId):
102 return DecamMapper.detectorNames[copyId[
'ccdnum']]
104 raise RuntimeError(
"No name found for dataId: %s"%(dataId))
106 def _transformId(self, dataId):
107 copyId = CameraMapper._transformId(self, dataId)
109 copyId.setdefault(
"ccdnum", copyId[
"ccd"])
118 def _computeCcdExposureId(self, dataId):
119 """Compute the 64-bit (long) identifier for a CCD exposure. 124 Data identifier with visit, ccd. 129 Integer identifier for a CCD exposure. 132 visit = copyId[
'visit']
133 ccdnum = copyId[
'ccdnum']
134 return int(
"%07d%02d" % (visit, ccdnum))
136 def _computeCoaddExposureId(self, dataId, singleFilter):
137 """Compute the 64-bit (long) identifier for a coadd. 142 Data identifier with tract and patch. 143 singleFilter : `bool` 144 True means the desired ID is for a single-filter coadd, 145 in which case the dataId must contain filter. 150 Unique integer identifier. 152 tract =
int(dataId[
'tract'])
153 if tract < 0
or tract >= 2**DecamMapper._nbit_tract:
154 raise RuntimeError(
'tract not in range [0,%d)' % (2**DecamMapper._nbit_tract))
155 patchX, patchY = [
int(x)
for x
in dataId[
'patch'].split(
',')]
156 for p
in (patchX, patchY):
157 if p < 0
or p >= 2**DecamMapper._nbit_patch:
158 raise RuntimeError(
'patch component not in range [0, %d)' % 2**DecamMapper._nbit_patch)
159 oid = (((tract << DecamMapper._nbit_patch) + patchX) << DecamMapper._nbit_patch) + patchY
161 return (oid << DecamMapper._nbit_filter) +
afwImage.Filter(dataId[
'filter']).getId()
168 return 64 - DecamMapper._nbit_id
174 return 64 - DecamMapper._nbit_id
191 dqmArr = dqmask.getArray()
193 mArr = mask.getArray()
194 idxBad = np.where(dqmArr & 1)
195 idxSat = np.where(dqmArr & 2)
196 idxIntrp = np.where(dqmArr & 4)
197 idxCr = np.where(dqmArr & 16)
198 idxBleed = np.where(dqmArr & 64)
199 idxEdge = np.where(dqmArr & 512)
200 mArr[idxBad] |= mask.getPlaneBitMask(
"BAD")
201 mArr[idxSat] |= mask.getPlaneBitMask(
"SAT")
202 mArr[idxIntrp] |= mask.getPlaneBitMask(
"INTRP")
203 mArr[idxCr] |= mask.getPlaneBitMask(
"CR")
204 mArr[idxBleed] |= mask.getPlaneBitMask(
"SAT")
205 mArr[idxEdge] |= mask.getPlaneBitMask(
"EDGE")
209 wtmArr = wtmap.getArray()
210 idxUndefWeight = np.where(wtmArr <= 0)
212 wtmArr[idxUndefWeight] =
min(1e-14, np.min(wtmArr[np.where(wtmArr > 0)]))
214 varim = afwImage.ImageF(var)
219 instcalMap = self.map_instcal(dataId)
220 dqmaskMap = self.map_dqmask(dataId)
221 wtmapMap = self.map_wtmap(dataId)
222 instcalType = getattr(afwImage, instcalMap.getPythonType().split(
".")[-1])
223 dqmaskType = getattr(afwImage, dqmaskMap.getPythonType().split(
".")[-1])
224 wtmapType = getattr(afwImage, wtmapMap.getPythonType().split(
".")[-1])
225 instcal = instcalType(instcalMap.getLocationsWithRoot()[0])
226 dqmask = dqmaskType(dqmaskMap.getLocationsWithRoot()[0])
227 wtmap = wtmapType(wtmapMap.getLocationsWithRoot()[0])
232 mi = afwImage.MaskedImageF(afwImage.ImageF(instcal.getImage()), mask, variance)
235 exp = afwImage.ExposureF(mi, wcs)
238 calib.setFluxMag0(10**(0.4 * md.getScalar(
"MAGZERO")))
241 exp.getInfo().setVisitInfo(visitInfo)
243 for kw
in (
'LTV1',
'LTV2'):
250 """Standardize a raw dataset by converting it to an Exposure. 252 Raw images are MEF files with one HDU for each detector. 256 item : `lsst.afw.image.MaskedImage` 257 The image read by the butler. 263 result : `lsst.afw.image.Exposure` 264 The standardized Exposure. 268 md = exp.getMetadata()
270 exp.getInfo().setVisitInfo(visitInfo)
278 rawPath = self.map_raw(dataId).getLocations()[0]
279 headerPath = re.sub(
r'[\[](\d+)[\]]$',
"[0]", rawPath)
282 exp.getInfo().setVisitInfo(visitInfo)
293 def _standardizeCpMasterCal(self, datasetType, item, dataId, setFilter=False):
294 """Standardize a MasterCal image obtained from NOAO archive into Exposure 296 These MasterCal images are MEF files with one HDU for each detector. 297 Some WCS header, eg CTYPE1, exists only in the zeroth extensionr, 298 so info in the zeroth header need to be copied over to metadata. 303 Dataset type ("bias" or "flat"). 304 item : `lsst.afw.image.MaskedImage` 305 The image read by the butler. 309 Whether to set the filter in the Exposure. 313 result : `lsst.afw.image.Exposure` 314 The standardized Exposure. 317 md = item.getMetadata()
318 masterCalMap = getattr(self,
"map_" + datasetType)
319 masterCalPath = masterCalMap(dataId).getLocationsWithRoot()[0]
320 headerPath = re.sub(
r'[\[](\d+)[\]]$',
"[0]", masterCalPath)
322 for kw
in (
'CTYPE1',
'CTYPE2',
'CRVAL1',
'CRVAL2',
'CUNIT1',
'CUNIT2',
323 'CD1_1',
'CD1_2',
'CD2_1',
'CD2_2'):
324 if kw
in md0.paramNames()
and kw
not in md.paramNames():
325 md.add(kw, md0.getScalar(kw))
342 """Map defects dataset with the calibration registry. 344 Overriding the method so to use CalibrationMapping policy, 345 instead of looking up the path in defectRegistry as currently 346 implemented in CameraMapper. 355 result : `lsst.daf.persistence.ButlerLocation` 357 return self.
mappings[
"defects"].
map(self, dataId=dataId, write=write)
360 """Return a defect list based on butlerLocation returned by map_defects. 362 Use all nonzero pixels in the Community Pipeline Bad Pixel Masks. 366 butlerLocation : `lsst.daf.persistence.ButlerLocation` 367 Butler Location with path to defects FITS. 373 result : `lsst.meas.algorithms.DefectListT` 375 bpmFitsPath = butlerLocation.getLocationsWithRoot()[0]
376 bpmImg = afwImage.ImageU(bpmFitsPath, allowUnsafe=
True)
377 idxBad = np.nonzero(bpmImg.getArray())
378 mim = afwImage.MaskedImageU(bpmImg.getDimensions())
379 mim.getMask().getArray()[idxBad] |= mim.getMask().getPlaneBitMask(
"BAD")
380 return isr.getDefectListFromMask(mim,
"BAD")
383 """Return the defect list as it is. Do not standardize it to Exposure. 389 """Directory containing linearizers""" 392 return os.path.join(packageDir,
"decam",
"linearizer")
395 """Map a linearizer""" 397 location =
"%02d.fits" % (dataId[
"ccdnum"])
399 pythonType=
"lsst.ip.isr.LinearizeSquared",
401 storageName=
"PickleStorage",
402 locationList=[location],
def bypass_instcal(self, datasetType, pythonType, butlerLocation, dataId)
def bypass_deepCoaddId(self, datasetType, pythonType, location, dataId)
def translate_dqmask(self, dqmask)
def _standardizeExposure(self, mapping, item, dataId, filter=True, trimmed=True, setVisitInfo=True)
def std_defects(self, item, dataId)
def getLinearizerDir(cls)
def std_fringe(self, item, dataId)
def std_cpFlat(self, item, dataId)
def _standardizeCpMasterCal(self, datasetType, item, dataId, setFilter=False)
def std_flat(self, item, dataId)
def bypass_dcrMergedCoaddId(self, datasetType, pythonType, location, dataId)
def std_cpBias(self, item, dataId)
Describe an exposure's calibration.
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT >> image, typename std::shared_ptr< Mask< MaskPixelT >> mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT >> variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
def _computeCcdExposureId(self, dataId)
def bypass_ccdExposureId(self, datasetType, pythonType, location, dataId)
def bypass_dcrCoaddId(self, datasetType, pythonType, location, dataId)
std::shared_ptr< Exposure< ImagePixelT, MaskPixelT, VariancePixelT > > makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
A function to return an Exposure of the correct type (cf.
def bypass_dcrCoaddId_bits(self, args, kwargs)
def std_bias(self, item, dataId)
def __init__(self, inputPolicy=None, kwargs)
Represent a 2-dimensional array of bitmask pixels.
def map(self, datasetType, dataId, write=False)
def std_dark(self, item, dataId)
def bypass_defects(self, datasetType, pythonType, butlerLocation, dataId)
def bypass_dcrMergedCoaddId_bits(self, args, kwargs)
Holds an integer identifier for an LSST filter.
def bypass_ccdExposureId_bits(self, datasetType, pythonType, location, dataId)
def _computeCoaddExposureId(self, dataId, singleFilter)
def bypass_deepMergedCoaddId(self, datasetType, pythonType, location, dataId)
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
def bypass_deepMergedCoaddId_bits(self, args, kwargs)
def _transformId(self, dataId)
def map_linearizer(self, dataId, write=False)
def translate_wtmap(self, wtmap)
def bypass_deepCoaddId_bits(self, args, kwargs)
def exposureFromImage(image, dataId=None, mapper=None, logger=None, setVisitInfo=True)
def std_raw(self, item, dataId)
def map_defects(self, dataId, write=False)