Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tickets/DM-4820 Improvement of raw data handling in DecamMapper #14

Merged
merged 2 commits into from
Jan 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 11 additions & 14 deletions python/lsst/obs/decam/decamMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ def std_raw(self, item, dataId):
"""Standardize a raw dataset by converting it to an Exposure.

Raw images are MEF files with one HDU for each detector.
Some useful header keywords, such as EXPTIME and MJD-OBS,
exist only in the zeroth extensionr. Here information in
the zeroth header are copied to metadata.
Header keywords EXPTIME and MJD-OBS exist only in the zeroth
extension and are copied to metadata.

@param item: The image read by the butler
@param dataId: Data identifier
Expand All @@ -191,8 +190,8 @@ def std_raw(self, item, dataId):
rawPath = self.map_raw(dataId).getLocations()[0]
headerPath = re.sub(r'[\[](\d+)[\]]$', "[0]", rawPath)
md0 = afwImage.readMetadata(headerPath)
for kw in md0.paramNames():
if kw not in md.paramNames():
for kw in ('EXPTIME', 'MJD-OBS'):
if kw in md0.paramNames() and kw not in md.paramNames():
md.add(kw, md0.get(kw))
return self._standardizeExposure(self.exposures['raw'], exp, dataId,
trimmed=False)
Expand All @@ -216,8 +215,9 @@ def _standardizeMasterCal(self, datasetType, item, dataId, setFilter=False):
masterCalPath = masterCalMap(dataId).getLocations()[0]
headerPath = re.sub(r'[\[](\d+)[\]]$', "[0]", masterCalPath)
md0 = afwImage.readMetadata(headerPath)
for kw in md0.paramNames():
if kw not in md.paramNames():
for kw in ('CTYPE1', 'CTYPE2', 'CRVAL1', 'CRVAL2', 'CUNIT1', 'CUNIT2',
'CD1_1', 'CD1_2', 'CD2_1', 'CD2_2'):
if kw in md0.paramNames() and kw not in md.paramNames():
md.add(kw, md0.get(kw))
wcs = afwImage.makeWcs(md, True)
exp = afwImage.makeExposure(mi, wcs)
Expand Down Expand Up @@ -257,13 +257,10 @@ def bypass_defects(self, datasetType, pythonType, butlerLocation, dataId):
"""
bpmFitsPath = butlerLocation.locationList[0]
bpmImg = afwImage.ImageU(bpmFitsPath)
bpmArr = bpmImg.getArray()
idxBad = np.nonzero(bpmArr)
workImg = afwImage.ImageU(bpmImg.getDimensions())
workImg.getArray()[idxBad] = 1
ds = afwDetection.FootprintSet(workImg, afwDetection.Threshold(0.5))
fpList = ds.getFootprints()
return isr.defectListFromFootprintList(fpList, growFootprints=0)
idxBad = np.nonzero(bpmImg.getArray())
mim = afwImage.MaskedImageU(bpmImg.getDimensions())
mim.getMask().getArray()[idxBad] |= mim.getMask().getPlaneBitMask("BAD")
return isr.getDefectListFromMask(mim, "BAD", growFootprints=0)

def std_defects(self, item, dataId):
"""Return the defect list as it is.
Expand Down
12 changes: 12 additions & 0 deletions tests/getRaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def setUp(self):
self.size = (2160, 4146)
self.dataId = {'visit': 229388, 'ccdnum': 1}
self.filter = "z"
self.exptime = 200.0

def tearDown(self):
del self.butler
Expand All @@ -69,6 +70,14 @@ def testRaw(self):
self.assertEqual(exp.getHeight(), self.size[1])
self.assertEqual(exp.getDetector().getId(), self.dataId["ccdnum"])
self.assertEqual(exp.getFilter().getFilterProperty().getName(), self.filter)
self.assertTrue(exp.hasWcs())

# Metadata which should have been copied from zeroth extension.
self.assertIn("MJD-OBS", exp.getMetadata().paramNames())
self.assertEqual(exp.getCalib().getExptime(), self.exptime)

# Example of metadata which should *not* have been copied from zeroth extension.
self.assertNotIn("PROPOSER", exp.getMetadata().paramNames())

def testRawMetadata(self):
"""Test retrieval of metadata"""
Expand All @@ -84,6 +93,7 @@ def testBias(self):
print("dataId: %s" % self.dataId)
print("detector id: %s" % exp.getDetector().getId())
self.assertEqual(exp.getDetector().getId(), self.dataId["ccdnum"])
self.assertTrue(exp.hasWcs())

def testFlat(self):
"""Test retrieval of flat image"""
Expand All @@ -93,6 +103,7 @@ def testFlat(self):
print("filter: %s" % self.filter)
self.assertEqual(exp.getDetector().getId(), self.dataId["ccdnum"])
self.assertEqual(exp.getFilter().getFilterProperty().getName(), self.filter)
self.assertTrue(exp.hasWcs())

def testFringe(self):
"""Test retrieval of fringe image"""
Expand All @@ -106,6 +117,7 @@ def testFringe(self):
def testDefect(self):
"""Test retrieval of defect list"""
defectList = self.butler.get("defects", self.dataId)
self.assertEqual(len(defectList), 9)
for d in defectList:
self.assertIsInstance(d, afwImage.DefectBase)

Expand Down