lsst.meas.base gc76e4e2a6e+28356f993d
Loading...
Searching...
No Matches
Classes | Functions | Variables
lsst.meas.base.forcedPhotCcd Namespace Reference

Classes

class  for
 
class  ForcedPhotCcdConnections
 
class  may
 

Functions

def runQuantum (self, butlerQC, inputRefs, outputRefs)
 
def df2RefCat (self, dfList, exposureBBox, exposureWcs)
 
def df2SourceCat (self, df)
 

Variables

 footprintSource
 
None butler : `None`
 
lsst refSchema : `lsst.afw.table.Schema`, optional
 
dict initInputs : `dict`
 
lsst exposure : `lsst.afw.image.exposure.Exposure`
 
lsst skyCorr : `lsst.afw.math.backgroundList`, optional
 
 doApplySkyCorr
 
lsst externalSkyWcsCatalog : `lsst.afw.table.ExposureCatalog`, optional
 
 doApplyExternalSkyWcs
 
lsst externalPhotoCalibCatalog : `lsst.afw.table.ExposureCatalog`, optional
 
 doApplyExternalPhotoCalib
 
lsst finalizedPsfApCorrCatalog : `lsst.afw.table.ExposureCatalog`, optional
 
 doApplyFinalizedPsf
 
sequence refCats of `lsst.daf.butler.DeferredDatasetHandle`
 
lsst refWcs : `lsst.afw.image.SkyWcs`
 
lsst refSources : `lsst.afw.table.SourceCatalog`
 
DataId exposureDataId : `DataId`
 
lsst refCat : `lsst.afw.table.SourceCatalog`
 
str idPackerName : `str`
 
lsst measCat : `lsst.afw.table.SourceCatalog`
 
int expId : `int`
 
int exposureId : `int`
 
lsst result : `lsst.pipe.base.Struct`
 
 schema
 
 outputSchema
 

Function Documentation

◆ df2RefCat()

def lsst.meas.base.forcedPhotCcd.df2RefCat (   self,
  dfList,
  exposureBBox,
  exposureWcs 
)
Convert list of DataFrames to reference catalog

Concatenate list of DataFrames presumably from multiple patches and
downselect rows that overlap the exposureBBox using the exposureWcs.

Parameters
----------
dfList : `list` of `pandas.DataFrame`
    Each element containst diaObjects with ra/decl position in degrees
    Columns 'diaObjectId', 'ra', 'decl' are expected
exposureBBox :   `lsst.geom.Box2I`
    Bounding box on which to select rows that overlap
exposureWcs : `lsst.afw.geom.SkyWcs`
    World coordinate system to convert sky coords in ref cat to
    pixel coords with which to compare with exposureBBox

Returns
-------
refCat : `lsst.afw.table.SourceTable`
    Source Catalog with minimal schema that overlaps exposureBBox

Definition at line 770 of file forcedPhotCcd.py.

◆ df2SourceCat()

def lsst.meas.base.forcedPhotCcd.df2SourceCat (   self,
  df 
)
Create minimal schema SourceCatalog from a pandas DataFrame.

The forced measurement subtask expects this as input.

Parameters
----------
df : `pandas.DataFrame`
    DiaObjects with locations and ids.

Returns
-------
outputCatalog : `lsst.afw.table.SourceTable`
    Output catalog with minimal schema.

Definition at line 801 of file forcedPhotCcd.py.

◆ runQuantum()

def lsst.meas.base.forcedPhotCcd.runQuantum (   self,
  butlerQC,
  inputRefs,
  outputRefs 
)

Definition at line 724 of file forcedPhotCcd.py.

Variable Documentation

◆ butler

None lsst.meas.base.forcedPhotCcd.butler : `None`

Definition at line 266 of file forcedPhotCcd.py.

◆ doApplyExternalPhotoCalib

lsst.meas.base.forcedPhotCcd.doApplyExternalPhotoCalib

Definition at line 365 of file forcedPhotCcd.py.

◆ doApplyExternalSkyWcs

lsst.meas.base.forcedPhotCcd.doApplyExternalSkyWcs

Definition at line 361 of file forcedPhotCcd.py.

◆ doApplyFinalizedPsf

lsst.meas.base.forcedPhotCcd.doApplyFinalizedPsf

Definition at line 369 of file forcedPhotCcd.py.

◆ doApplySkyCorr

lsst.meas.base.forcedPhotCcd.doApplySkyCorr

Definition at line 358 of file forcedPhotCcd.py.

◆ expId

int lsst.meas.base.forcedPhotCcd.expId : `int`

Definition at line 507 of file forcedPhotCcd.py.

◆ exposure

lsst lsst.meas.base.forcedPhotCcd.exposure : `lsst.afw.image.exposure.Exposure`
ConfigClass = ForcedPhotCcdConfig
_DefaultName = "forcedPhotCcd"
dataPrefix = ""

def __init__(self, butler=None, refSchema=None, initInputs=None, **kwds):
    super().__init__(**kwds)

    if butler is not None:
        warnings.warn("The 'butler' parameter is no longer used and can be safely removed.",
                      category=FutureWarning, stacklevel=2)
        butler = None

    if initInputs is not None:
        refSchema = initInputs['inputSchema'].schema

    if refSchema is None:
        raise ValueError("No reference schema provided.")

    self.makeSubtask("measurement", refSchema=refSchema)
    # It is necessary to get the schema internal to the forced measurement
    # task until such a time that the schema is not owned by the
    # measurement task, but is passed in by an external caller.
    if self.config.doApCorr:
        self.makeSubtask("applyApCorr", schema=self.measurement.schema)
    self.makeSubtask('catalogCalculation', schema=self.measurement.schema)
    self.outputSchema = lsst.afw.table.SourceCatalog(self.measurement.schema)

def runQuantum(self, butlerQC, inputRefs, outputRefs):
    inputs = butlerQC.get(inputRefs)

    tract = butlerQC.quantum.dataId['tract']
    skyMap = inputs.pop('skyMap')
    inputs['refWcs'] = skyMap[tract].getWcs()

    # Connections only exist if they are configured to be used.
    skyCorr = inputs.pop('skyCorr', None)
    if self.config.useGlobalExternalSkyWcs:
        externalSkyWcsCatalog = inputs.pop('externalSkyWcsGlobalCatalog', None)
    else:
        externalSkyWcsCatalog = inputs.pop('externalSkyWcsTractCatalog', None)
    if self.config.useGlobalExternalPhotoCalib:
        externalPhotoCalibCatalog = inputs.pop('externalPhotoCalibGlobalCatalog', None)
    else:
        externalPhotoCalibCatalog = inputs.pop('externalPhotoCalibTractCatalog', None)
    finalizedPsfApCorrCatalog = inputs.pop('finalizedPsfApCorrCatalog', None)

    inputs['exposure'] = self.prepareCalibratedExposure(
        inputs['exposure'],
        skyCorr=skyCorr,
        externalSkyWcsCatalog=externalSkyWcsCatalog,
        externalPhotoCalibCatalog=externalPhotoCalibCatalog,
        finalizedPsfApCorrCatalog=finalizedPsfApCorrCatalog
    )

    inputs['refCat'] = self.mergeAndFilterReferences(inputs['exposure'], inputs['refCat'],
                                                     inputs['refWcs'])

    if inputs['refCat'] is None:
        self.log.info("No WCS for exposure %s.  No %s catalog will be written.",
                      butlerQC.quantum.dataId, outputRefs.measCat.datasetType.name)
    else:
        inputs['measCat'], inputs['exposureId'] = self.generateMeasCat(inputRefs.exposure.dataId,
                                                                       inputs['exposure'],
                                                                       inputs['refCat'], inputs['refWcs'],
                                                                       "visit_detector")
        self.attachFootprints(inputs['measCat'], inputs['refCat'], inputs['exposure'], inputs['refWcs'])
        outputs = self.run(**inputs)
        butlerQC.put(outputs, outputRefs)

def prepareCalibratedExposure(self, exposure, skyCorr=None, externalSkyWcsCatalog=None,
                              externalPhotoCalibCatalog=None, finalizedPsfApCorrCatalog=None):
detectorId = exposure.getInfo().getDetector().getId()

if externalPhotoCalibCatalog is not None:
    row = externalPhotoCalibCatalog.find(detectorId)
    if row is None:
        self.log.warning("Detector id %s not found in externalPhotoCalibCatalog; "
                         "Using original photoCalib.", detectorId)
    else:
        photoCalib = row.getPhotoCalib()
        if photoCalib is None:
            self.log.warning("Detector id %s has None for photoCalib in externalPhotoCalibCatalog; "
                             "Using original photoCalib.", detectorId)
        else:
            exposure.setPhotoCalib(photoCalib)

if externalSkyWcsCatalog is not None:
    row = externalSkyWcsCatalog.find(detectorId)
    if row is None:
        self.log.warning("Detector id %s not found in externalSkyWcsCatalog; "
                         "Using original skyWcs.", detectorId)
    else:
        skyWcs = row.getWcs()
        if skyWcs is None:
            self.log.warning("Detector id %s has None for skyWcs in externalSkyWcsCatalog; "
                             "Using original skyWcs.", detectorId)
        else:
            exposure.setWcs(skyWcs)

if finalizedPsfApCorrCatalog is not None:
    row = finalizedPsfApCorrCatalog.find(detectorId)
    if row is None:
        self.log.warning("Detector id %s not found in finalizedPsfApCorrCatalog; "
                         "Using original psf.", detectorId)
    else:
        psf = row.getPsf()
        apCorrMap = row.getApCorrMap()
        if psf is None or apCorrMap is None:
            self.log.warning("Detector id %s has None for psf/apCorrMap in "
                             "finalizedPsfApCorrCatalog; Using original psf.", detectorId)
        else:
            exposure.setPsf(psf)
            exposure.setApCorrMap(apCorrMap)

if skyCorr is not None:
    exposure.maskedImage -= skyCorr.getImage()

return exposure

def mergeAndFilterReferences(self, exposure, refCats, refWcs):

Definition at line 355 of file forcedPhotCcd.py.

◆ exposureDataId

DataId lsst.meas.base.forcedPhotCcd.exposureDataId : `DataId`
mergedRefCat = None

# Step 1: Determine bounds of the exposure photometry will
# be performed on.
expWcs = exposure.getWcs()
if expWcs is None:
    self.log.info("Exposure has no WCS.  Returning None for mergedRefCat.")
else:
    expRegion = exposure.getBBox(lsst.afw.image.PARENT)
    expBBox = lsst.geom.Box2D(expRegion)
    expBoxCorners = expBBox.getCorners()
    expSkyCorners = [expWcs.pixelToSky(corner).getVector() for
                     corner in expBoxCorners]
    expPolygon = lsst.sphgeom.ConvexPolygon(expSkyCorners)

    # Step 2: Filter out reference catalog sources that are
    # not contained within the exposure boundaries, or whose
    # parents are not within the exposure boundaries.  Note
    # that within a single input refCat, the parents always
    # appear before the children.
    for refCat in refCats:
        refCat = refCat.get()
        if mergedRefCat is None:
            mergedRefCat = lsst.afw.table.SourceCatalog(refCat.table)
            containedIds = {0}  # zero as a parent ID means "this is a parent"
        for record in refCat:
            if (expPolygon.contains(record.getCoord().getVector()) and record.getParent()
                    in containedIds):
                record.setFootprint(record.getFootprint())
                mergedRefCat.append(record)
                containedIds.add(record.getId())
    if mergedRefCat is None:
        raise RuntimeError("No reference objects for forced photometry.")
    mergedRefCat.sort(lsst.afw.table.SourceTable.getParentKey())
return mergedRefCat

def generateMeasCat(self, exposureDataId, exposure, refCat, refWcs, idPackerName):

Definition at line 491 of file forcedPhotCcd.py.

◆ exposureId

int lsst.meas.base.forcedPhotCcd.exposureId : `int`

Definition at line 531 of file forcedPhotCcd.py.

◆ externalPhotoCalibCatalog

lsst lsst.meas.base.forcedPhotCcd.externalPhotoCalibCatalog : `lsst.afw.table.ExposureCatalog`, optional

Definition at line 363 of file forcedPhotCcd.py.

◆ externalSkyWcsCatalog

lsst lsst.meas.base.forcedPhotCcd.externalSkyWcsCatalog : `lsst.afw.table.ExposureCatalog`, optional

Definition at line 359 of file forcedPhotCcd.py.

◆ finalizedPsfApCorrCatalog

lsst lsst.meas.base.forcedPhotCcd.finalizedPsfApCorrCatalog : `lsst.afw.table.ExposureCatalog`, optional

Definition at line 367 of file forcedPhotCcd.py.

◆ footprintSource

lsst.meas.base.forcedPhotCcd.footprintSource

Definition at line 248 of file forcedPhotCcd.py.

◆ idPackerName

str lsst.meas.base.forcedPhotCcd.idPackerName : `str`

Definition at line 500 of file forcedPhotCcd.py.

◆ initInputs

dict lsst.meas.base.forcedPhotCcd.initInputs : `dict`

Definition at line 272 of file forcedPhotCcd.py.

◆ measCat

lsst lsst.meas.base.forcedPhotCcd.measCat : `lsst.afw.table.SourceCatalog`
exposureIdInfo = ExposureIdInfo.fromDataId(exposureDataId, idPackerName)
idFactory = exposureIdInfo.makeSourceIdFactory()

measCat = self.measurement.generateMeasCat(exposure, refCat, refWcs,
                                           idFactory=idFactory)
return measCat, exposureIdInfo.expId

def run(self, measCat, exposure, refCat, refWcs, exposureId=None):

Definition at line 505 of file forcedPhotCcd.py.

◆ outputSchema

lsst.meas.base.forcedPhotCcd.outputSchema

Definition at line 722 of file forcedPhotCcd.py.

◆ refCat

lsst lsst.meas.base.forcedPhotCcd.refCat : `lsst.afw.table.SourceCatalog`

Definition at line 495 of file forcedPhotCcd.py.

◆ refCats

sequence lsst.meas.base.forcedPhotCcd.refCats of `lsst.daf.butler.DeferredDatasetHandle`

Definition at line 433 of file forcedPhotCcd.py.

◆ refSchema

lsst.meas.base.forcedPhotCcd.refSchema : `lsst.afw.table.Schema`, optional

Definition at line 268 of file forcedPhotCcd.py.

◆ refSources

lsst lsst.meas.base.forcedPhotCcd.refSources : `lsst.afw.table.SourceCatalog`

Definition at line 441 of file forcedPhotCcd.py.

◆ refWcs

lsst lsst.meas.base.forcedPhotCcd.refWcs : `lsst.afw.image.SkyWcs`

Definition at line 436 of file forcedPhotCcd.py.

◆ result

lsst lsst.meas.base.forcedPhotCcd.result : `lsst.pipe.base.Struct`

Definition at line 537 of file forcedPhotCcd.py.

◆ schema

lsst.meas.base.forcedPhotCcd.schema

Definition at line 720 of file forcedPhotCcd.py.

◆ skyCorr

lsst lsst.meas.base.forcedPhotCcd.skyCorr : `lsst.afw.math.backgroundList`, optional

Definition at line 357 of file forcedPhotCcd.py.