コード例 #1
0
ファイル: calibrateTask.py プロジェクト: Daraexus/pipe_tasks
    def loadAndMatch(self, exposure, sourceCat):
        """!Fake loading and matching

        Copy the source catalog to a reference catalog and producing a match list
        """
        wcs = exposure.getWcs()
        refSchema = LoadReferenceObjectsTask.makeMinimalSchema(
            filterNameList = [FilterName],
            addIsPhotometric = True,
        )
        refCat = afwTable.SimpleCatalog(refSchema)
        refFluxKey = refSchema[FilterName + "_flux"].asKey()
        refIsPhotoKey = refSchema["photometric"].asKey()

        matches = lsst.afw.table.ReferenceMatchVector()
        for src in sourceCat:
            flux = 1e-3*src.getPsfFlux()*np.random.normal(1.0, 2e-2)
            refObj = refCat.addNew()
            refObj.set(refFluxKey, flux)
            refObj.setCoord(wcs.pixelToSky(src.getCentroid()))
            refObj.set(refIsPhotoKey, True)
            match = lsst.afw.table.ReferenceMatch(refObj, src, 0)
            matches.append(match)

        return pipeBase.Struct(
            refCat = refCat,
            matches = matches,
            matchMeta = createMatchMetadata(exposure),
        )
コード例 #2
0
    def loadAndMatch(self, exposure, sourceCat):
        """!Fake loading and matching

        Copy the source catalog to a reference catalog and producing a match list
        """
        wcs = exposure.getWcs()
        refSchema = LoadReferenceObjectsTask.makeMinimalSchema(
            filterNameList=[FilterName],
            addIsPhotometric=True,
        )
        refCat = afwTable.SimpleCatalog(refSchema)
        refFluxKey = refSchema[FilterName + "_flux"].asKey()
        refIsPhotoKey = refSchema["photometric"].asKey()

        matches = lsst.afw.table.ReferenceMatchVector()
        for src in sourceCat:
            flux = 1e-3 * src.getPsfFlux() * np.random.normal(1.0, 2e-2)
            refObj = refCat.addNew()
            refObj.set(refFluxKey, flux)
            refObj.setCoord(wcs.pixelToSky(src.getCentroid()))
            refObj.set(refIsPhotoKey, True)
            match = lsst.afw.table.ReferenceMatch(refObj, src, 0)
            matches.append(match)

        return pipeBase.Struct(
            refCat=refCat,
            matches=matches,
            matchMeta=createMatchMetadata(exposure),
        )
コード例 #3
0
    def execute(self, dataRef):
        """!Characterize a science image

        @param dataRef: butler data reference
        @return a pipeBase Struct containing the results
        """
        self.log.info("Performing Super Calibrate on sensor data ID %s" % (dataRef.dataId,))

        self.log.info("Reading input data using dataRef")
        inputData = self.read_input_data(dataRef)

        self.log.info("Running operations. The run() method should not take anything Butler")
        if self.config.doWrite and self.config.doAstrometry:
            self.matchMeta = createMatchMetadata(inputData.getDict()['exposure'], border=self.pixelMargin)
        else:
            self.matchMeta = None
        result = CalibrateTask.calibrate(CalibrateTask(config=self.config, log=self.log, icSourceSchema=self.icSourceSchema),
                                         **inputData.getDict())

        self.log.info("Writing output data using dataRef")
        self.write_output_data(dataRef, result)

        return result
コード例 #4
0
ファイル: calibrate.py プロジェクト: yalsayyad/pipe_tasks
    def run(self, dataRef, exposure=None, background=None, icSourceCat=None, doUnpersist=True):
        """!Calibrate an exposure, optionally unpersisting inputs and persisting outputs.

        This is a wrapper around the `calibrate` method that unpersists inputs
        (if `doUnpersist` true) and persists outputs (if `config.doWrite` true)

        @param[in] dataRef  butler data reference corresponding to a science image
        @param[in,out] exposure  characterized exposure (an lsst.afw.image.ExposureF or similar),
            or None to unpersist existing icExp and icBackground.
            See calibrate method for details of what is read and written.
        @param[in,out] background  initial model of background already subtracted from exposure
            (an lsst.afw.math.BackgroundList). May be None if no background has been subtracted,
            though that is unusual for calibration.
            A refined background model is output.
            Ignored if exposure is None.
        @param[in] icSourceCat  catalog from which to copy the fields specified by icSourceKeys, or None;
        @param[in] doUnpersist  unpersist data:
            - if True, exposure, background and icSourceCat are read from dataRef and those three arguments
                must all be None;
            - if False the exposure must be provided; background and icSourceCat are optional.
            True is intended for running as a command-line task, False for running as a subtask

        @warning until detectAndMeasure can determine suitable sources for measuring aperture correction
        by itself, you must provide icSourceCat and a suitable entry in config.icSourceFieldsToCopy

        @return same data as the calibrate method
        """
        self.log.info("Processing %s" % (dataRef.dataId))

        if doUnpersist:
            if any(item is not None for item in (exposure, background, icSourceCat)):
                raise RuntimeError("doUnpersist true; exposure, background and icSourceCat must all be None")
            exposure = dataRef.get("icExp", immediate=True)
            background = dataRef.get("icExpBackground", immediate=True)
            icSourceCat = dataRef.get("icSrc", immediate=True)
        elif exposure is None:
            raise RuntimeError("doUnpersist false; exposure must be provided")

        if self.config.doWrite and self.config.doAstrometry:
            matchMeta = createMatchMetadata(exposure, border=self.pixelMargin)
        else:
            matchMeta = None

        exposureIdInfo = dataRef.get("expIdInfo")

        calRes = self.calibrate(
            exposure = exposure,
            exposureIdInfo = exposureIdInfo,
            background = background,
            icSourceCat = icSourceCat,
        )

        if self.config.doWrite:
            self.writeOutputs(
                dataRef = dataRef,
                exposure = calRes.exposure,
                background = calRes.background,
                sourceCat = calRes.sourceCat,
                astromMatches = calRes.astromMatches,
                matchMeta = matchMeta,
            )

        return calRes
コード例 #5
0
    def run(self,
            dataRef,
            exposure=None,
            background=None,
            icSourceCat=None,
            doUnpersist=True):
        """!Calibrate an exposure, optionally unpersisting inputs and
            persisting outputs.

        This is a wrapper around the `calibrate` method that unpersists inputs
        (if `doUnpersist` true) and persists outputs (if `config.doWrite` true)

        @param[in] dataRef  butler data reference corresponding to a science
            image
        @param[in,out] exposure  characterized exposure (an
            lsst.afw.image.ExposureF or similar), or None to unpersist existing
            icExp and icBackground. See calibrate method for details of what is
            read and written.
        @param[in,out] background  initial model of background already
            subtracted from exposure (an lsst.afw.math.BackgroundList). May be
            None if no background has been subtracted, though that is unusual
            for calibration. A refined background model is output. Ignored if
            exposure is None.
        @param[in] icSourceCat  catalog from which to copy the fields specified
            by icSourceKeys, or None;
        @param[in] doUnpersist  unpersist data:
            - if True, exposure, background and icSourceCat are read from
              dataRef and those three arguments must all be None;
            - if False the exposure must be provided; background and
              icSourceCat are optional. True is intended for running as a
              command-line task, False for running as a subtask

        @return same data as the calibrate method
        """
        self.log.info("Processing %s" % (dataRef.dataId))

        if doUnpersist:
            if any(item is not None
                   for item in (exposure, background, icSourceCat)):
                raise RuntimeError("doUnpersist true; exposure, background "
                                   "and icSourceCat must all be None")
            exposure = dataRef.get("icExp", immediate=True)
            background = dataRef.get("icExpBackground", immediate=True)
            icSourceCat = dataRef.get("icSrc", immediate=True)
        elif exposure is None:
            raise RuntimeError("doUnpersist false; exposure must be provided")

        if self.config.doWrite and self.config.doAstrometry:
            matchMeta = createMatchMetadata(exposure, border=self.pixelMargin)
        else:
            matchMeta = None

        exposureIdInfo = dataRef.get("expIdInfo")

        calRes = self.calibrate(
            exposure=exposure,
            exposureIdInfo=exposureIdInfo,
            background=background,
            icSourceCat=icSourceCat,
        )

        if self.config.doWrite:
            self.writeOutputs(
                dataRef=dataRef,
                exposure=calRes.exposure,
                background=calRes.background,
                sourceCat=calRes.sourceCat,
                astromMatches=calRes.astromMatches,
                matchMeta=matchMeta,
            )

        return calRes