5 #include "lsst/afw/image/ImageUtils.h"
8 #include "lsst/daf/base/PropertySet.h"
10 namespace jointcal = lsst::jointcal;
11 namespace afwImg = lsst::afw::image;
12 namespace afwGeom = lsst::afw::geom;
17 typedef std::shared_ptr<jointcal::GtransfoPoly>
GtPoly_Ptr;
27 lsst::afw::geom::Point2D crpix_lsst = wcs->getPixelOrigin();
29 lsst::daf::base::PropertyList::Ptr wcsMeta = wcs->getFitsMetadata();
31 if (wcs->hasDistortion()) {
34 lsst::afw::image::TanWcs::decodeSipHeader(*wcsMeta,
"A", sipA);
35 lsst::afw::image::TanWcs::decodeSipHeader(*wcsMeta,
"B", sipB);
37 int sipOrder = std::max(wcsMeta->get<
int>(
"A_ORDER"), wcsMeta->get<
int>(
"B_ORDER"));
40 for (
int i = 0; i <= sipOrder; ++i) {
41 for (
int j = 0; j <= sipOrder; ++j) {
42 if (i < sipA.cols() && j < sipA.rows() && (i + j) <= sipOrder)
43 sipPoly.
coeff(i, j, 0) = sipA(i, j);
44 if (i < sipB.cols() && j < sipB.rows() && (i + j) <= sipOrder)
45 sipPoly.
coeff(i, j, 1) = sipB(i, j);
67 Eigen::Matrix2d cdMat = wcs->getCDMatrix();
69 cdTrans.
coeff(1, 0, 0) = cdMat(0, 0);
70 cdTrans.
coeff(0, 1, 0) = cdMat(0, 1);
71 cdTrans.
coeff(1, 0, 1) = cdMat(1, 0);
72 cdTrans.
coeff(0, 1, 1) = cdMat(1, 1);
81 double ra = wcsMeta->get<
double>(
"CRVAL1");
82 double dec = wcsMeta->get<
double>(
"CRVAL2");
94 const
bool noLowOrderSipTerms) {
96 afwGeom::Point2D crpix_lsst;
105 linPart.
invert().
apply(0., 0., crpix_lsst[0], crpix_lsst[1]);
110 if (noLowOrderSipTerms) {
111 Point ctmp =
Point(crpix_lsst[0], crpix_lsst[1]);
116 r->apply(0, 0, crpix_lsst[0], crpix_lsst[1]);
126 afwGeom::Point2D crval;
127 crval[0] = wcsTransfo.getTangentPoint().x;
128 crval[1] = wcsTransfo.getTangentPoint().y;
131 Eigen::Matrix2d cdMat;
132 cdMat(0, 0) = linPart.
coeff(1, 0, 0);
133 cdMat(0, 1) = linPart.
coeff(0, 1, 0);
134 cdMat(1, 0) = linPart.
coeff(1, 0, 1);
135 cdMat(1, 1) = linPart.
coeff(0, 1, 1);
137 if (!wcsTransfo.getCorr())
138 return std::make_shared<afwImg::TanWcs>(crval, crpix_lsst, cdMat);
162 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
163 "GtransfoToSip: could not invert the input wcs ");
170 Eigen::MatrixXd sipA(Eigen::MatrixXd::Zero(sipOrder + 1, sipOrder + 1));
171 Eigen::MatrixXd sipB(Eigen::MatrixXd::Zero(sipOrder + 1, sipOrder + 1));
172 for (
int i = 0; i <= sipOrder; ++i)
173 for (
int j = 0; j <= sipOrder - i; ++j) {
174 sipA(i, j) = sipPoly.
coeff(i, j, 0);
175 sipB(i, j) = sipPoly.
coeff(i, j, 1);
180 Eigen::MatrixXd sipAp(Eigen::MatrixXd::Zero(sipOrder + 1, sipOrder + 1));
181 Eigen::MatrixXd sipBp(Eigen::MatrixXd::Zero(sipOrder + 1, sipOrder + 1));
182 for (
int i = 0; i <= sipOrder; ++i)
183 for (
int j = 0; j <= sipOrder - i; ++j) {
184 sipAp(i, j) = sipPolyInv.
coeff(i, j, 0);
185 sipBp(i, j) = sipPolyInv.
coeff(i, j, 1);
188 return std::make_shared<afwImg::TanWcs>(crval, crpix_lsst, cdMat, sipA, sipB, sipAp, sipBp);
Implements the (forward) SIP distorsion scheme.
implements the linear transformations (6 real coefficients).
unsigned getDegree() const
returns degree
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
virtual GtransfoLin linearApproximation(const Point &where, const double step=0.01) const
linear (local) approximation.
Polynomial transformation class.
virtual std::unique_ptr< Gtransfo > inverseTransfo(const double precision, const Frame ®ion) const
returns an inverse transfo. Numerical if not overloaded.
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const
std::unique_ptr< GtransfoPoly > inversePolyTransfo(const Gtransfo &Direct, const Frame &frame, const double Prec)
approximates the inverse by a polynomial, up to required precision.
rectangle with sides parallel to axes.
boost::shared_ptr< lsst::afw::image::TanWcs > gtransfoToTanWcs(const lsst::jointcal::TanSipPix2RaDec wcsTransfo, const lsst::jointcal::Frame &ccdFrame, const bool noLowOrderSipTerms=false)
Transform the other way around.
just here to provide a specialized constructor, and fit.
GtransfoLin invert() const
returns the inverse: T1 = T2.invert();
std::shared_ptr< jointcal::GtransfoPoly > GtPoly_Ptr
TanSipPix2RaDec convertTanWcs(const std::shared_ptr< lsst::afw::image::TanWcs > wcs)
Transform an afw TanWcs into a Gtransfo.