Skip to content

Commit

Permalink
Use HDU in instcal templates instead of ccdnum.
Browse files Browse the repository at this point in the history
Since an HDU's position in an instcal file does not necessarily correspond to
its CCD number, this template had been mislabling CCDs.

Also removes special handling of decam raw files that was required to track the
hdu field. This code was largely a duplication of the pipe_tasks ingest task,
and can be alleviated with the minor changes to that task (also implemented on
this ticket.)
  • Loading branch information
ctslater committed Jan 10, 2017
1 parent f0fb256 commit 0a13fd3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
6 changes: 3 additions & 3 deletions policy/DecamMapper.paf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exposures: {
template: "%(visit)07d/postISR/postISR-%(visit)07d_%(ccdnum)02d.fits"
}
instcal: {
template: "%(visit)07d/instcal%(visit)07d.fits.fz[%(ccdnum)d]"
template: "%(visit)07d/instcal%(visit)07d.fits.fz[%(hdu)d]"
python: "lsst.afw.image.DecoratedImageF"
persistable: "DecoratedImageF"
storage: "FitsStorage"
Expand All @@ -46,7 +46,7 @@ exposures: {
columns: "ccdnum"
}
dqmask: {
template: "%(visit)07d/dqmask%(visit)07d.fits.fz[%(ccdnum)d]"
template: "%(visit)07d/dqmask%(visit)07d.fits.fz[%(hdu)d]"
python: "lsst.afw.image.ImageU"
persistable: "ImageU"
storage: "FitsStorage"
Expand All @@ -56,7 +56,7 @@ exposures: {
columns: "ccdnum"
}
wtmap: {
template: "%(visit)07d/wtmap%(visit)07d.fits.fz[%(ccdnum)d]"
template: "%(visit)07d/wtmap%(visit)07d.fits.fz[%(hdu)d]"
python: "lsst.afw.image.ImageF"
persistable: "ImageF"
storage: "FitsStorage"
Expand Down
8 changes: 5 additions & 3 deletions python/lsst/obs/decam/decamMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ def __init__(self, inputPolicy=None, **kwargs):
afwImageUtils.defineFilter('SOLID', lambdaEff=0, alias=['solid'])

# The data ID key ccdnum is not directly used in the current policy
# template of the raw dataset, so is not in its keyDict automatically.
# Add it so raw dataset know about the data ID key ccdnum.
self.mappings["raw"].keyDict.update({'ccdnum': int})
# template of the raw and instcal et al. datasets, so is not in its
# keyDict automatically. Add it so the butler know about the data ID key
# ccdnum.
for datasetType in ("raw", "instcal", "dqmask", "wtmap"):
self.mappings[datasetType].keyDict.update({'ccdnum': int})

# The number of bits allocated for fields in object IDs
# TODO: This needs to be updated; also see Trac #2797
Expand Down
44 changes: 15 additions & 29 deletions python/lsst/obs/decam/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def run(self, args):
continue

for info in hduInfoList:
info['hdu'] = None
self.register.addRow(registry, info, dryrun=args.dryrun, create=args.create)

self.register.addVisits(registry, dryrun=args.dryrun)
Expand Down Expand Up @@ -155,39 +154,26 @@ def getInfo(self, filename, filetype="raw"):
phuInfo[self.instcalPrefix] = self.expnumMapper[expnum][self.instcalPrefix]
phuInfo[self.dqmaskPrefix] = self.expnumMapper[expnum][self.dqmaskPrefix]
phuInfo[self.wtmapPrefix] = self.expnumMapper[expnum][self.wtmapPrefix]
for idx, info in enumerate(infoList):
for info in infoList:
expnum = info["visit"]
info[self.instcalPrefix] = self.expnumMapper[expnum][self.instcalPrefix]
info[self.dqmaskPrefix] = self.expnumMapper[expnum][self.dqmaskPrefix]
info[self.wtmapPrefix] = self.expnumMapper[expnum][self.wtmapPrefix]

elif filetype == "raw":
md = afwImage.readMetadata(filename, self.config.hdu)
phuInfo = self.getInfoFromMetadata(md)
# Some data IDs can not be extracted from the zeroth extension
# of the MEF. Add them so Butler does not try to find them
# in the registry which may still yet to be created.
for key in ("ccdnum", "hdu", "ccd"):
if key not in phuInfo:
phuInfo[key] = 0
extnames = set(self.config.extnames)
extnum = 1
infoList = []
while len(extnames) > 0:
extnum += 1
try:
md = afwImage.readMetadata(filename, extnum)
except:
self.log.warn("Error reading %s extensions %s" % (filename, extnames))
break
ext = self.getExtensionName(md)
if ext in extnames:
info = self.getInfoFromMetadata(md, info=phuInfo.copy())
info['hdu'] = extnum - 1
info[self.instcalPrefix] = ""
info[self.dqmaskPrefix] = ""
info[self.wtmapPrefix] = ""
infoList.append(info)
extnames.discard(ext)
phuInfo, infoList = super(DecamParseTask, self).getInfo(filename)
for info in infoList:
info[self.instcalPrefix] = ""
info[self.dqmaskPrefix] = ""
info[self.wtmapPrefix] = ""

# Some data IDs can not be extracted from the zeroth extension
# of the MEF. Add them so Butler does not try to find them
# in the registry which may still yet to be created.
for key in ("ccdnum", "hdu", "ccd"):
if key not in phuInfo:
phuInfo[key] = 0

return phuInfo, infoList

@staticmethod
Expand Down
7 changes: 7 additions & 0 deletions tests/testGetInstcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def testInstcal(self):
for keyword in wcs_keywords:
self.assertNotIn(keyword, exp.getMetadata().paramNames())

def testCcdName(self):
"""Verify that we get the proper CCD for a specified ccdnum."""
dataId = {'visit': 229388, 'ccdnum': 62}
exp = self.butler.get("instcal", dataId, immediate=True)
md = exp.getMetadata()
self.assertEqual(md.get("DETPOS"), "N31")


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass
Expand Down

0 comments on commit 0a13fd3

Please sign in to comment.