Skip to content

Commit

Permalink
Update applyCalib in updateExposure.py
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenam committed Jun 28, 2016
1 parent 6718db7 commit da4547b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion python/lsst/meas/mosaic/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run(self, dataRef):
results = applyMosaicResultsCatalog(dataRef, catalog)
catalog = results.catalog
if self.config.doApplyCalib:
catalog = applyCalib(catalog, results.ffp.calib)
catalog = applyCalib(catalog, results.ffp.calib, hscRun=hscRun)
dataRef.put(catalog, "calibrated_src")

def writeConfig(self, *args, **kwargs):
Expand Down
39 changes: 20 additions & 19 deletions python/lsst/meas/mosaic/updateExposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ def applyMosaicResultsCatalog(dataRef, catalog, addCorrection=True):
return Struct(catalog=catalog, wcs=wcs, ffp=ffp)


def applyCalib(catalog, calib):
def applyCalib(catalog, calib, hscRun=None):
"""Convert all fluxes in a catalog to magnitudes
The fluxes are converted in-place, so that the "flux.*" are now really
The fluxes are converted in-place, so that the "_flux*" are now really
magnitudes.
"""
fluxKeys, errKeys = getFluxKeys(catalog.schema)

mapper = afwTable.SchemaMapper(catalog.schema)
fluxKeys, errKeys = getFluxKeys(catalog.schema, hscRun=hscRun)
mapper = afwTable.SchemaMapper(catalog.schema, True)
for item in catalog.schema:
name = item.field.getName()
if name in fluxKeys:
continue
mapper.addMapping(item.key)
aliasMap = catalog.schema.getAliasMap()

newFluxKeys = {}
newErrKeys = {}
Expand All @@ -181,35 +181,36 @@ def applyCalib(catalog, calib):
(fluxField.getName(), fluxField.getDoc()), "mag",
fluxField.getElementCount())
newFluxKeys[newName] = mapper.addMapping(fluxKeys[name], newField)
if name in errKeys:
errField = catalog.schema.find(name + ".err").field

sigmaName = "Sigma"
if hscRun is not None:
sigmaName = "_err"

if name + sigmaName in errKeys:
errField = catalog.schema.find(name + sigmaName).field
if errField.getElementCount() == 1:
newErrField = errField.__class__(newName + ".err",
newErrField = errField.__class__(newName + sigmaName,
"Calibrated magnitude error from %s (%s)" %
(errField.getName(), errField.getDoc()),
"mag")
(errField.getName(), errField.getDoc()), "mag")
else:
newErrField = errField.__class__(newName + ".err",
newErrField = errField.__class__(newName + sigmaName,
"Calibrated magnitude error from %s (%s)" %
(errField.getName(), errField.getDoc()),
"mag",
(errField.getName(), errField.getDoc()), "mag",
errField.getElementCount())
newErrKeys[newName] = mapper.addMapping(errKeys[name], newErrField)
newErrKeys[newName] = mapper.addMapping(errKeys[name + sigmaName], newErrField)
aliasMap.set(name, newName)
aliasMap.set(name+sigmaName, newName+sigmaName)

calib.setThrowOnNegativeFlux(False)

newCatalog = afwTable.SourceCatalog(mapper.getOutputSchema())
for slot in ("PsfFlux", "ModelFlux", "ApFlux", "InstFlux", "Centroid", "Shape"):
oldColumn = getattr(catalog, "get" + slot + "Definition")()
newColumn = oldColumn.replace("flux", "mag", 1) if oldColumn.startswith("flux.") else oldColumn
getattr(newCatalog, "define" + slot)(newColumn)
newCatalog.extend(catalog, mapper=mapper)

for name, key in newFluxKeys.items():
flux = newCatalog[key]
if name in newErrKeys:
fluxErr = newCatalog[newErrKeys[name]]
magArray = numpy.array([calib.getMagnitude(f, e) for f,e in zip(flux, fluxErr)])
magArray = numpy.array([calib.getMagnitude(f, e) for f, e in zip(flux, fluxErr)])
mag = magArray[:,0]
fluxErr[:] = magArray[:,1]
else:
Expand Down

0 comments on commit da4547b

Please sign in to comment.