23 __all__ = [
"approximateWcs"]
36 """A fake unit test case class that will enable us to call
37 assertWcsAlmostEqualOverBBox from the method approximateWcs"""
40 raise UserWarning(
"WCS fitting failed " + msgStr)
44 skyTolerance=0.001*lsst.geom.arcseconds, pixelTolerance=0.02, useTanWcs=False):
45 """Approximate an existing WCS as a TAN-SIP WCS
47 The fit is performed by evaluating the WCS at a uniform grid of points
48 within a bounding box.
52 wcs : `lsst.afw.geom.SkyWcs`
54 bbox : `lsst.geom.Box2I`
55 the region over which the WCS will be fit
59 number of grid points along x
61 number of grid points along y
63 number of times to iterate over fitting
64 skyTolerance : `lsst.geom.Angle`
65 maximum allowed difference in world coordinates between
66 input wcs and approximate wcs (default is 0.001 arcsec)
67 pixelTolerance : `float`
68 maximum allowed difference in pixel coordinates between
69 input wcs and approximate wcs (default is 0.02 pixels)
71 send a TAN version of wcs to the fitter? It is documented to require that,
72 but I don't think the fitter actually cares
76 fitWcs : `lsst.afw.geom.SkyWcs`
80 crpix = wcs.getPixelOrigin()
81 crval = wcs.getSkyOrigin()
82 cdMatrix = wcs.getCdMatrix(crpix)
88 refSchema = afwTable.SimpleTable.makeMinimalSchema()
92 sourceSchema = afwTable.SourceTable.makeMinimalSchema()
101 for x
in np.linspace(bboxd.getMinX(), bboxd.getMaxX(), nx):
102 for y
in np.linspace(bboxd.getMinY(), bboxd.getMaxY(), ny):
104 skyCoord = wcs.pixelToSky(pixelPos)
106 refObj = refCat.addNew()
107 refObj.set(refCoordKey, skyCoord)
109 source = sourceCat.addNew()
110 source.set(sourceCentroidKey, pixelPos)
115 for indx
in range(iterations):
117 tanWcs = sipObject.getNewWcs()
118 fitWcs = sipObject.getNewWcs()
122 maxDiffPix=pixelTolerance)