convControl = afwMath.ConvolutionControl()
convControl.setDoNormalize(False)
convControl.setDoCopyEdge(False)
# Set a reference exposure to use for creating the new coadd.
# It doesn't matter which exposure we use, since we just need the
# bounding box information and Factory to create a new expsure with
# the same dtype.
refExp = inputCoadds[0]
bbox = refExp.getBBox()
image = refExp.image.Factory(bbox)
variance_list = []
# Convovle the image in each band and weight by the median variance
for calexp in inputCoadds:
convolved = convolveImage(calexp.image, calexp.getPsf())
_variance = np.median(calexp.variance.array)
convolved.array[:] /= _variance
image += convolved
variance_list.append(_variance)
variance = refExp.variance.Factory(bbox)
if self.config.outputPixelatedVariance:
# Write the per pixel variance to the output coadd
variance.array[:] = np.sum([1/coadd.variance for coadd in inputCoadds], axis=0)
else:
# Use a flat variance in each band
variance.array[:] = np.sum(1/np.array(variance_list))
# Combine the masks planes to calculate the mask plae of the new coadd
mask = self.combinedMasks([coadd.mask for coadd in inputCoadds])
# Create the exposure
maskedImage = refExp.maskedImage.Factory(image, mask=mask, variance=variance)
chi2coadd = refExp.Factory(maskedImage, exposureInfo=refExp.getInfo())
chi2coadd.info.setFilter(None)
return pipeBase.Struct(chi2Coadd=chi2coadd)
class DetectChi2SourcesConnections(
pipeBase.PipelineTaskConnections,
dimensions=("tract", "patch", "skymap"),
defaultTemplates={
"inputCoaddName": "deepChi2",
"outputCoaddName": "deepChi2"
}
):
detectionSchema = cT.InitOutput(
doc="Schema of the detection catalog",
name="{outputCoaddName}Coadd_det_schema",
storageClass="SourceCatalog",
)
exposure = cT.Input(
doc="Exposure on which detections are to be performed",
name="{inputCoaddName}Coadd_calexp",
storageClass="ExposureF",
dimensions=("tract", "patch", "skymap"),
)
outputSources = cT.Output(
doc="Detected sources catalog",
name="{outputCoaddName}Coadd_det",
storageClass="SourceCatalog",
dimensions=("tract", "patch", "skymap"),
)
class DetectChi2SourcesConfig(pipeBase.PipelineTaskConfig, pipelineConnections=DetectChi2SourcesConnections):
detection = pexConfig.ConfigurableField(
target=SourceDetectionTask,
doc="Detect sources in chi2 coadd"
)
idGenerator = SkyMapIdGeneratorConfig.make_field()
def setDefaults(self):
super().setDefaults()
self.detection.reEstimateBackground = False
self.detection.thresholdValue = 3
class DetectChi2SourcesTask(pipeBase.PipelineTask):
_DefaultName = "detectChi2Sources"
ConfigClass = DetectChi2SourcesConfig
def __init__(self, schema=None, **kwargs):
# N.B. Super is used here to handle the multiple inheritance of PipelineTasks, the init tree
# call structure has been reviewed carefully to be sure super will work as intended.
super().__init__(**kwargs)
if schema is None:
schema = afwTable.SourceTable.makeMinimalSchema()
self.schema = schema
self.makeSubtask("detection", schema=self.schema)
self.detectionSchema = afwTable.SourceCatalog(self.schema)
def runQuantum(self, butlerQC, inputRefs, outputRefs):
inputs = butlerQC.get(inputRefs)
idGenerator = self.config.idGenerator.apply(butlerQC.quantum.dataId)
inputs["idFactory"] = idGenerator.make_table_id_factory()
inputs["expId"] = idGenerator.catalog_id
outputs = self.run(**inputs)
butlerQC.put(outputs, outputRefs)
def run(self, exposure: afwImage.Exposure, idFactory: afwTable.IdFactory, expId: int) -> pipeBase.Struct:
Definition at line 310 of file assembleChi2Coadd.py.