def testDistortionPointerInDetector(self): # no distortion object present by default dist = self.det.getDistortion() self.assertTrue(dist is None) # make sure we can set a radialpoly and round-trip it. x, y = 1.0, 1.0 p = afwGeom.Point2D(x, y) self.det.setDistortion(cameraGeom.RadialPolyDistortion(self.coeffs)) self.roundTrip(self.det.getDistortion(), x, y)
def testRoundTrip(self): x, y = 1.0, 1.0 # try NullDistortion ndist = cameraGeom.NullDistortion() self.roundTrip(ndist, x, y) # try RadialPolyDistortion rdist = cameraGeom.RadialPolyDistortion(self.coeffs) self.roundTrip(rdist, x, y)
def testMomentDistortion(self): moments = [ [1.0, 1.0, 0.0], [1.0, 1.0, 0.1], ] nDist = cameraGeom.NullDistortion() rDist = cameraGeom.RadialPolyDistortion(self.coeffs) for moment in moments: self.tryAFewCoords(rDist, moment) self.tryAFewCoords(nDist, moment)
def testzAxisCases(self): r = 1000.0 iqq = geomEllip.Quadrupole(1.0, 1.0, 0.0) px = afwGeom.Point2D(r, 0.0) py = afwGeom.Point2D(0.0, r) pxy = afwGeom.Point2D(r / numpy.sqrt(2.0), r / numpy.sqrt(2.0)) nDist = cameraGeom.NullDistortion() rDist = cameraGeom.RadialPolyDistortion(self.coeffs) rcoeffs = self.coeffs[:] rcoeffs.reverse() r2Known = numpy.polyval(rcoeffs, r) epsilon = 1.0e-6 drKnown = -(r2Known - numpy.polyval(rcoeffs, r + epsilon)) / epsilon points = [px, py, pxy] scalings = [drKnown**2, drKnown**2, 0.5 * (drKnown**2 - 1.0)] for i in range(3): p = points[i] scale = scalings[i] # check the point p2 = rDist.distort(p, self.det) x, y = p2.getX(), p2.getY() r2Calc = numpy.hypot(x, y) if self.prynt: print "r2known,r2Calc: ", r2Known, r2Calc self.assertAlmostEqual(r2Known, r2Calc) # check the moment iqq2 = rDist.distort(p, iqq, self.det) iqqList = [iqq2.getIxx(), iqq2.getIyy(), iqq2.getIxy()] if self.prynt: print "scale: ", scale, iqqList[i] self.assertAlmostEqual(scale, iqqList[i])
def setUp(self): self.x0, self.y0 = 0, 0 self.nx, self.ny = 512, 512 #2048, 4096 self.sky = 100.0 self.nObj = 100 # make a distorter # This is a lot of distortion ... from circle r=1, to ellipse with a=1.3 (ie. 30%) # For suprimecam, we expect only about 5% self.distCoeffs = [0.0, 1.0, 2.0e-04, 3.0e-8] lanczosOrder = 3 coefficientsDistort = True self.distorter = cameraGeom.RadialPolyDistortion( self.distCoeffs, coefficientsDistort, lanczosOrder) # make a detector self.detector = cameraUtils.makeDefaultCcd( afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(self.nx, self.ny))) self.detector.setDistortion(self.distorter) self.detector.setCenter(cameraGeom.FpPoint( 255.5, 255.5)) # move boresight from center to 0,0 if False: for x, y in [(0, 0), (0, 511), (511, 0), (511, 511)]: p = afwGeom.Point2D(x, y) iqq = self.distorter.distort(p, geomEllip.Quadrupole(), self.detector) print x, y, geomEllip.Axes(iqq) print self.detector.getPositionFromPixel(p).getMm() print "Max distortion on this detector: ", self.distorter.computeMaxShear( self.detector) # detection policies self.detConfig = measAlg.SourceDetectionConfig() # measurement policies self.measSrcConfig = measAlg.SourceMeasurementConfig() # psf star selector starSelectorFactory = measAlg.starSelectorRegistry["secondMoment"] starSelectorConfig = starSelectorFactory.ConfigClass() starSelectorConfig.fluxLim = 5000.0 starSelectorConfig.histSize = 32 starSelectorConfig.clumpNSigma = 1.0 starSelectorConfig.badFlags = [] self.starSelector = starSelectorFactory(starSelectorConfig) # psf determiner psfDeterminerFactory = measAlg.psfDeterminerRegistry["pca"] psfDeterminerConfig = psfDeterminerFactory.ConfigClass() width, height = self.nx, self.ny nEigenComponents = 3 psfDeterminerConfig.sizeCellX = width // 3 psfDeterminerConfig.sizeCellY = height // 3 psfDeterminerConfig.nEigenComponents = nEigenComponents psfDeterminerConfig.spatialOrder = 1 psfDeterminerConfig.kernelSizeMin = 31 psfDeterminerConfig.nStarPerCell = 0 psfDeterminerConfig.nStarPerCellSpatialFit = 0 # unlimited self.psfDeterminer = psfDeterminerFactory(psfDeterminerConfig)