LSST Applications g1cfbe01172+01aa18f939,g20cdd03214+31e6b93548,g28da252d5a+ea8665a95b,g2bbee38e9b+9ec6cc348d,g2bc492864f+9ec6cc348d,g347aa1857d+9ec6cc348d,g3a166c0a6a+9ec6cc348d,g4322eb9e3a+65eff1e020,g461a3dce89+b86e4b8053,g50ff169b8f+f991eae79d,g52b1c1532d+b86e4b8053,g607f77f49a+31e6b93548,g78056777b3+8ae2798781,g858d7b2824+31e6b93548,g8cd86fa7b1+4851e61ca4,g9ddcbc5298+f24b38b85a,ga1e77700b3+3309dba821,gae0086650b+b86e4b8053,gb0e22166c9+6076c0b52b,gbb886bcc26+dccb771098,gbd462c55f0+dc07f8e65d,gc0c51c7ec2+31e6b93548,gc120e1dc64+a417ce3171,gc28159a63d+9ec6cc348d,gc2a6998b7e+f95f64aeae,gcdd4ae20e8+507450c4cd,gcf0d15dbbd+507450c4cd,gd1535ee943+bcf88ba65f,gd598c5cd71+66126f91fb,gdaeeff99f8+006e14e809,gdbce86181e+39d5515b1a,ge3d4d395c2+b12d4d6a95,ge79ae78c31+9ec6cc348d,gf048a9a2f4+d9c36e6b63,gfbcc870c63+ea41c4420b,w.2024.27
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions | Variables
lsst.meas.base.forcedPhotCcd Namespace Reference

Classes

class  for
 
class  ForcedPhotCcdConnections
 
class  may
 

Functions

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

Variables

 footprintSource
 
 refSchema : `lsst.afw.table.Schema`, optional
 
 initInputs : `dict`
 
 exposure : `lsst.afw.image.exposure.Exposure`
 
 skyCorr : `lsst.afw.math.backgroundList`, optional
 
 doApplySkyCorr
 
 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`
 
 schema
 
 outputSchema
 

Function Documentation

◆ df2RefCat()

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/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

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

Definition at line 592 of file forcedPhotCcd.py.

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

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

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

Definition at line 623 of file forcedPhotCcd.py.

623 def df2SourceCat(self, df):
624 """Create minimal schema SourceCatalog from a pandas DataFrame.
625
626 The forced measurement subtask expects this as input.
627
628 Parameters
629 ----------
630 df : `pandas.DataFrame`
631 DiaObjects with locations and ids.
632
633 Returns
634 -------
635 outputCatalog : `lsst.afw.table.SourceTable`
636 Output catalog with minimal schema.
637 """
639 outputCatalog = lsst.afw.table.SourceCatalog(schema)
640 outputCatalog.reserve(len(df))
641
642 for diaObjectId, ra, dec in df[['ra', 'dec']].itertuples():
643 outputRecord = outputCatalog.addNew()
644 outputRecord.setId(diaObjectId)
645 outputRecord.setCoord(lsst.geom.SpherePoint(ra, dec, lsst.geom.degrees))
646 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,
butlerQC,
inputRefs,
outputRefs )

Definition at line 556 of file forcedPhotCcd.py.

556 def runQuantum(self, butlerQC, inputRefs, outputRefs):
557 inputs = butlerQC.get(inputRefs)
558
559 tract = butlerQC.quantum.dataId["tract"]
560 skyMap = inputs.pop("skyMap")
561 inputs["refWcs"] = skyMap[tract].getWcs()
562
563 # Connections only exist if they are configured to be used.
564 skyCorr = inputs.pop('skyCorr', None)
565
566 inputs['exposure'] = self.prepareCalibratedExposure(
567 inputs['exposure'],
568 skyCorr=skyCorr,
569 visitSummary=inputs.pop("visitSummary"),
570 )
571
572 self.log.info("Filtering ref cats: %s", ','.join([str(i.dataId) for i in inputs['refCat']]))
573 if inputs["exposure"].getWcs() is not None:
574 refCat = self.df2RefCat([i.get(parameters={"columns": ['diaObjectId', 'ra', 'dec']})
575 for i in inputs['refCat']],
576 inputs['exposure'].getBBox(), inputs['exposure'].getWcs())
577 inputs['refCat'] = refCat
578 # generateMeasCat does not use the refWcs.
579 inputs['measCat'], inputs['exposureId'] = self.generateMeasCat(
580 inputRefs.exposure.dataId, inputs['exposure'], inputs['refCat'], inputs['refWcs']
581 )
582 # attachFootprints only uses refWcs in ``transformed`` mode, which is not
583 # supported in the DataFrame-backed task.
584 self.attachFootprints(inputs["measCat"], inputs["refCat"], inputs["exposure"], inputs["refWcs"])
585 outputs = self.run(**inputs)
586
587 butlerQC.put(outputs, outputRefs)
588 else:
589 self.log.info("No WCS for %s. Skipping and no %s catalog will be written.",
590 butlerQC.quantum.dataId, outputRefs.measCat.datasetType.name)
591

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:
    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, dataId, exposure, refCat, refWcs):

Definition at line 360 of file forcedPhotCcd.py.

◆ doApplySkyCorr

lsst.meas.base.forcedPhotCcd.doApplySkyCorr

Definition at line 263 of file forcedPhotCcd.py.

◆ expId

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

Definition at line 374 of file forcedPhotCcd.py.

◆ exposure

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

def __init__(self, refSchema=None, initInputs=None, **kwargs):
    super().__init__(**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['exposure'],
        skyCorr=skyCorr,
        visitSummary=inputs.pop("visitSummary"),
    )

    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'])
        self.attachFootprints(inputs['measCat'], inputs['refCat'], inputs['exposure'], inputs['refWcs'])
        outputs = self.run(**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:
        exposure.setPhotoCalib(photoCalib)
    if (skyWcs := row.getWcs()) is not None:
        exposure.setWcs(skyWcs)
    if (psf := row.getPsf()) is not None:
        exposure.setPsf(psf)
    if (apCorrMap := row.getApCorrMap()) is not None:
        exposure.info.setApCorrMap(apCorrMap)

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

return exposure

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

Definition at line 260 of file forcedPhotCcd.py.

◆ exposureId

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

Definition at line 396 of file forcedPhotCcd.py.

◆ footprintSource

lsst.meas.base.forcedPhotCcd.footprintSource

Definition at line 157 of file forcedPhotCcd.py.

◆ initInputs

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

Definition at line 195 of file forcedPhotCcd.py.

◆ measCat

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

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

Definition at line 372 of file forcedPhotCcd.py.

◆ outputSchema

lsst.meas.base.forcedPhotCcd.outputSchema

Definition at line 554 of file forcedPhotCcd.py.

◆ refCat

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

Definition at line 364 of file forcedPhotCcd.py.

◆ refCats

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

Definition at line 302 of file forcedPhotCcd.py.

◆ refSchema

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

Definition at line 191 of file forcedPhotCcd.py.

◆ refSources

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

Definition at line 310 of file forcedPhotCcd.py.

◆ refWcs

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

Definition at line 305 of file forcedPhotCcd.py.

◆ result

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

Definition at line 402 of file forcedPhotCcd.py.

◆ schema

lsst.meas.base.forcedPhotCcd.schema

Definition at line 553 of file forcedPhotCcd.py.

◆ skyCorr

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

Definition at line 262 of file forcedPhotCcd.py.

◆ visitSummary

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

Definition at line 264 of file forcedPhotCcd.py.