LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Variables
lsst.pipe.tasks.processCcdWithFakes Namespace Reference

Classes

class  docstring
 
class  ProcessCcdWithFakesConnections
 

Variables

 exposure : `lsst.afw.image.exposure.exposure.ExposureF`
 
 skyMap : `lsst.skymap.SkyMap`
 
 wcs : `lsst.afw.geom.SkyWcs`, optional
 
 photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`, optional
 
 icSourceCat : `lsst.afw.table.SourceCatalog`, optional
 
 sfdSourceCat : `lsst.afw.table.SourceCatalog`, optional
 
 externalSkyWcsGlobalCatalog
 
 externalSkyWcsTractCatalog : `lsst.afw.table.ExposureCatalog`, optional
 
 externalPhotoCalibGlobalCatalog
 
 externalPhotoCalibTractCatalog
 
 idGenerator : `lsst.meas.base.IdGenerator`, optional
 
 resultStruct : `lsst.pipe.base.struct.Struct`
 
 radius
 
 fakeCats : `list` of `lsst.daf.butler.DeferredDatasetHandle`
 
 combinedFakeCat : `pandas.DataFrame`
 
 fakeCat : `pandas.core.frame.DataFrame`
 
 movingFakeCat : `pandas.DataFrame`
 
 calibCat : `lsst.afw.table.SourceCatalog`
 
 sourceCat : `lsst.afw.table.SourceCatalog`
 
 fieldsToCopy : `lsst.pex.config.listField.List`
 
 newCat : `lsst.afw.table.SourceCatalog`
 
 band : `str`
 
 rngSeed : `int`
 
 dataFrame : `pandas.DataFrame`
 

Detailed Description

Insert fake sources into calexps

Variable Documentation

◆ band

lsst.pipe.tasks.processCcdWithFakes.band : `str`

Definition at line 777 of file processCcdWithFakes.py.

◆ calibCat

lsst.pipe.tasks.processCcdWithFakes.calibCat : `lsst.afw.table.SourceCatalog`
selected = exposure.getInfo().getVisitInfo().getId() == fakeCat["visit"]

return fakeCat[selected]

def copyCalibrationFields(self, calibCat, sourceCat, fieldsToCopy):

Definition at line 550 of file processCcdWithFakes.py.

◆ combinedFakeCat

lsst.pipe.tasks.processCcdWithFakes.combinedFakeCat : `pandas.DataFrame`

Definition at line 507 of file processCcdWithFakes.py.

◆ dataFrame

lsst.pipe.tasks.processCcdWithFakes.dataFrame : `pandas.DataFrame`

Definition at line 788 of file processCcdWithFakes.py.

◆ exposure

lsst.pipe.tasks.processCcdWithFakes.exposure : `lsst.afw.image.exposure.exposure.ExposureF`

Definition at line 418 of file processCcdWithFakes.py.

◆ externalPhotoCalibGlobalCatalog

lsst.pipe.tasks.processCcdWithFakes.externalPhotoCalibGlobalCatalog
Initial value:
2 optional
Custom catalog class for ExposureRecord/Table.
Definition Exposure.h:310

Definition at line 437 of file processCcdWithFakes.py.

◆ externalPhotoCalibTractCatalog

lsst.pipe.tasks.processCcdWithFakes.externalPhotoCalibTractCatalog
Initial value:
2 optional

Definition at line 440 of file processCcdWithFakes.py.

◆ externalSkyWcsGlobalCatalog

lsst.pipe.tasks.processCcdWithFakes.externalSkyWcsGlobalCatalog
Initial value:
2 optional

Definition at line 432 of file processCcdWithFakes.py.

◆ externalSkyWcsTractCatalog

lsst.pipe.tasks.processCcdWithFakes.externalSkyWcsTractCatalog : `lsst.afw.table.ExposureCatalog`, optional

Definition at line 435 of file processCcdWithFakes.py.

◆ fakeCat

lsst.pipe.tasks.processCcdWithFakes.fakeCat : `pandas.core.frame.DataFrame`
if len(fakeCats) == 1:
    return fakeCats[0].get()
outputCat = []
for fakeCatRef in fakeCats:
    cat = fakeCatRef.get()
    tractId = fakeCatRef.dataId["tract"]
    # Make sure all data is within the inner part of the tract.
    outputCat.append(cat[
        skyMap.findTractIdArray(cat[self.config.insertFakes.ra_col],
                                cat[self.config.insertFakes.dec_col],
                                degrees=False)
        == tractId])

return pd.concat(outputCat)

def getVisitMatchedFakeCat(self, fakeCat, exposure):
# Make a new SourceCatalog with the data from sourceCat so that we can add the new columns to it
sourceSchemaMapper = afwTable.SchemaMapper(sourceCat.schema)
sourceSchemaMapper.addMinimalSchema(sourceCat.schema, True)

calibSchemaMapper = afwTable.SchemaMapper(calibCat.schema, sourceCat.schema)

# Add the desired columns from the option fieldsToCopy
missingFieldNames = []
for fieldName in fieldsToCopy:
    if fieldName in calibCat.schema:
        schemaItem = calibCat.schema.find(fieldName)
        calibSchemaMapper.editOutputSchema().addField(schemaItem.getField())
        schema = calibSchemaMapper.editOutputSchema()
        calibSchemaMapper.addMapping(schemaItem.getKey(), schema.find(fieldName).getField())
    else:
        missingFieldNames.append(fieldName)
if missingFieldNames:
    raise RuntimeError(f"calibCat is missing fields {missingFieldNames} specified in "
                       "fieldsToCopy")

if "calib_detected" not in calibSchemaMapper.getOutputSchema():
    self.calibSourceKey = calibSchemaMapper.addOutputField(afwTable.Field["Flag"]("calib_detected",
                                                           "Source was detected as an icSource"))
else:
    self.calibSourceKey = None

schema = calibSchemaMapper.getOutputSchema()
newCat = afwTable.SourceCatalog(schema)
newCat.reserve(len(sourceCat))
newCat.extend(sourceCat, sourceSchemaMapper)

# Set the aliases so it doesn't complain.
for k, v in sourceCat.schema.getAliasMap().items():
    newCat.schema.getAliasMap().set(k, v)

select = newCat["deblend_nChild"] == 0
matches = afwTable.matchXy(newCat[select], calibCat, self.config.matchRadiusPix)
# Check that no sourceCat sources are listed twice (we already know
# that each match has a unique calibCat source ID, due to using
# that ID as the key in bestMatches)
numMatches = len(matches)
numUniqueSources = len(set(m[1].getId() for m in matches))
if numUniqueSources != numMatches:
    self.log.warning("%d calibCat sources matched only %d sourceCat sources", numMatches,
                     numUniqueSources)

self.log.info("Copying flags from calibCat to sourceCat for %s sources", numMatches)

# For each match: set the calibSourceKey flag and copy the desired
# fields
for src, calibSrc, d in matches:
    if self.calibSourceKey:
        src.setFlag(self.calibSourceKey, True)
    # src.assign copies the footprint from calibSrc, which we don't want
    # (DM-407)
    # so set calibSrc's footprint to src's footprint before src.assign,
    # then restore it
    calibSrcFootprint = calibSrc.getFootprint()
    try:
        calibSrc.setFootprint(src.getFootprint())
        src.assign(calibSrc, calibSchemaMapper)
    finally:
        calibSrc.setFootprint(calibSrcFootprint)

return newCat


class ProcessCcdWithVariableFakesConnections(ProcessCcdWithFakesConnections):
ccdVisitFakeMagnitudes = cT.Output(
doc="Catalog of fakes with magnitudes scattered for this ccdVisit.",
name="{fakesType}ccdVisitFakeMagnitudes",
storageClass="DataFrame",
dimensions=("instrument", "visit", "detector"),
)


@deprecated(
reason="This task will be removed in v28.0 as it is replaced by `source_injection` tasks.",
version="v28.0",
category=FutureWarning,
)
class ProcessCcdWithVariableFakesConfig(ProcessCcdWithFakesConfig,
                                pipelineConnections=ProcessCcdWithVariableFakesConnections):
scatterSize = pexConfig.RangeField(
dtype=float,
default=0.4,
min=0,
max=100,
doc="Amount of scatter to add to the visit magnitude for variable "
    "sources."
)


@deprecated(
reason="This task will be removed in v28.0 as it is replaced by `source_injection` tasks.",
version="v28.0",
category=FutureWarning,
)
class ProcessCcdWithVariableFakesTask(ProcessCcdWithFakesTask):
_DefaultName = "processCcdWithVariableFakes"
ConfigClass = ProcessCcdWithVariableFakesConfig

def run(self, fakeCats, exposure, skyMap, wcs=None, photoCalib=None,
        icSourceCat=None, sfdSourceCat=None, idGenerator=None):
fakeCat = self.composeFakeCat(fakeCats, skyMap)

if wcs is None:
    wcs = exposure.getWcs()

if photoCalib is None:
    photoCalib = exposure.getPhotoCalib()

if idGenerator is None:
    idGenerator = IdGenerator()

band = exposure.getFilter().bandLabel
ccdVisitMagnitudes = self.addVariability(
    fakeCat,
    band,
    exposure,
    photoCalib,
    idGenerator.catalog_id,
)

self.insertFakes.run(fakeCat, exposure, wcs, photoCalib)

# detect, deblend and measure sources
returnedStruct = self.calibrate.run(exposure, idGenerator=idGenerator)
sourceCat = returnedStruct.sourceCat

sourceCat = self.copyCalibrationFields(sfdSourceCat, sourceCat, self.config.srcFieldsToCopy)

resultStruct = pipeBase.Struct(outputExposure=exposure,
                               outputCat=sourceCat,
                               ccdVisitFakeMagnitudes=ccdVisitMagnitudes)
return resultStruct

def addVariability(self, fakeCat, band, exposure, photoCalib, rngSeed):

Definition at line 531 of file processCcdWithFakes.py.

◆ fakeCats

lsst.pipe.tasks.processCcdWithFakes.fakeCats : `list` of `lsst.daf.butler.DeferredDatasetHandle`
fakeCat = self.composeFakeCat(fakeCats, skyMap)

if wcs is None:
    wcs = exposure.getWcs()

if photoCalib is None:
    photoCalib = exposure.getPhotoCalib()

if self.config.doMatchVisit:
    fakeCat = self.getVisitMatchedFakeCat(fakeCat, exposure)

self.insertFakes.run(fakeCat, exposure, wcs, photoCalib)

# detect, deblend and measure sources
if idGenerator is None:
    idGenerator = IdGenerator()
returnedStruct = self.calibrate.run(exposure, idGenerator=idGenerator)
sourceCat = returnedStruct.sourceCat

sourceCat = self.copyCalibrationFields(sfdSourceCat, sourceCat, self.config.srcFieldsToCopy)

resultStruct = pipeBase.Struct(outputExposure=exposure, outputCat=sourceCat)
return resultStruct

def composeFakeCat(self, fakeCats, skyMap):

Definition at line 500 of file processCcdWithFakes.py.

◆ fieldsToCopy

lsst.pipe.tasks.processCcdWithFakes.fieldsToCopy : `lsst.pex.config.listField.List`

Definition at line 554 of file processCcdWithFakes.py.

◆ icSourceCat

lsst.pipe.tasks.processCcdWithFakes.icSourceCat : `lsst.afw.table.SourceCatalog`, optional

Definition at line 426 of file processCcdWithFakes.py.

◆ idGenerator

lsst.pipe.tasks.processCcdWithFakes.idGenerator : `lsst.meas.base.IdGenerator`, optional

Definition at line 443 of file processCcdWithFakes.py.

◆ movingFakeCat

lsst.pipe.tasks.processCcdWithFakes.movingFakeCat : `pandas.DataFrame`

Definition at line 538 of file processCcdWithFakes.py.

◆ newCat

lsst.pipe.tasks.processCcdWithFakes.newCat : `lsst.afw.table.SourceCatalog`

Definition at line 559 of file processCcdWithFakes.py.

◆ photoCalib

lsst.pipe.tasks.processCcdWithFakes.photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`, optional

Definition at line 424 of file processCcdWithFakes.py.

◆ radius

lsst.pipe.tasks.processCcdWithFakes.radius

Definition at line 457 of file processCcdWithFakes.py.

◆ resultStruct

lsst.pipe.tasks.processCcdWithFakes.resultStruct : `lsst.pipe.base.struct.Struct`

Definition at line 448 of file processCcdWithFakes.py.

◆ rngSeed

lsst.pipe.tasks.processCcdWithFakes.rngSeed : `int`

Definition at line 783 of file processCcdWithFakes.py.

◆ sfdSourceCat

lsst.pipe.tasks.processCcdWithFakes.sfdSourceCat : `lsst.afw.table.SourceCatalog`, optional

Definition at line 429 of file processCcdWithFakes.py.

◆ skyMap

lsst.pipe.tasks.processCcdWithFakes.skyMap : `lsst.skymap.SkyMap`

Definition at line 420 of file processCcdWithFakes.py.

◆ sourceCat

lsst.pipe.tasks.processCcdWithFakes.sourceCat : `lsst.afw.table.SourceCatalog`

Definition at line 552 of file processCcdWithFakes.py.

◆ wcs

lsst.pipe.tasks.processCcdWithFakes.wcs : `lsst.afw.geom.SkyWcs`, optional

Definition at line 422 of file processCcdWithFakes.py.