Example #1
0
    def testAddTrimmedAmp(self):
        """Test that building a Ccd from trimmed Amps leads to a trimmed Ccd"""

        dataSec = afwGeom.BoxI(afwGeom.PointI(1, 0), afwGeom.ExtentI(10, 20))
        biasSec = afwGeom.BoxI(afwGeom.PointI(0, 0), afwGeom.ExtentI(1, 1))
        allPixelsInAmp = afwGeom.BoxI(afwGeom.PointI(0, 0), afwGeom.ExtentI(11, 21))
        eParams = cameraGeom.ElectronicParams(1.0, 1.0, 65000)

        ccd = cameraGeom.Ccd(cameraGeom.Id(0))
        self.assertFalse(ccd.isTrimmed())

        for i in range(2):
            amp = cameraGeom.Amp(cameraGeom.Id(i, "", i, 0),
                                 allPixelsInAmp, biasSec, dataSec, eParams)
            amp.setTrimmed(True)

            if i%2 == 0:                # check both APIs
                ccd.addAmp(afwGeom.PointI(i, 0), amp)
            else:
                ccd.addAmp(amp)
            self.assertTrue(ccd.isTrimmed())

        # should fail to add non-trimmed Amp to a trimmed Ccd
        i += 1
        amp = cameraGeom.Amp(cameraGeom.Id(i, "", i, 0),
                             allPixelsInAmp, biasSec, dataSec, eParams)
        self.assertFalse(amp.isTrimmed())

        utilsTests.assertRaisesLsstCpp(self, pexExcept.InvalidParameterException, ccd.addAmp, amp)

        # should fail to add trimmed Amp to a non-trimmed Ccd
        ccd.setTrimmed(False)
        amp.setTrimmed(True)
        utilsTests.assertRaisesLsstCpp(self, pexExcept.InvalidParameterException, ccd.addAmp, amp)
Example #2
0
    def testSortedAmps(self):
        """Test if the Amps are sorted by ID after insertion into a Ccd"""

        ccd = cameraGeom.Ccd(cameraGeom.Id())
        Col = 0
        for serial in [0, 1, 2, 3, 4, 5, 6, 7]:
            gain, readNoise, saturationLevel = 0, 0, 0
            width, height = 10, 10

            allPixels = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(width, height))
            biasSec = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(0, height))
            dataSec = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(width, height))

            eParams = cameraGeom.ElectronicParams(gain, readNoise, saturationLevel)
            amp = cameraGeom.Amp(cameraGeom.Id(serial, "", Col, 0), allPixels, biasSec, dataSec,
                                 eParams)

            ccd.addAmp(afwGeom.Point2I(Col, 0), amp); Col += 1
        #
        # Check that Amps are sorted by Id
        #
        serials = []
        for a in ccd:
            serials.append(a.getId().getSerial())

        self.assertEqual(serials, sorted(serials))
 def _standardizeExposure(self,
                          mapping,
                          item,
                          dataId,
                          filter=True,
                          trimmed=True):
     item = super(FileMapper, self)._standardizeExposure(mapping,
                                                         item,
                                                         dataId,
                                                         filter=filter,
                                                         trimmed=trimmed)
     detector = afwCg.Ccd(afwCg.Id("Dummy"))
     item.setDetector(detector)
     return item
Example #4
0
    def testNullDistortionDefaultCcd(self):
        """Test that we can use a NullDistortion even if the Detector is default-constructed"""
        ccd = cameraGeom.Ccd(cameraGeom.Id("dummy"))
        distorter = cameraGeom.NullDistortion()

        pin = afwGeom.PointD(0, 0)
        pout = distorter.undistort(pin, ccd)

        self.assertEqual(pin, pout)

        ein = geomEllip.Quadrupole(1, 0, 1)
        eout = distorter.distort(pin, ein, ccd)

        self.assertEqual(ein, eout)
Example #5
0
    def testSortedCcds(self):
        """Test if the Ccds are sorted by ID after insertion into a Raft"""

        raft = cameraGeom.Raft(cameraGeom.Id(), 8, 1)
        Col = 0
        for serial in [7, 0, 1, 3, 2, 6, 5, 4]:
            ccd = cameraGeom.Ccd(cameraGeom.Id(serial))
            raft.addDetector(afwGeom.Point2I(Col, 0), cameraGeom.FpPoint(afwGeom.Point2D(0, 0)),
                             cameraGeom.Orientation(0), ccd)
            Col += 1
        #
        # Check that CCDs are sorted by Id
        #
        serials = []
        for ccd in raft:
            serials.append(ccd.getId().getSerial())

        self.assertEqual(serials, sorted(serials))
Example #6
0
    def setUp(self):
        width, height = 110, 301

        self.mi = afwImage.MaskedImageF(afwGeom.ExtentI(width, height))
        self.mi.set(0)
        sd = 3                          # standard deviation of image
        self.mi.getVariance().set(sd*sd)
        self.mi.getMask().addMaskPlane("DETECTED")

        self.FWHM = 5
        self.ksize = 31                      # size of desired kernel

        sigma1 = 1.75
        sigma2 = 2*sigma1

        self.exposure = afwImage.makeExposure(self.mi)
        self.exposure.setPsf(measAlg.DoubleGaussianPsf(self.ksize, self.ksize,
                                                    1.5*sigma1, 1, 0.1))
        crval = afwCoord.makeCoord(afwCoord.ICRS, 0.0*afwGeom.degrees, 0.0*afwGeom.degrees)
        wcs = afwImage.makeWcs(crval, afwGeom.PointD(0, 0), 1.0, 0, 0, 1.0)
        self.exposure.setWcs(wcs)

        ccd = cameraGeom.Ccd(cameraGeom.Id(1))
        ccd.addAmp(cameraGeom.Amp(cameraGeom.Id(0),
                                  afwGeom.BoxI(afwGeom.PointI(0,0), self.exposure.getDimensions()),
                                  afwGeom.BoxI(afwGeom.PointI(0,0), afwGeom.ExtentI(0,0)),
                                  afwGeom.BoxI(afwGeom.PointI(0,0), self.exposure.getDimensions()),
                                  cameraGeom.ElectronicParams(1.0, 100.0, 65535)))
        self.exposure.setDetector(ccd)
        self.exposure.getDetector().setDistortion(None)        
        #
        # Make a kernel with the exactly correct basis functions.  Useful for debugging
        #
        basisKernelList = afwMath.KernelList()
        for sigma in (sigma1, sigma2):
            basisKernel = afwMath.AnalyticKernel(self.ksize, self.ksize,
                                                 afwMath.GaussianFunction2D(sigma, sigma))
            basisImage = afwImage.ImageD(basisKernel.getDimensions())
            basisKernel.computeImage(basisImage, True)
            basisImage /= np.sum(basisImage.getArray())

            if sigma == sigma1:
                basisImage0 = basisImage
            else:
                basisImage -= basisImage0

            basisKernelList.append(afwMath.FixedKernel(basisImage))

        order = 1                                # 1 => up to linear
        spFunc = afwMath.PolynomialFunction2D(order)

        exactKernel = afwMath.LinearCombinationKernel(basisKernelList, spFunc)
        exactKernel.setSpatialParameters([[1.0, 0,          0],
                                          [0.0, 0.5*1e-2, 0.2e-2]])

        rand = afwMath.Random()               # make these tests repeatable by setting seed

        addNoise = True

        if addNoise:
            im = self.mi.getImage()
            afwMath.randomGaussianImage(im, rand) # N(0, 1)
            im *= sd                              # N(0, sd^2)
            del im

        xarr, yarr = [], []

        for x, y in [(20, 20), (60, 20), 
                     (30, 35),
                     (50, 50),
                     (20, 90), (70, 160), (25, 265), (75, 275), (85, 30),
                     (50, 120), (70, 80),
                     (60, 210), (20, 210),
                     ]:
            xarr.append(x)
            yarr.append(y)

        for x, y in zip(xarr, yarr):
            dx = rand.uniform() - 0.5   # random (centered) offsets
            dy = rand.uniform() - 0.5

            k = exactKernel.getSpatialFunction(1)(x, y) # functional variation of Kernel ...
            b = (k*sigma1**2/((1 - k)*sigma2**2))       # ... converted double Gaussian's "b"

            #flux = 80000 - 20*x - 10*(y/float(height))**2
            flux = 80000*(1 + 0.1*(rand.uniform() - 0.5))
            I0 = flux*(1 + b)/(2*np.pi*(sigma1**2 + b*sigma2**2))
            for iy in range(y - self.ksize//2, y + self.ksize//2 + 1):
                if iy < 0 or iy >= self.mi.getHeight():
                    continue

                for ix in range(x - self.ksize//2, x + self.ksize//2 + 1):
                    if ix < 0 or ix >= self.mi.getWidth():
                        continue

                    I = I0*psfVal(ix, iy, x + dx, y + dy, sigma1, sigma2, b)
                    Isample = rand.poisson(I) if addNoise else I
                    self.mi.getImage().set(ix, iy, self.mi.getImage().get(ix, iy) + Isample)
                    self.mi.getVariance().set(ix, iy, self.mi.getVariance().get(ix, iy) + I)
        # 
        bbox = afwGeom.BoxI(afwGeom.PointI(0,0), afwGeom.ExtentI(width, height))
        self.cellSet = afwMath.SpatialCellSet(bbox, 100)

        self.footprintSet = afwDetection.FootprintSet(self.mi, afwDetection.Threshold(100), "DETECTED")

        self.catalog = SpatialModelPsfTestCase.measure(self.footprintSet, self.exposure)

        for source in self.catalog:
            try:
                cand = measAlg.makePsfCandidate(source, self.exposure)
                self.cellSet.insertCandidate(cand)

            except Exception, e:
                print e
                continue
Example #7
0
def makeCcd(ccdName):
    ccd = cameraGeom.Ccd(cameraGeom.Id(ccdName), pixelSize)
    ccd.addAmp(1, 0, makeAmp(1))
    return ccd