770 """Computes and returns a spherical convex polygon approximation to the
771 region of the unit sphere covered by an image specified with a WCS and
772 a width/height (pixels). The polygon is computed by connecting the
773 world coordinates of the 4 image corners with great circles, and can
774 optionally be padded by padRad radians.
777 cd = wcs.getCDMatrix()
778 xpad = math.degrees(padRad) / math.sqrt(cd[0,0]**2 + cd[0,1]**2)
779 ypad = math.degrees(padRad) / math.sqrt(cd[1,0]**2 + cd[1,1]**2)
780 xmin, ymin = -0.5 - xpad, -0.5 - ypad
781 xmax, ymax = widthPix + xpad - 0.5, heightPix + ypad - 0.5
783 coords = [wcs.pixelToSky(xmin, ymin), wcs.pixelToSky(xmax, ymin),
784 wcs.pixelToSky(xmax, ymax), wcs.pixelToSky(xmin, ymax)]
788 verts.append(tuple(c.getVector()))
790 convex, cc = geom.convex(verts)
792 raise RuntimeError(
'Image corners do not form a convex polygon: ' + cc)
795 return geom.SphericalConvexPolygon(verts)