Class SipApproximation¶
Defined in File SipApproximation.h
Class Documentation¶
-
class
SipApproximation
¶ A fitter and results class for approximating a general Transform in a form compatible with FITS WCS persistence.
The Simple Imaging Polynomial (SIP) convention (Shupe et al 2005) adds forward and reverse polynomial mappings to a standard projection FITS WCS projection (e.g. “TAN” for gnomonic) that relate Intermediate World Coordinates (see Calabretta & Greisen 2002) to image pixel coordinates. The SIP “forward” transform is defined by polynomial coeffients \(A\) and \(B\) that map pixel coordinates \((u, v)\) to Intermediate World Coordinates \((x, y)\) via
\[\begin{split} \boldsymbol{S}\left[\begin{array}{c} x \\ y \end{array}\right] \equiv \left[\begin{array}{c} x_s \\ y_s \end{array}\right] = \left[\begin{array}{c} (u - u_0) + \displaystyle\sum_{p,q}^{0 \le p + q \le N} \mathrm{A}_{p,q} (u - u_0)^p (v - v_0)^q \\ (v - v_0) + \displaystyle\sum_{p,q}^{0 \le p + q \le N} \mathrm{B}_{p,q} (u - u_0)^p (v - v_0)^q \end{array}\right] \end{split}\]The reverse transform has essentially the same form:\[\begin{split} \left[\begin{array}{c} u - u_0 \\ v - v_0 \end{array}\right] = \left[\begin{array}{c} x_s + \displaystyle\sum_{p,q}^{0 \le p + q \le N} \mathrm{AP}_{p,q} x_s^p y_s^q \\ y_s + \displaystyle\sum_{p,q}^{0 \le p + q \le N} \mathrm{BP}_{p,q} x_s^p y_s^q \end{array}\right] \end{split}\]In both cases, \((u_0, v_0)\) is the pixel origin (CRPIX in FITS WCS) and \(\boldsymbol{S}\) is the inverse of the Jacobian “CD” matrix. Both CRPIX and CD are considered fixed inputs, and we do not attempt to null the zeroth- and first-order terms of \(A\) and \(B\) (as some SIP fitters do); together, these conventions make solving for the coefficients a much simpler linear problem.While LSST WCSs are in general too complex to be described exactly in FITS WCS, they can generally be closely approximated by standard FITS WCS projection with additional SIP distortions. This class fits such an approximation, given a TransformPoint2ToPoint2 object that represents the exact mapping from pixels to Intermediate World Coordinates with a SIP distortion.
- Note
In the implementation, we typically refer to \((u-u_0, v-v_0)\) as
dpix
(for “pixel delta”), and \((x_s, y_s)\) assiwc
(for “scaled
intermediate world coordinates”).
Public Functions
Construct a new approximation by fitting on a grid of points.
strong
- Parameters
[in] pixelToIwc
: The true Transform to approximate. Should go from pixels to Intermediate World Coordinates when applyForward is called.[in] crpix
: Pixel origin, using the LSST 0-indexed convention rather than the FITS 1-indexed convention; equal to (CRPIX1 - 1, CRPIX2 - 1).[in] cd
: Nominal Jacobian (“CD” in FITS WCS).[in] bbox
: Pixel-coordinate bounding box over which the approximation should be valid. Used to construct the grid of points to fit.[in] gridShape
: Number of points in x and y for the grid of points.[in] order
: Order of the polynomial (same for forward and reverse transforms).[in] useInverse
: If true, the inverse SIP transform will be fit and compared to data points generated by calls to pixelToIwc.applyInverse instead of pixelToIwc.applyForward.[in] svdThreshold
: Fraction of the largest singular value at which to declare smaller singular values zero in the least squares solution. Negative values use Eigen’s internal default.
- Exceptions
lsst::pex::exceptions::InvalidParameterError
: Thrown if order is negative or gridShape is non-positive.
Construct from existing SIP coefficients.
This constructor is primarily intended for testing purposes.
strong
- Parameters
[in] pixelToIwc
: The true Transform to approximate. Should go from pixels to Intermediate World Coordinates when applyForward is called.[in] crpix
: Pixel origin, using the LSST 0-indexed convention rather than the FITS 1-indexed convention; equal to (CRPIX1 - 1, CRPIX - 1).[in] cd
: Nominal Jacobian (“CD” in FITS WCS).[in] bbox
: Pixel-coordinate bounding box over which the approximation should be valid. Used to construct the grid of points to fit.[in] gridShape
: Number of points in x and y for the grid of points.[in] a
: Matrix of A coefficients, with the first dimension corresponding to powers of \((u - u_0)\) and the second corresponding to powers of \((v - v_0)\).[in] b
: Matrix of B coefficients, with the first dimension corresponding to powers of \((u - u_0)\) and the second corresponding to powers of \((v - v_0)\).[in] ap
: Matrix of AP coefficients, with the first dimension corresponding to powers of \(x_s\) and the second corresponding to powers of \(y_s\).[in] bp
: Matrix of BP coefficients, with the first dimension corresponding to powers of \(x_s\) and the second corresponding to powers of \(y_s\).[in] useInverse
: If true, the inverse SIP transform will be compared to data points generated by calls to pixelToIwc.applyInverse instead of pixelToIwc.applyForward.
- Exceptions
lsst::pex::exceptions::InvalidParameterError
: Thrown if gridShape is non-positive, or any matrix argument is non-square.
-
SipApproximation
(SipApproximation const&)¶
-
SipApproximation &
operator=
(SipApproximation const&)¶
-
SipApproximation
(SipApproximation&&)¶
-
SipApproximation &
operator=
(SipApproximation&&)¶
-
~SipApproximation
()¶
-
int
getOrder
() const¶ Return the polynomial order of the current solution (same for forward and reverse).
-
double
getA
(int p, int q) const¶ Return a coefficient of the forward transform polynomial.
Out-of-bounds arguments yields undefined behavior.
strong
-
double
getB
(int p, int q) const¶ Return a coefficient of the forward transform polynomial.
Out-of-bounds arguments yields undefined behavior.
strong
-
double
getAP
(int p, int q) const¶ Return a coefficient of the reverse transform polynomial.
Out-of-bounds arguments yields undefined behavior.
strong
-
double
getBP
(int p, int q) const¶ Return a coefficient of the reverse transform polynomial.
Out-of-bounds arguments yields undefined behavior.
strong
-
Eigen::MatrixXd
getA
() const¶ Return the coefficients of the forward transform polynomial.
-
Eigen::MatrixXd
getB
() const¶ Return the coefficients of the forward transform polynomial.
-
Eigen::MatrixXd
getAP
() const¶ Return the coefficients of the reverse transform polynomial.
-
Eigen::MatrixXd
getBP
() const¶ Return the coefficients of the reverse transform polynomial.
-
Point2D
applyForward
(Point2D const &pix) const¶ Convert a point from pixels to intermediate world coordinates.
This method is inefficient and should only be used for diagnostic purposes.
strong
-
std::vector<Point2D>
applyForward
(std::vector<Point2D> const &pix) const¶ Convert an array of points from pixels to intermediate world coordinates.
strong
-
Point2D
applyInverse
(Point2D const &iwcs) const¶ Convert a point from intermediate world coordinates to pixels.
This method is inefficient and should only be used for diagnostic purposes.
strong
-
std::vector<Point2D>
applyInverse
(std::vector<Point2D> const &iwcs) const¶ Convert an array of points from intermediate world coordinates to pixels.
strong
-
Extent2D
getGridStep
() const¶ Return the distance between grid points in pixels.
-
Extent2I
getGridShape
() const¶ Return the number of grid points in x and y.
-
Box2D
getBBox
() const¶ Return the pixel-coordinate bounding box over which the approximation should be valid.
-
Point2D
getPixelOrigin
() const¶ Return the pixel origin of the WCS being approximated.
-
Eigen::Matrix2d
getCdMatrix
() const¶ Return the CD matrix of the WCS being approximated.
-
void
updateGrid
(Extent2I const &shape)¶ Update the grid to the given number of points in x and y.
This does not invalidate or modify the current solution; this allows the user to fit with a coarse grid and then check whether the solution still works well on a finer grid.
strong
- Exceptions
lsst::pex::exceptions::InvalidParameterError
: Thrown if shape is non-positive.
-
void
refineGrid
(int factor = 2)¶ Update the grid by making it finer by a given integer factor.
strong
- Exceptions
lsst::pex::exceptions::InvalidParameterError
: Thrown if factor is non-positive.
-
void
fit
(int order, double svdThreshold = -1)¶ Obtain a new solution at the given order with the current grid.
strong
- Parameters
[in] order
: Polynomial order to fit.[in] svdThreshold
: Fraction of the largest singular value at which to declare smaller singular values zero in the least squares solution. Negative values use Eigen’s internal default.
- Exceptions
pex::exceptions::LogicError
: Thrown if the number of free parameters implied by order is larger than the number of data points defined by the grid.
-
std::pair<double, double>
computeMaxDeviation
() const¶ Return the maximum deviation of the solution from the exact transform on the current grid.
The deviations are in scaled intermediate world coordinates \(\sqrt{\delta x_s^2 \delta y_s^2}\) for the forward transform and in pixels \((\delta u^2, \delta v^2)\) for the reverse transform (respectively). Note that in the common case where the CD matrix includes the scaling from angle units to pixel units, the scaled intermediate world coordinate values are also in (nominal) pixel units.