astropy.wcs.utils.fit_wcs_from_points(xy, world_coords, proj_point='center', projection='TAN', sip_degree=None)[source]

Given two matching sets of coordinates on detector and sky, compute the WCS.

Fits a WCS object to matched set of input detector and sky coordinates. Optionally, a SIP can be fit to account for geometric distortion. Returns an WCS object with the best fit parameters for mapping between input pixel and sky coordinates.

The projection type (default ‘TAN’) can passed in as a string, one of the valid three-letter projection codes - or as a WCS object with projection keywords already set. Note that if an input WCS has any non-polynomial distortion, this will be applied and reflected in the fit terms and coefficients. Passing in a WCS object in this way essentially allows it to be refit based on the matched input coordinates and projection point, but take care when using this option as non-projection related keywords in the input might cause unexpected behavior.

xytuple of two numpy.ndarray

x & y pixel coordinates.


Skycoord object with world coordinates.

proj_point‘center’ or ~astropy.coordinates.SkyCoord`

Defaults to ‘center’, in which the geometric center of input world coordinates will be used as the projection point. To specify an exact point for the projection, a Skycoord object with a coordinate pair can be passed in. For consistency, the units and frame of these coordinates will be transformed to match world_coords if they don’t.

projectionstr or WCS

Three letter projection code, of any of standard projections defined in the FITS WCS standard. Optionally, a WCS object with projection keywords set may be passed in.

sip_degreeNone or int

If set to a non-zero integer value, will fit SIP of degree sip_degree to model geometric distortion. Defaults to None, meaning no distortion corrections will be fit.


The best-fit WCS to the points given.


  • The fiducial point for the spherical projection can be set to ‘center’ to use the mean position of input sky coordinates, or as an SkyCoord object.

  • Units in all output WCS objects will always be in degrees.

  • If the coordinate frame differs between SkyCoord objects passed in for world_coords and proj_point, the frame for world_coords will override as the frame for the output WCS.

  • If a WCS object is passed in to projection the CD/PC matrix will be used as an initial guess for the fit. If this is known to be significantly off and may throw off the fit, set to the identity matrix (for example, by doing wcs.wcs.pc = [(1., 0.,), (0., 1.)])