Esempio n. 1
0
    def psf(self, exposure, sources):
        """Measure the PSF

        @param exposure Exposure to process
        @param sources Measured sources on exposure
        """
        assert exposure, "No exposure provided"
        assert sources, "No sources provided"
        psfPolicy = self.config['psf']
        selName = psfPolicy['selectName']
        selPolicy = psfPolicy['select'].getPolicy()
        algName = psfPolicy['algorithmName']
        algPolicy = psfPolicy['algorithm'].getPolicy()
        self.log.log(self.log.INFO, "Measuring PSF")

        #
        # Run an extra detection step to mask out faint stars
        #
        if False:
            print "RHL is cleaning faint sources"

            import lsst.afw.math as afwMath

            sigma = 1.0
            gaussFunc = afwMath.GaussianFunction1D(sigma)
            gaussKernel = afwMath.SeparableKernel(15, 15, gaussFunc, gaussFunc)

            im = exposure.getMaskedImage().getImage()
            convolvedImage = im.Factory(im.getDimensions())
            afwMath.convolve(convolvedImage, im, gaussKernel)
            del im

            fs = afwDet.makeFootprintSet(convolvedImage,
                                         afwDet.createThreshold(4, "stdev"))
            fs = afwDet.makeFootprintSet(fs, 3, True)
            fs.setMask(exposure.getMaskedImage().getMask(), "DETECTED")

        starSelector = measAlg.makeStarSelector(selName, selPolicy)
        psfCandidateList = starSelector.selectStars(exposure, sources)

        psfDeterminer = measAlg.makePsfDeterminer(algName, algPolicy)
        psf, cellSet = psfDeterminer.determinePsf(exposure, psfCandidateList)

        # The PSF candidates contain a copy of the source, and so we need to explicitly propagate new flags
        for cand in psfCandidateList:
            cand = measAlg.cast_PsfCandidateF(cand)
            src = cand.getSource()
            if src.getFlagForDetection() & measAlg.Flags.PSFSTAR:
                ident = src.getId()
                src = sources[ident]
                assert src.getId() == ident
                src.setFlagForDetection(src.getFlagForDetection()
                                        | measAlg.Flags.PSFSTAR)

        exposure.setPsf(psf)
        return psf, cellSet
    def setup(self):
        self.log = Log(self.log, "PsfDeterminationStage - parallel")

        policyFile = pexPolicy.DefaultPolicyFile("meas_pipeline", 
                                                 "PsfDeterminationStageDictionary.paf", "policy")
        defPolicy = pexPolicy.Policy.createPolicy(policyFile, policyFile.getRepositoryPath(), True)
        
        if self.policy is None:
            self.policy = pexPolicy.Policy()
        self.policy.mergeDefaults(defPolicy.getDictionary())

        starSelectorName = self.policy.get("starSelectorName")
        starSelectorPolicy = self.policy.getPolicy("starSelectorPolicy")
        self.starSelector = measAlg.makeStarSelector(starSelectorName, starSelectorPolicy)

        psfDeterminerName = self.policy.get("psfDeterminerName")
        psfDeterminerPolicy = self.policy.getPolicy("psfDeterminerPolicy")
        self.psfDeterminer = measAlg.makePsfDeterminer(psfDeterminerName, psfDeterminerPolicy)
Esempio n. 3
0
    def psf(self, exposure, sources, matches):
        """Measure the PSF

        @param exposure Exposure to process
        @param sources Measured sources on exposure
        @param matches (optional) A matchlist as returned by self.astrometry
        """
        assert exposure, "No exposure provided"
        assert sources, "No sources provided"
        psfPolicy = self.config['psf']

        algName   = psfPolicy['algorithmName']
        algPolicy = psfPolicy['algorithm']
        metadata = dafBase.PropertyList()
        self.log.log(self.log.INFO, "Measuring PSF")

        if matches:
            if True:
                #
                # The matchList copies of the sources are not identical to the input sources,
                # so replace them with our pristine originals
                #
                matchesIn = matches
                matches = []
                for ref, source, distance in matchesIn:
                    mySources = [s for s in sources if s.getId() == source.getId()]
                    if len(mySources) != 1:
                        raise RuntimeError("Failed to find matchList source ID == %d in input source list" %
                                           source.getId())
                    mySource = mySources[0]
                    
                    matches.append((ref, mySource, distance))

                    if False:
                        print mySource.getXAstrom(), source.getXAstrom() - mySource.getXAstrom(), \
                              mySource.getYAstrom(), source.getYAstrom() - mySource.getYAstrom()
            

        psfCandidateList = self.select(exposure, matches, algPolicy)

        psfDeterminer = measAlg.makePsfDeterminer(algName, algPolicy.getPolicy())
        psf, cellSet = psfDeterminer.determinePsf(exposure, psfCandidateList, metadata)
        exposure.setPsf(psf)
        return psf, cellSet
    def setup(self):
        self.log = Log(self.log, "PsfDeterminationStage - parallel")

        policyFile = pexPolicy.DefaultPolicyFile(
            "meas_pipeline", "PsfDeterminationStageDictionary.paf", "policy")
        defPolicy = pexPolicy.Policy.createPolicy(
            policyFile, policyFile.getRepositoryPath(), True)

        if self.policy is None:
            self.policy = pexPolicy.Policy()
        self.policy.mergeDefaults(defPolicy.getDictionary())

        starSelectorName = self.policy.get("starSelectorName")
        starSelectorPolicy = self.policy.getPolicy("starSelectorPolicy")
        self.starSelector = measAlg.makeStarSelector(starSelectorName,
                                                     starSelectorPolicy)

        psfDeterminerName = self.policy.get("psfDeterminerName")
        psfDeterminerPolicy = self.policy.getPolicy("psfDeterminerPolicy")
        self.psfDeterminer = measAlg.makePsfDeterminer(psfDeterminerName,
                                                       psfDeterminerPolicy)
Esempio n. 5
0
    algPolicy.add('lambda', 0.5)
    algPolicy.add('reducedChi2ForPsfCandidates', 2.)
    algPolicy.add('nEigenComponents', 4)
    algPolicy.add('kernelSize', 5)
    algPolicy.add('kernelSizeMin', 13)
    algPolicy.add('kernelSizeMax', 45)
    algPolicy.add('spatialOrder', 2)
    algPolicy.add('nStarPerCell', 0)
    algPolicy.add('nStarPerCellSpatialFit', 10)
    algPolicy.add('tolerance', 1e-2)
    algPolicy.add('spatialReject', 3.)

    starSelector = measAlg.makeStarSelector(selName, selPolicy)
    psfCandidateList = starSelector.selectStars(exposure, sources)

    psfDeterminer = measAlg.makePsfDeterminer(algName, algPolicy)
    psf, cellSet = psfDeterminer.determinePsf(exposure, psfCandidateList)

    # The PSF candidates contain a copy of the source, and so we need to explicitly propagate new flags
    for cand in psfCandidateList:
        cand = measAlg.cast_PsfCandidateF(cand)
        src = cand.getSource()
        if src.getFlagForDetection() & measAlg.Flags.PSFSTAR:
            ident = src.getId()
            src = sources[ident]
            assert src.getId() == ident
            src.setFlagForDetection(src.getFlagForDetection()
                                    | measAlg.Flags.PSFSTAR)
    exposure.setPsf(psf)

    print 'Got PSF', psf
Esempio n. 6
0
	algPolicy.add('lambda', 0.5)
	algPolicy.add('reducedChi2ForPsfCandidates', 2.)
	algPolicy.add('nEigenComponents', 4)
	algPolicy.add('kernelSize', 5)
	algPolicy.add('kernelSizeMin', 13)
	algPolicy.add('kernelSizeMax', 45)
	algPolicy.add('spatialOrder', 2)
	algPolicy.add('nStarPerCell', 0)
	algPolicy.add('nStarPerCellSpatialFit', 10)
	algPolicy.add('tolerance', 1e-2)
	algPolicy.add('spatialReject', 3.)
	
	starSelector = measAlg.makeStarSelector(selName, selPolicy)
	psfCandidateList = starSelector.selectStars(exposure, sources)

	psfDeterminer = measAlg.makePsfDeterminer(algName, algPolicy)
	psf, cellSet = psfDeterminer.determinePsf(exposure, psfCandidateList)

	# The PSF candidates contain a copy of the source, and so we need to explicitly propagate new flags
	for cand in psfCandidateList:
		cand = measAlg.cast_PsfCandidateF(cand)
		src = cand.getSource()
		if src.getFlagForDetection() & measAlg.Flags.PSFSTAR:
			ident = src.getId()
			src = sources[ident]
			assert src.getId() == ident
			src.setFlagForDetection(src.getFlagForDetection() | measAlg.Flags.PSFSTAR)
	exposure.setPsf(psf)

	print 'Got PSF', psf