22 from __future__
import absolute_import, division, print_function
24 __all__ = [
"approximateWcs"]
26 from builtins
import range
27 from builtins
import object
32 from lsst.meas.base
import SingleFrameMeasurementTask
38 """A fake unit test case class that will enable us to call 39 assertWcsAlmostEqualOverBBox from the method approximateWcs""" 42 raise UserWarning(
"WCS fitting failed " + msgStr)
46 skyTolerance=0.001*afwGeom.arcseconds, pixelTolerance=0.02, useTanWcs=False):
47 """Approximate an existing WCS as a TAN-SIP WCS 49 The fit is performed by evaluating the WCS at a uniform grid of points within a bounding box. 51 @param[in] wcs wcs to approximate 52 @param[in] bbox the region over which the WCS will be fit 53 @param[in] order order of SIP fit 54 @param[in] nx number of grid points along x 55 @param[in] ny number of grid points along y 56 @param[in] iterations number of times to iterate over fitting 57 @param[in] skyTolerance maximum allowed difference in world coordinates between 58 input wcs and approximate wcs (default is 0.001 arcsec) 59 @param[in] pixelTolerance maximum allowed difference in pixel coordinates between 60 input wcs and approximate wcs (default is 0.02 pixels) 61 @param[in] useTanWcs send a TAN version of wcs to the fitter? It is documented to require that, 62 but I don't think the fitter actually cares 63 @return the fit TAN-SIP WCS 66 crpix = wcs.getPixelOrigin()
67 crval = wcs.getSkyOrigin()
68 cdMatrix = wcs.getCdMatrix(crpix)
74 refSchema = afwTable.SimpleTable.makeMinimalSchema()
78 sourceSchema = afwTable.SourceTable.makeMinimalSchema()
79 SingleFrameMeasurementTask(schema=sourceSchema)
87 for x
in np.linspace(bboxd.getMinX(), bboxd.getMaxX(), nx):
88 for y
in np.linspace(bboxd.getMinY(), bboxd.getMaxY(), ny):
90 skyCoord = wcs.pixelToSky(pixelPos)
92 refObj = refCat.addNew()
93 refObj.set(refCoordKey, skyCoord)
95 source = sourceCat.addNew()
96 source.set(sourceCentroidKey, pixelPos)
101 for indx
in range(iterations):
103 tanWcs = sipObject.getNewWcs()
104 fitWcs = sipObject.getNewWcs()
107 assertWcsAlmostEqualOverBBox(mockTest, wcs, fitWcs, bbox, maxDiffSky=skyTolerance,
108 maxDiffPix=pixelTolerance)
CreateWcsWithSip< MatchT > makeCreateWcsWithSip(std::vector< MatchT > const &matches, afw::geom::SkyWcs const &linearWcs, int const order, afw::geom::Box2I const &bbox=afw::geom::Box2I(), int const ngrid=0)
Factory function for CreateWcsWithSip.
std::shared_ptr< SkyWcs > makeSkyWcs(Point2D const &crpix, coord::IcrsCoord const &crval, Eigen::Matrix2d const &cdMatrix, std::string const &projection="TAN")
def approximateWcs(wcs, bbox, order=3, nx=20, ny=20, iterations=3, skyTolerance=0.001 *afwGeom.arcseconds, pixelTolerance=0.02, useTanWcs=False)