788 """Computes and returns a spherical convex polygon approximation to the 789 region of the unit sphere covered by an image specified with a WCS and 790 a width/height (pixels). The polygon is computed by connecting the 791 world coordinates of the 4 image corners with great circles, and can 792 optionally be padded by padRad radians. 795 cd = wcs.getCdMatrix()
796 xpad = math.degrees(padRad) / math.sqrt(cd[0, 0]**2 + cd[0, 1]**2)
797 ypad = math.degrees(padRad) / math.sqrt(cd[1, 0]**2 + cd[1, 1]**2)
798 xmin, ymin = -0.5 - xpad, -0.5 - ypad
799 xmax, ymax = widthPix + xpad - 0.5, heightPix + ypad - 0.5
801 coords = [wcs.pixelToSky(xmin, ymin), wcs.pixelToSky(xmax, ymin),
802 wcs.pixelToSky(xmax, ymax), wcs.pixelToSky(xmin, ymax)]
806 verts.append(tuple(c.getVector()))
808 convex, cc = geom.convex(verts)
810 raise RuntimeError(
'Image corners do not form a convex polygon: ' + cc)
813 return geom.SphericalConvexPolygon(verts)
814 def imageToPolygon(wcs, widthPix, heightPix, padRad=0.0)