コード例 #1
0
ファイル: mergeDetections.py プロジェクト: lsst/pipe_tasks
    def runQuantum(self, butlerQC, inputRefs, outputRefs):
        inputs = butlerQC.get(inputRefs)
        exposureIdInfo = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
                                                   "tract_patch")
        inputs["skySeed"] = exposureIdInfo.expId
        inputs["idFactory"] = exposureIdInfo.makeSourceIdFactory()
        catalogDict = {
            ref.dataId['band']: cat
            for ref, cat in zip(inputRefs.catalogs, inputs['catalogs'])
        }
        inputs['catalogs'] = catalogDict
        skyMap = inputs.pop('skyMap')
        # Can use the first dataId to find the tract and patch being worked on
        tractNumber = inputRefs.catalogs[0].dataId['tract']
        tractInfo = skyMap[tractNumber]
        patchInfo = tractInfo.getPatchInfo(
            inputRefs.catalogs[0].dataId['patch'])
        skyInfo = Struct(skyMap=skyMap,
                         tractInfo=tractInfo,
                         patchInfo=patchInfo,
                         wcs=tractInfo.getWcs(),
                         bbox=patchInfo.getOuterBBox())
        inputs['skyInfo'] = skyInfo

        outputs = self.run(**inputs)
        butlerQC.put(outputs, outputRefs)
コード例 #2
0
 def runQuantum(self, butlerQC, inputRefs, outputRefs):
     inputs = butlerQC.get(inputRefs)
     id_tp = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
                                       "tract_patch").expId
     input_refs_objs = [(inputRefs.cats_meas, inputs['cats_meas']),
                        (inputRefs.coadds, inputs['coadds'])]
     cats, exps = [{dRef.dataId: obj
                    for dRef, obj in zip(refs, objs)}
                   for refs, objs in input_refs_objs]
     dataIds = set(cats).union(set(exps))
     catexps = [
         CatalogExposure(
             catalog=cats.get(dataId),
             exposure=exps.get(dataId),
             dataId=dataId,
             id_tract_patch=id_tp,
         ) for dataId in dataIds
     ]
     outputs = self.run(catexps=catexps, cat_ref=inputs['cat_ref'])
     butlerQC.put(outputs, outputRefs)
     # Validate the output catalog's schema and raise if inconsistent (after output to allow debugging)
     if outputs.cat_output.schema != self.cat_output_schema.schema:
         raise RuntimeError(
             f'{__class__}.config.fit_multiband.run schema != initOutput schema:'
             f' {outputs.cat_output.schema} vs {self.cat_output_schema.schema}'
         )
コード例 #3
0
 def runQuantum(self, butlerQC, inputRefs, outputRefs):
     inputs = butlerQC.get(inputRefs)
     if 'exposureIdInfo' not in inputs.keys():
         inputs['exposureIdInfo'] = ExposureIdInfo.fromDataId(
             butlerQC.quantum.dataId, "visit_detector")
     outputs = self.run(**inputs)
     butlerQC.put(outputs, outputRefs)
コード例 #4
0
 def runQuantum(self, butlerQC, inputRefs, outputRefs):
     # Obtain the list of bands, sort them (alphabetically), then reorder
     # all input lists to match this band order.
     bandOrder = [dRef.dataId["band"] for dRef in inputRefs.coadds]
     bandOrder.sort()
     inputRefs = reorderRefs(inputRefs, bandOrder, dataIdKey="band")
     inputs = butlerQC.get(inputRefs)
     exposureIdInfo = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
                                                "tract_patch")
     inputs["idFactory"] = exposureIdInfo.makeSourceIdFactory()
     inputs["filters"] = [dRef.dataId["band"] for dRef in inputRefs.coadds]
     outputs = self.run(**inputs)
     butlerQC.put(outputs, outputRefs)
コード例 #5
0
 def runQuantum(self, butlerQC, inputRefs, outputRefs):
     inputs = butlerQC.get(inputRefs)
     exposureIdInfo = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
                                                "tract_patch")
     inputs["idFactory"] = exposureIdInfo.makeSourceIdFactory()
     inputs["filters"] = [dRef.dataId["band"] for dRef in inputRefs.coadds]
     outputs = self.run(**inputs)
     sortedTemplateCatalogs = []
     for outRef in outputRefs.templateCatalogs:
         band = outRef.dataId['band']
         sortedTemplateCatalogs.append(outputs.templateCatalogs[band])
     outputs.templateCatalogs = sortedTemplateCatalogs
     butlerQC.put(outputs, outputRefs)
コード例 #6
0
    def runQuantum(self, butlerQC, inputRefs, outputRefs):
        inputs = butlerQC.get(inputRefs)
        inputs['exposureIdInfo'] = ExposureIdInfo.fromDataId(
            butlerQC.quantum.dataId, "visit_detector")

        if self.config.doAstrometry:
            refObjLoader = ReferenceObjectLoader(
                dataIds=[
                    ref.datasetRef.dataId for ref in inputRefs.astromRefCat
                ],
                refCats=inputs.pop('astromRefCat'),
                config=self.config.astromRefObjLoader,
                log=self.log)
            self.pixelMargin = refObjLoader.config.pixelMargin
            self.astrometry.setRefObjLoader(refObjLoader)

        if self.config.doPhotoCal:
            photoRefObjLoader = ReferenceObjectLoader(
                dataIds=[
                    ref.datasetRef.dataId for ref in inputRefs.photoRefCat
                ],
                refCats=inputs.pop('photoRefCat'),
                config=self.config.photoRefObjLoader,
                log=self.log)
            self.pixelMargin = photoRefObjLoader.config.pixelMargin
            self.photoCal.match.setRefObjLoader(photoRefObjLoader)

        outputs = self.run(**inputs)

        if self.config.doWriteMatches and self.config.doAstrometry:
            normalizedMatches = afwTable.packMatches(outputs.astromMatches)
            normalizedMatches.table.setMetadata(outputs.matchMeta)
            if self.config.doWriteMatchesDenormalized:
                denormMatches = denormalizeMatches(outputs.astromMatches,
                                                   outputs.matchMeta)
                outputs.matchesDenormalized = denormMatches
            outputs.matches = normalizedMatches
        butlerQC.put(outputs, outputRefs)
コード例 #7
0
    def generateMeasCat(self, exposureDataId, exposure, refCat, refCatInBand,
                        refWcs, idPackerName, footprintData):
        """Generate a measurement catalog for Gen3.

        Parameters
        ----------
        exposureDataId : `DataId`
            Butler dataId for this exposure.
        exposure : `lsst.afw.image.exposure.Exposure`
            Exposure to generate the catalog for.
        refCat : `lsst.afw.table.SourceCatalog`
            Catalog of shapes and positions at which to force photometry.
        refCatInBand : `lsst.afw.table.SourceCatalog`
            Catalog of shapes and position in the band forced photometry is
            currently being performed
        refWcs : `lsst.afw.image.SkyWcs`
            Reference world coordinate system.
        idPackerName : `str`
            Type of ID packer to construct from the registry.
        footprintData : `ScarletDataModel` or `lsst.afw.table.SourceCatalog`
            Either the scarlet data models or the deblended catalog
            containing footprints.
            If `footprintData` is `None` then the footprints contained
            in `refCatInBand` are used.

        Returns
        -------
        measCat : `lsst.afw.table.SourceCatalog`
            Catalog of forced sources to measure.
        expId : `int`
            Unique binary id associated with the input exposure

        Raises
        ------
        LookupError
            Raised if a footprint with a given source id was in the reference
            catalog but not in the reference catalog in band (meaning there
            was some sort of mismatch in the two input catalogs)
        """
        exposureIdInfo = ExposureIdInfo.fromDataId(exposureDataId,
                                                   idPackerName)
        idFactory = exposureIdInfo.makeSourceIdFactory()

        measCat = self.measurement.generateMeasCat(exposure,
                                                   refCat,
                                                   refWcs,
                                                   idFactory=idFactory)
        # attach footprints here, as the attachFootprints method is geared for gen2
        # and is not worth modifying, as this can naturally live inside this method
        if self.config.footprintDatasetName == "ScarletModelData":
            # Load the scarlet models
            self._attachScarletFootprints(catalog=measCat,
                                          modelData=footprintData,
                                          exposure=exposure,
                                          band=exposureDataId["band"])
        else:
            if self.config.footprintDatasetName is None:
                footprintCat = refCatInBand
            else:
                footprintCat = footprintData
            for srcRecord in measCat:
                fpRecord = footprintCat.find(srcRecord.getId())
                if fpRecord is None:
                    raise LookupError(
                        "Cannot find Footprint for source {}; please check that {} "
                        "IDs are compatible with reference source IDs".format(
                            srcRecord.getId(), footprintCat))
                srcRecord.setFootprint(fpRecord.getFootprint())
        return measCat, exposureIdInfo.expId
コード例 #8
0
 def runQuantum(self, butlerQC, inputRefs, outputRefs):
     inputs = butlerQC.get(inputRefs)
     inputs["idFactory"] = ExposureIdInfo.fromDataId(
         butlerQC.quantum.dataId, "tract_patch").makeSourceIdFactory()
     outputs = self.run(**inputs)
     butlerQC.put(outputs, outputRefs)