32 __all__ = [
"approximateWcs"]
35 """A fake unit test case class that will enable us to call
36 assertWcsNearlyEqualOverBBox from the method approximateWcs"""
39 raise UserWarning(
"WCS fitting failed " + msgStr)
41 def approximateWcs(wcs, bbox, order=3, nx=20, ny=20, iterations=3, \
42 skyTolerance=0.001*afwGeom.arcseconds, pixelTolerance=0.02, useTanWcs=
False):
43 """Approximate an existing WCS as a TAN-SIP WCS
45 The fit is performed by evaluating the WCS at a uniform grid of points within a bounding box.
47 @param[in] wcs wcs to approximate
48 @param[in] bbox the region over which the WCS will be fit
49 @param[in] order order of SIP fit
50 @param[in] nx number of grid points along x
51 @param[in] ny number of grid points along y
52 @param[in] iterations number of times to iterate over fitting
53 @param[in] skyTolerance maximum allowed difference in world coordinates between
54 input wcs and approximate wcs (default is 0.001 arcsec)
55 @param[in] pixelTolerance maximum allowed difference in pixel coordinates between
56 input wcs and approximate wcs (default is 0.02 pixels)
57 @param[in] useTanWcs send a TAN version of wcs to the fitter? It is documented to require that,
58 but I don't think the fitter actually cares
59 @return the fit TAN-SIP WCS
62 crCoord = wcs.getSkyOrigin()
63 crPix = wcs.getPixelOrigin()
64 cdMat = wcs.getCDMatrix()
65 tanWcs =
afwImage.makeWcs(crCoord, crPix, cdMat[0,0], cdMat[0,1], cdMat[1,0], cdMat[1,1])
70 refSchema = afwTable.SimpleTable.makeMinimalSchema()
74 sourceSchema = afwTable.SourceTable.makeMinimalSchema()
75 SingleFrameMeasurementTask(schema=sourceSchema)
83 for x
in numpy.linspace(bboxd.getMinX(), bboxd.getMaxX(), nx):
84 for y
in numpy.linspace(bboxd.getMinY(), bboxd.getMaxY(), ny):
86 skyCoord = wcs.pixelToSky(pixelPos)
88 refObj = refCat.addNew()
89 refObj.set(refCoordKey, skyCoord)
91 source = sourceCat.addNew()
92 source.set(sourceCentroidKey, pixelPos)
97 for indx
in range(iterations) :
99 tanWcs = sipObject.getNewWcs()
100 fitWcs = sipObject.getNewWcs()
104 maxDiffPix=pixelTolerance)
std::vector< ReferenceMatch > ReferenceMatchVector
CreateWcsWithSip< MatchT > makeCreateWcsWithSip(std::vector< MatchT > const &matches, afw::image::Wcs const &linearWcs, int const order, afw::geom::Box2I const &bbox=afw::geom::Box2I(), int const ngrid=0)
Factory function for CreateWcsWithSip.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Lightweight representation of a geometric match between two records.
Wcs::Ptr makeWcs(coord::Coord const &crval, geom::Point2D const &crpix, double CD11, double CD12, double CD21, double CD22)
Create a Wcs object from crval, crpix, CD, using CD elements (useful from python) ...
A floating-point coordinate rectangle geometry.
def assertWcsNearlyEqualOverBBox
Compare pixelToSky and skyToPixel for two WCS over a rectangular grid of pixel positions.
A FunctorKey used to get or set celestial coordiantes from a pair of Angle keys.