fitsmgmt.wcs.local_cd_matrix

fitsmgmt.wcs.local_cd_matrix(wcs, x0, y0, step=0.001)

Estimate the local CD matrix (deg/pixel) of a WCS at one pixel position.

Computes the CD matrix by finite-differencing wcs.all_pix2world at (x0, y0), (x0 + step, y0), and (x0, y0 + step). This is useful for building a small linear WCS that is tangent to a larger (possibly non-linear, e.g. SIP-distorted) WCS at one point – for example, to set up a common output grid centered on a moving target’s position in each of several input frames before reprojecting them onto it.

Note the result is the Jacobian of RA/Dec (not of the cos(dec)-corrected tangent-plane coordinates) with respect to pixel position, evaluated by direct finite differencing. Away from dec=0, this generally differs from wcs.wcs.cd itself (when wcs happens to already be a linear TAN WCS) by the local cos(dec) factor relating RA to angular distance – that is expected, not a bug; see make_linear_wcs for the matrix this function’s output is meant to feed into.

Parameters

wcs : astropy.wcs.WCS

The WCS to linearize.

x0 : float

Pixel position (0-indexed, in wcs’s pixel convention) at which to evaluate the local CD matrix.

y0 : float

Pixel position (0-indexed, in wcs’s pixel convention) at which to evaluate the local CD matrix.

step : float = 0.001

Finite-difference step size in pixels. Default is 1e-3.

Returns

cd : numpy.ndarray

2x2 CD matrix in deg/pixel, ordered as [[dRA/dx, dRA/dy], [dDec/dx, dDec/dy]], with the RA terms already corrected for wraparound at the 0/360 deg boundary.