LSST Applications g0265f82a02+093ff98f47,g02d81e74bb+10352d6f39,g1f3e9fa97e+40b0fc677d,g2079a07aa2+14824f138e,g2bbee38e9b+093ff98f47,g337abbeb29+093ff98f47,g3ddfee87b4+064c02c7ee,g487adcacf7+7e842ebf4b,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g568d43a26c+1d7ac31cb0,g591dd9f2cf+fb1f69e2ea,g858d7b2824+10352d6f39,g8a8a8dda67+a6fc98d2e7,g8cdfe0ae6a+66d966b544,g99cad8db69+7ce8a7c20a,g9ddcbc5298+d4bad12328,ga1e77700b3+246acaaf9c,ga2e4dd1c03+064c02c7ee,ga8c6da7877+04f6ba86dc,gae46bcf261+093ff98f47,gb0e22166c9+3863383f4c,gba4ed39666+9664299f35,gbb8dafda3b+db40f59a7d,gbeb006f7da+e6a448e96d,gbf5cecdb8a+10352d6f39,gc0f3af6251+10a3fd39cd,gc120e1dc64+5839e50a77,gc28159a63d+093ff98f47,gcf0d15dbbd+064c02c7ee,gd2a12a3803+0c2c227a2b,gdaeeff99f8+a38ce5ea23,ge79ae78c31+093ff98f47,gee10cc3b42+a6fc98d2e7,gf1cff7945b+10352d6f39,w.2024.15
LSST Data Management Base Package
No Matches
Classes | Functions | Variables
lsst.meas.base.forcedPhotCcd Namespace Reference


class  for
class  ForcedPhotCcdConnections
class  may


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


 refSchema : `lsst.afw.table.Schema`, optional
 initInputs : `dict`
 exposure : `lsst.afw.image.exposure.Exposure`
 skyCorr : `lsst.afw.math.backgroundList`, optional
 visitSummary : `lsst.afw.table.ExposureCatalog`, optional
sequence refCats of `lsst.daf.butler.DeferredDatasetHandle`
 refWcs : `lsst.afw.image.SkyWcs`
 refSources : `lsst.afw.table.SourceCatalog`
 dataId : `lsst.daf.butler.DataCoordinate`
 refCat : `lsst.afw.table.SourceCatalog`
 measCat : `lsst.afw.table.SourceCatalog`
 expId : `int`
 exposureId : `int`
 result : `lsst.pipe.base.Struct`

Function Documentation

◆ df2RefCat()

lsst.meas.base.forcedPhotCcd.df2RefCat ( self,
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.

dfList : `list` of `pandas.DataFrame`
    Each element containst diaObjects with ra/dec position in degrees
    Columns 'diaObjectId', 'ra', 'dec' 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

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

Definition at line 585 of file

585 def df2RefCat(self, dfList, exposureBBox, exposureWcs):
586 """Convert list of DataFrames to reference catalog
588 Concatenate list of DataFrames presumably from multiple patches and
589 downselect rows that overlap the exposureBBox using the exposureWcs.
591 Parameters
592 ----------
593 dfList : `list` of `pandas.DataFrame`
594 Each element containst diaObjects with ra/dec position in degrees
595 Columns 'diaObjectId', 'ra', 'dec' are expected
596 exposureBBox : `lsst.geom.Box2I`
597 Bounding box on which to select rows that overlap
598 exposureWcs : `lsst.afw.geom.SkyWcs`
599 World coordinate system to convert sky coords in ref cat to
600 pixel coords with which to compare with exposureBBox
602 Returns
603 -------
604 refCat : `lsst.afw.table.SourceTable`
605 Source Catalog with minimal schema that overlaps exposureBBox
606 """
607 df = pd.concat(dfList)
608 # translate ra/dec coords in dataframe to detector pixel coords
609 # to down select rows that overlap the detector bbox
610 mapping = exposureWcs.getTransform().getMapping()
611 x, y = mapping.applyInverse(np.array(df[['ra', 'dec']].values*2*np.pi/360).T)
612 inBBox = lsst.geom.Box2D(exposureBBox).contains(x, y)
613 refCat = self.df2SourceCat(df[inBBox])
614 return refCat
A floating-point coordinate rectangle geometry.
Definition Box.h:413

◆ df2SourceCat()

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

The forced measurement subtask expects this as input.

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

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

Definition at line 616 of file

616 def df2SourceCat(self, df):
617 """Create minimal schema SourceCatalog from a pandas DataFrame.
619 The forced measurement subtask expects this as input.
621 Parameters
622 ----------
623 df : `pandas.DataFrame`
624 DiaObjects with locations and ids.
626 Returns
627 -------
628 outputCatalog : `lsst.afw.table.SourceTable`
629 Output catalog with minimal schema.
630 """
632 outputCatalog = lsst.afw.table.SourceCatalog(schema)
633 outputCatalog.reserve(len(df))
635 for diaObjectId, ra, dec in df[['ra', 'dec']].itertuples():
636 outputRecord = outputCatalog.addNew()
637 outputRecord.setId(diaObjectId)
638 outputRecord.setCoord(lsst.geom.SpherePoint(ra, dec, lsst.geom.degrees))
639 return outputCatalog
static Schema makeMinimalSchema()
Return a minimal schema for Source tables and records.
Definition Source.h:258
Point in an unspecified spherical coordinate system.
Definition SpherePoint.h:57

◆ runQuantum()

lsst.meas.base.forcedPhotCcd.runQuantum ( self,
outputRefs )

Definition at line 550 of file

550 def runQuantum(self, butlerQC, inputRefs, outputRefs):
551 inputs = butlerQC.get(inputRefs)
553 # When run with dataframes, we do not need a reference wcs.
554 inputs['refWcs'] = None
556 # Connections only exist if they are configured to be used.
557 skyCorr = inputs.pop('skyCorr', None)
559 inputs['exposure'] = self.prepareCalibratedExposure(
560 inputs['exposure'],
561 skyCorr=skyCorr,
562 visitSummary=inputs.pop("visitSummary"),
563 )
565"Filtering ref cats: %s", ','.join([str(i.dataId) for i in inputs['refCat']]))
566 if inputs["exposure"].getWcs() is not None:
567 refCat = self.df2RefCat([i.get(parameters={"columns": ['diaObjectId', 'ra', 'dec']})
568 for i in inputs['refCat']],
569 inputs['exposure'].getBBox(), inputs['exposure'].getWcs())
570 inputs['refCat'] = refCat
571 # generateMeasCat does not use the refWcs.
572 inputs['measCat'], inputs['exposureId'] = self.generateMeasCat(
573 inputRefs.exposure.dataId, inputs['exposure'], inputs['refCat'], inputs['refWcs']
574 )
575 # attachFootprints only uses refWcs in ``transformed`` mode, which is not
576 # supported in the DataFrame-backed task.
577 self.attachFootprints(inputs["measCat"], inputs["refCat"], inputs["exposure"], inputs["refWcs"])
578 outputs =**inputs)
580 butlerQC.put(outputs, outputRefs)
581 else:
582"No WCS for %s. Skipping and no %s catalog will be written.",
583 butlerQC.quantum.dataId,

Variable Documentation

◆ dataId

lsst.meas.base.forcedPhotCcd.dataId : `lsst.daf.butler.DataCoordinate`
mergedRefCat = None

# Step 1: Determine bounds of the exposure photometry will
# be performed on.
expWcs = exposure.getWcs()
if expWcs is None:"Exposure has no WCS.  Returning None for mergedRefCat.")
    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):
    if mergedRefCat is None:
        raise RuntimeError("No reference objects for forced photometry.")
return mergedRefCat

def generateMeasCat(self, dataId, exposure, refCat, refWcs):

Definition at line 360 of file

◆ doApplySkyCorr


Definition at line 263 of file

◆ expId

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

Definition at line 374 of file

◆ exposure

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

def __init__(self, refSchema=None, initInputs=None, **kwargs):

    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)

    inputs['exposure'] = self.prepareCalibratedExposure(

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

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

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

if visitSummary is not None:
    row = visitSummary.find(detectorId)
    if row is None:
        raise RuntimeError(f"Detector id {detectorId} not found in visitSummary.")
    if (photoCalib := row.getPhotoCalib()) is not None:
    if (skyWcs := row.getWcs()) is not None:
    if (psf := row.getPsf()) is not None:
    if (apCorrMap := row.getApCorrMap()) is not None:

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

return exposure

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

Definition at line 260 of file

◆ exposureId

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

Definition at line 396 of file

◆ footprintSource


Definition at line 157 of file

◆ initInputs

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

Definition at line 195 of file

◆ measCat

lsst.meas.base.forcedPhotCcd.measCat : `lsst.afw.table.SourceCatalog`
id_generator = self.config.idGenerator.apply(dataId)
measCat = self.measurement.generateMeasCat(exposure, refCat, refWcs,
return measCat, id_generator.catalog_id

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

Definition at line 372 of file

◆ outputSchema


Definition at line 548 of file

◆ refCat

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

Definition at line 364 of file

◆ refCats

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

Definition at line 302 of file

◆ refSchema

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

Definition at line 191 of file

◆ refSources

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

Definition at line 310 of file

◆ refWcs

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

Definition at line 305 of file

◆ result

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

Definition at line 402 of file

◆ schema


Definition at line 547 of file

◆ skyCorr

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

Definition at line 262 of file

◆ visitSummary

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

Definition at line 264 of file