Coverage for python/lsst/meas/base/applyApCorr.py : 79%

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 2015 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/>. #
# If True then scale flux sigma by apCorr; if False then use a more complex computation # that over-estimates flux error (often grossly so) because it double-counts photon noise. # This flag is intended to be temporary until we figure out a better way to compute # the effects of aperture correction on flux uncertainty
"""!Catalog field names and keys needed to aperture correct a particular flux """
"""!Construct an ApCorrInfo and add fields to the schema
The aperture correction can be derived from the meaasurements in the column being aperture-corrected or from measurements in a different column (a "proxy"). In the first case, we will add columns to contain the aperture correction values; in the second case (using a proxy), we will add an alias to the proxy's aperture correction values. In all cases, we add a flag.
@param[in,out] schema source catalog schema; three fields are used to generate keys: - {name}_flux - {name}_fluxSigma - {name}_flag three fields are added: - {name}_apCorr (only if not already added by proxy) - {name}_apCorrSigma (only if not already added by proxy) - {name}_flag_apCorr @param[in] model field name prefix for flux with aperture correction model, e.g. "base_PsfFlux" @param[in] name field name prefix for flux needing aperture correction; may be None if it's the same as for the 'model' parameter
ApCorrInfo has the following attributes: - name: field name prefix for flux needing aperture correction - modelName: field name for aperture correction model for flux - modelSigmaName: field name for aperture correction model for fluxSigma - doApCorrColumn: should we write the aperture correction values? (not if they're already being written by a proxy) - fluxName: name of flux field - fluxSigmaName: name of flux sigma field - fluxKey: key to flux field - fluxSigmaKey: key to flux sigma field - fluxFlagKey: key to flux flag field - apCorrKey: key to new aperture correction field - apCorrSigmaKey: key to new aperture correction sigma field - apCorrFlagKey: key to new aperture correction flag field """
# No need to write the same aperture corrections multiple times name + "_apCorr", doc="aperture correction applied to %s" % (name,), type=np.float64, ) name + "_apCorrSigma", doc="aperture correction applied to %s" % (name,), type=np.float64, ) else:
name + "_flag_apCorr", doc="set if unable to aperture correct %s" % (name,), type="Flag", )
doc="flux measurement algorithms in getApCorrNameSet() to ignore; " "if a name is listed that does not appear in getApCorrNameSet() then a warning is logged", dtype=str, optional=False, default=(), ) doc="set the general failure flag for a flux when it cannot be aperture-corrected?", dtype=bool, default=True, ) doc="flux measurement algorithms to be aperture-corrected by reference to another algorithm; " "this is a mapping alg1:alg2, where 'alg1' is the algorithm being corrected, and 'alg2' " "is the algorithm supplying the corrections", keytype=str, itemtype=str, default={}, )
"""!Apply aperture corrections """
"""Construct an instance of this task """
self.log.warn("Fields in ignoreList that are not in fluxCorrectList: %s", sorted(list(missingNameSet))) # if a field in the registry is missing from the schema, silently ignore it.
# Already done or ignored continue # Silently ignore continue
"""Apply aperture corrections to a catalog of sources
@param[in,out] catalog catalog of sources @param[in] apCorrMap aperture correction map (an lsst.afw.image.ApCorrMap)
If you show debug-level log messages then you will see statistics for the effects of aperture correction. """ else: self.log.debug("Use complex flux sigma computation that double-counts photon noise " "and thus over-estimates flux uncertainty") missingNames = [(apCorrInfo.modelName, apCorrInfo.modelSigmaName)[i] for i, model in enumerate((apCorrModel, apCorrSigmaModel)) if model is None] self.log.warn("Cannot aperture correct %s because could not find %s in apCorrMap" % (apCorrInfo.name, " or ".join(missingNames),)) for source in catalog: source.set(apCorrInfo.apCorrFlagKey, True) continue
# say we've failed when we start; we'll unset these flags when we succeed
apCorrSigma = apCorrSigmaModel.evaluate(center) except lsst.pex.exceptions.DomainError: continue
continue
else: a = fluxSigma/flux b = apCorrSigma/apCorr source.set(apCorrInfo.fluxSigmaKey, abs(flux*apCorr)*math.sqrt(a*a + b*b))
# log statistics on the effects of aperture correction "mean apCorrSigma=%s, stdDev apCorrSigma=%s for %s sources", apCorrInfo.name, apCorrArr.mean(), apCorrArr.std(), apCorrSigmaArr.mean(), apCorrSigmaArr.std(), len(catalog)) |