def __init__(self, butler=None, schema=None, initInputs=None, **kwargs):
        # Make PipelineTask-only wording less transitional after cmdlineTask is removed
        """!
        @brief Initialize the merge detections task.

        A @ref FootprintMergeList_ "FootprintMergeList" will be used to
        merge the source catalogs.

        @param[in] schema     the schema of the detection catalogs used as input to this one
        @param[in] butler     a butler used to read the input schema from disk, if schema is None
        @param[in] initInputs This a PipelineTask-only argument that holds all inputs passed in
                              through the PipelineTask middleware
        @param[in] **kwargs   keyword arguments to be passed to CmdLineTask.__init__

        The task will set its own self.schema attribute to the schema of the output merged catalog.
        """
        super().__init__(**kwargs)
        if initInputs is not None:
            schema = initInputs['schema'].schema

        self.makeSubtask("skyObjects")
        self.schema = self.getInputSchema(butler=butler, schema=schema)

        filterNames = [
            getShortFilterName(name) for name in self.config.priorityList
        ]
        filterNames += [self.config.skyFilterName]
        self.merged = afwDetect.FootprintMergeList(self.schema, filterNames)
        self.outputSchema = afwTable.SourceCatalog(self.schema)
        self.outputPeakSchema = afwDetect.PeakCatalog(
            self.merged.getPeakSchema())
Esempio n. 2
0
def mergeCatalogs(catList, names, peakDist, idFactory, indivNames=[], samePeakDist=-1.):
    schema = afwTable.SourceTable.makeMinimalSchema()
    merged = afwDetect.FootprintMergeList(schema, names)

    if not indivNames:
        indivNames = names

    # Count the number of objects and peaks in this list
    mergedList = merged.getMergedSourceCatalog(catList, indivNames, peakDist,
                                               schema, idFactory, samePeakDist)
    nob = len(mergedList)
    npeaks = sum([len(ob.getFootprint().getPeaks()) for ob in mergedList])

    return mergedList, nob, npeaks
    exposure = afwImage.ExposureF(lsst_image.getBBox(afwImage.PARENT))
    exposure.getMaskedImage().getImage().getArray(
    )[:, :] = lsst_image.getArray()

    exposure.getMaskedImage().getVariance().set(noise_sigma**2)
    exposure.setPsf(kernelPsf)
    exposure.setWcs(wcs)
    exposure.setCalib(calib)
    exposures[filter_] = exposure
    result = detectTask.makeSourceCatalog(table, exposure)
    detections[filter_] = result.sources
    result.sources.writeFits('%s/det_%s.fits' % (args.output_dir, filter_))

# merge detection lists together
merged = afwDet.FootprintMergeList(schema,
                                   [filter_ for filter_ in filter_names])

id_factory = afwTable.IdFactory.makeSource(0, 32)
merged_sources = merged.getMergedSourceCatalog(
    [detections[filter_] for filter_ in filter_names],
    [filter_ for filter_ in filter_names], 6, schema, id_factory, 1.8)
for record in merged_sources:
    record.getFootprint().sortPeaks()

print 'Total merged objects', len(merged_sources)
merged_sources.writeFits('%s/det_merge.fits' % (args.output_dir))

catalogs = {}
for filter_ in filter_names:
    print 'deblend, measure', filter_
    exposure = exposures[filter_]