Ejemplo n.º 1
0
    def testPadPsf(self):
        """Test automatic and manual PSF padding

        Compare expected Psf size, after padding, to the reference Psf size.
        The reference Psf Size is proxy for the Sciencee Psf size here.
        """
        psfModel = measAlg.DoubleGaussianPsf(self.ksize, self.ksize,
                                             self.sigma2)

        # Test automatic padding (doAutoPadPsf is True by default)
        autoPaddedKernel = nextOddInteger(self.subconfig.kernelSize *
                                          self.config.autoPadPsfTo)
        psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
        results = psfMatch.run(self.exp, psfModel)
        self.assertEqual(
            results.psfMatchedExposure.getPsf().computeImage().getWidth(),
            autoPaddedKernel)

        # Test manual padding
        self.config.doAutoPadPsf = False
        PAD_EVEN_VALUES = [0, 2, 4]
        for padPix in PAD_EVEN_VALUES:
            self.config.padPsfBy = padPix
            psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
            results = psfMatch.run(self.exp, psfModel)
            self.assertEqual(
                results.psfMatchedExposure.getPsf().computeImage().getWidth(),
                self.ksize + padPix)

        PAD_ODD_VALUES = [1, 3, 5]
        for padPix in PAD_ODD_VALUES:
            self.config.padPsfBy = padPix
            psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
            with self.assertRaises(ValueError):
                results = psfMatch.run(self.exp, psfModel)
Ejemplo n.º 2
0
 def testTooBig(self):
     self.subconfig.kernelSize = self.ksize
     psf = measAlg.DoubleGaussianPsf(self.ksize, self.ksize, self.sigma2)
     psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
     try:
         psfMatch.run(self.exp, psf)
     except Exception:
         pass
     else:
         self.fail()
Ejemplo n.º 3
0
 def testPropagateVisitInfo(self):
     """Test that a PSF-matched exposure preserves the original VisitInfo.
     """
     self.exp.getInfo().setVisitInfo(makeVisitInfo())
     psfModel = measAlg.DoubleGaussianPsf(self.ksize + 2, self.ksize + 2,
                                          self.sigma2)
     psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
     psfMatchedExposure = psfMatch.run(self.exp,
                                       psfModel).psfMatchedExposure
     self.assertEqual(psfMatchedExposure.getInfo().getVisitInfo(),
                      self.exp.getInfo().getVisitInfo())
Ejemplo n.º 4
0
    def runMatch(self, kOrder=0, kSumIn=3.7):
        self.subconfig.spatialKernelOrder = kOrder

        psf = measAlg.DoubleGaussianPsf(self.ksize, self.ksize, self.sigma2)
        psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
        results = psfMatch.run(self.exp, psf, kernelSum=kSumIn)

        matchingKernel = results.psfMatchingKernel

        kImage = afwImage.ImageD(matchingKernel.getDimensions())
        kSumOut = matchingKernel.computeImage(kImage, False)

        self.assertAlmostEqual(kSumIn, kSumOut)
Ejemplo n.º 5
0
 def testAdjustModelSize(self):
     """Test that modelPsfMatch correctly adjusts the model PSF dimensions to
     match those of the science PSF.
     """
     self.config.doAutoPadPsf = False
     psfModel = measAlg.DoubleGaussianPsf(self.ksize + 2, self.ksize + 2,
                                          self.sigma2)
     psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
     results = psfMatch.run(self.exp, psfModel)
     self.assertEqual(
         results.psfMatchedExposure.getPsf().computeImage().getDimensions(),
         self.exp.getPsf().computeImage().getDimensions())
     self.assertEqual(results.psfMatchedExposure.getPsf().getSigma1(),
                      self.sigma2)
Ejemplo n.º 6
0
 def testTooBig(self):
     """Test that modelPsfMatchTask raises if kernel size is too big and
     and automatic padding disabled
     """
     self.config.doAutoPadPsf = False
     self.subconfig.kernelSize = self.ksize
     psf = measAlg.DoubleGaussianPsf(self.ksize, self.ksize, self.sigma2)
     psfMatch = ipDiffim.ModelPsfMatchTask(config=self.config)
     try:
         psfMatch.run(self.exp, psf)
     except Exception:
         pass
     else:
         self.fail()
Ejemplo n.º 7
0
    calexpPath = sys.argv[1]
    boostPath = sys.argv[2]
    sigGauss = float(sys.argv[3])

    calexp = afwImage.ExposureF(calexpPath)
    psf = pcapsf_read_boost(boostPath)
    if not calexp.hasPsf():
        calexp.setPsf(psf)

    # match to this
    gaussPsf = measAlg.DoubleGaussianPsf(psf.getKernel().getWidth(),
                                         psf.getKernel().getHeight(), sigGauss)

    config = ipDiffim.ModelPsfMatchTask.ConfigClass()
    subconfig = config.kernel
    psfMatch = ipDiffim.ModelPsfMatchTask(subconfig)
    results = psfMatch.run(calexp, gaussPsf)
    cim = results.psfMatchedExposure
    sk = results.psfMatchingKernel
    kcs = results.kernelCellSet

    if 0:
        diffimTools.displaySpatialKernelQuality(kcs, sk, sb, frame=1)
    else:
        ds9.setMaskPlaneVisibility("DETECTED", False)
        ds9.mtv(calexp, frame=1)
        diffimTools.displaySpatialKernelMosaic(psf.getKernel(),
                                               calexp.getWidth(),
                                               calexp.getHeight(),
                                               frame=2)
        diffimTools.displaySpatialKernelMosaic(gaussPsf.getKernel(),