Exemplo n.º 1
0
 def run(md):
     kwds = extractCtorArgs(md)
     order = max(md["A_ORDER"], md["B_ORDER"], md["AP_ORDER"], md["BP_ORDER"])
     gridShape = Extent2I(5, 5)
     a = np.zeros((order + 1, order + 1), dtype=float)
     b = np.zeros((order + 1, order + 1), dtype=float)
     ap = np.zeros((order + 1, order + 1), dtype=float)
     bp = np.zeros((order + 1, order + 1), dtype=float)
     for p, q in packedRange(order):
         a[p, q] = md.get("A_%d_%d" % (p, q), 0.0)
         b[p, q] = md.get("B_%d_%d" % (p, q), 0.0)
         ap[p, q] = md.get("AP_%d_%d" % (p, q), 0.0)
         bp[p, q] = md.get("BP_%d_%d" % (p, q), 0.0)
     approx = SipApproximation(a=a, b=b, ap=ap, bp=bp, gridShape=gridShape, **kwds)
     self.compareSolution(md, approx)
     diffs = approx.computeMaxDeviation()
     self.assertLess(diffs[0], 1E-10)
     self.assertLess(diffs[1], 1E-10)
     bbox = kwds["bbox"]
     pix1 = [Point2D(x, y)
             for x in np.linspace(bbox.getMinX(), bbox.getMaxX(), gridShape.getX())
             for y in np.linspace(bbox.getMinY(), bbox.getMaxY(), gridShape.getY())]
     iwc1a = kwds["pixelToIwc"].applyForward(pix1)
     pix2a = kwds["pixelToIwc"].applyInverse(iwc1a)
     iwc1b = approx.applyForward(pix1)
     assert_allclose(iwc1a, iwc1b, rtol=1E-9, atol=1E-12)
     pix2b = approx.applyInverse(iwc1a)
     assert_allclose(pix2a, pix2b, rtol=1E-9, atol=1E-12)
Exemplo n.º 2
0
 def run(md, **kwds2):
     kwds = extractCtorArgs(md)
     kwds.update(kwds2)
     gridShape = Extent2I(20, 20)
     approx = SipApproximation(gridShape=gridShape, **kwds)
     diffs = approx.computeMaxDeviation()
     self.assertLess(diffs[0], 0.1)
     self.assertLess(diffs[1], 0.1)
Exemplo n.º 3
0
 def run(md, **kwds2):
     kwds = extractCtorArgs(md)
     kwds.update(kwds2)
     gridShape = Extent2I(20, 20)
     approx = SipApproximation(gridShape=gridShape, **kwds)
     diffs = approx.computeMaxDeviation()
     self.assertLess(diffs[0], 0.1)
     self.assertLess(diffs[1], 0.1)
Exemplo n.º 4
0
 def run(md, **kwds2):
     kwds = extractCtorArgs(md)
     kwds['order'] = max(md["A_ORDER"], md["B_ORDER"], md["AP_ORDER"], md["BP_ORDER"])
     kwds.update(kwds2)
     gridShape = Extent2I(10, 10)
     approx = SipApproximation(gridShape=gridShape, **kwds)
     diffs = approx.computeMaxDeviation()
     self.compareSolution(md, approx)
     self.assertLess(diffs[0], 1E-10)
     self.assertLess(diffs[1], 1E-10)
Exemplo n.º 5
0
 def run(md, **kwds2):
     kwds = extractCtorArgs(md)
     kwds['order'] = max(md["A_ORDER"], md["B_ORDER"], md["AP_ORDER"],
                         md["BP_ORDER"])
     kwds.update(kwds2)
     gridShape = Extent2I(10, 10)
     approx = SipApproximation(gridShape=gridShape, **kwds)
     diffs = approx.computeMaxDeviation()
     self.compareSolution(md, approx)
     self.assertLess(diffs[0], 1E-10)
     self.assertLess(diffs[1], 1E-10)
Exemplo n.º 6
0
 def run(md):
     kwds = extractCtorArgs(md)
     order = max(md["A_ORDER"], md["B_ORDER"], md["AP_ORDER"],
                 md["BP_ORDER"])
     gridShape = Extent2I(5, 5)
     a = np.zeros((order + 1, order + 1), dtype=float)
     b = np.zeros((order + 1, order + 1), dtype=float)
     ap = np.zeros((order + 1, order + 1), dtype=float)
     bp = np.zeros((order + 1, order + 1), dtype=float)
     for p, q in packedRange(order):
         a[p, q] = md.get(f"A_{p}_{q}", 0.0)
         b[p, q] = md.get(f"B_{p}_{q}", 0.0)
         ap[p, q] = md.get(f"AP_{p}_{q}", 0.0)
         bp[p, q] = md.get(f"BP_{p}_{q}", 0.0)
     approx = SipApproximation(a=a,
                               b=b,
                               ap=ap,
                               bp=bp,
                               gridShape=gridShape,
                               **kwds)
     self.compareSolution(md, approx)
     diffs = approx.computeMaxDeviation()
     self.assertLess(diffs[0], 1E-10)
     self.assertLess(diffs[1], 1E-10)
     bbox = kwds["bbox"]
     pix1 = [
         Point2D(x, y)
         for x in np.linspace(bbox.getMinX(), bbox.getMaxX(),
                              gridShape.getX())
         for y in np.linspace(bbox.getMinY(), bbox.getMaxY(),
                              gridShape.getY())
     ]
     iwc1a = kwds["pixelToIwc"].applyForward(pix1)
     pix2a = kwds["pixelToIwc"].applyInverse(iwc1a)
     iwc1b = approx.applyForward(pix1)
     assert_allclose(iwc1a, iwc1b, rtol=1E-9, atol=1E-12)
     pix2b = approx.applyInverse(iwc1a)
     assert_allclose(pix2a, pix2b, rtol=1E-9, atol=1E-12)
Exemplo n.º 7
0
def calculateSipWcsHeader(wcs, order, bbox, spacing, header=None):
    """Generate a SIP WCS header approximating a given ``SkyWcs``

    Parameters
    ----------
    wcs : `lsst.afw.geom.SkyWcs`
        World Coordinate System to approximate as SIP.
    order : `int`
        SIP order (equal to the maximum sum of the polynomial exponents).
    bbox : `lsst.geom.Box2I`
        Bounding box over which to approximate the ``wcs``.
    spacing : `float`
        Spacing between sample points.
    header : `lsst.daf.base.PropertyList`, optional
        Header to which to add SIP WCS keywords.

    Returns
    -------
    header : `lsst.daf.base.PropertyList`
        Header including SIP WCS keywords.

    Examples
    --------
    >>> header = calculateSipWcsHeader(exposure.getWcs(), 3, exposure.getBBox(), 20)
    >>> sipWcs = SkyWcs(header)
    """
    transform = getPixelToIntermediateWorldCoords(wcs)
    crpix = wcs.getPixelOrigin()
    cdMatrix = wcs.getCdMatrix()
    crval = wcs.getSkyOrigin()
    gridNum = Extent2I(int(bbox.getWidth() / spacing + 0.5),
                       int(bbox.getHeight() / spacing + 0.5))

    sip = SipApproximation(transform, crpix, cdMatrix, Box2D(bbox), gridNum,
                           order)

    md = makeTanSipMetadata(sip.getPixelOrigin(), crval, sip.getCdMatrix(),
                            sip.getA(), sip.getB(), sip.getAP(), sip.getBP())

    if header is not None:
        header.combine(md)
    else:
        header = md

    return header