LSSTApplications  16.0-10-g4f78f78+16,16.0-10-gc1446dd+42,16.0-11-g09ed895+1,16.0-13-g7649090,16.0-14-g0a28612+1,16.0-14-g6c7ed55+16,16.0-15-ga29f190+1,16.0-16-g89065d4+14,16.0-16-gd8e3590+16,16.0-16-ge6a35c8+6,16.0-17-g7e0e4ff+10,16.0-17-ga3d2e9f,16.0-19-gb830ed4e+16,16.0-2-g0febb12+21,16.0-2-g9d5294e+61,16.0-2-ga8830df+5,16.0-24-gc1c7f52+9,16.0-25-g07af9f2+1,16.0-3-ge00e371+21,16.0-36-g07840cb1,16.0-4-g18f3627+5,16.0-4-g5f3a788+20,16.0-4-ga3eb747+10,16.0-4-gabf74b7+16,16.0-4-gade8416+9,16.0-4-gb13d127+5,16.0-5-g6a53317+21,16.0-5-gb3f8a4b+74,16.0-5-gef99c9f+12,16.0-6-g9321be7+4,16.0-6-gcbc7b31+22,16.0-6-gf49912c+16,16.0-63-gae20905ba,16.0-7-gd2eeba5+31,16.0-8-g21fd5fe+16,16.0-8-g3a9f023+12,16.0-8-g4734f7a,16.0-9-g85d1a16+16,16.0-9-gf5c1f43,master-g07ce7b41a7,w.2018.48
LSSTDataManagementBasePackage
Public Member Functions | Protected Member Functions | Friends | List of all members
lsst::jointcal::GtransfoLin Class Reference

implements the linear transformations (6 real coefficients). More...

#include <Gtransfo.h>

Inheritance diagram for lsst::jointcal::GtransfoLin:
lsst::jointcal::GtransfoPoly lsst::jointcal::Gtransfo lsst::jointcal::GtransfoLinRot lsst::jointcal::GtransfoLinScale lsst::jointcal::GtransfoLinShift

Public Member Functions

 GtransfoLin ()
 the default constructor constructs the do-nothing transformation. More...
 
 GtransfoLin (GtransfoPoly const &gtransfoPoly)
 This triggers an exception if P.getOrder() != 1. More...
 
GtransfoLin operator* (GtransfoLin const &right) const
 enables to combine linear tranformations: T1=T2*T3 is legal. More...
 
GtransfoLin inverted () const
 returns the inverse: T1 = T2.inverted(); More...
 
void computeDerivative (Point const &where, GtransfoLin &derivative, const double step=0.01) const
 specialised analytic routine More...
 
GtransfoLin linearApproximation (Point const &where, const double step=0.01) const
 linear (local) approximation. More...
 
 GtransfoLin (const double ox, const double oy, const double aa11, const double aa12, const double aa21, const double aa22)
 Construct a GtransfoLin from parameters. More...
 
 GtransfoLin (GtransfoIdentity const &)
 Handy converter: More...
 
std::unique_ptr< Gtransfoclone () const
 returns a copy (allocated by new) of the transformation. More...
 
std::unique_ptr< GtransfoinverseTransfo (const double precision, const Frame &region) const
 returns an inverse transfo. Numerical if not overloaded. More...
 
double A11 () const
 
double A12 () const
 
double A21 () const
 
double A22 () const
 
double Dx () const
 
double Dy () const
 
unsigned getOrder () const
 Returns the polynomial order. More...
 
void apply (const double xIn, const double yIn, double &xOut, double &yOut) const override
 
void apply (Point const &in, Point &out) const
 applies the tranfo to in and writes into out. Is indeed virtual. More...
 
Point apply (Point const &in) const
 All these apply(..) shadow the virtual one in derived classes, unless one writes "using Gtransfo::apply". More...
 
Frame apply (Frame const &inputframe, bool inscribed) const
 Transform a bounding box, taking either the inscribed or circumscribed box. More...
 
virtual void transformPosAndErrors (const FatPoint &in, FatPoint &out) const override
 a mix of apply and Derivative More...
 
int getNpar () const override
 total number of parameters More...
 
void dump (std::ostream &stream=std::cout) const override
 print out of coefficients in a readable form. More...
 
double fit (StarMatchList const &starMatchList) override
 guess what More...
 
GtransfoPoly operator* (GtransfoPoly const &right) const
 Composition (internal stuff in quadruple precision) More...
 
GtransfoPoly operator+ (GtransfoPoly const &right) const
 Addition. More...
 
GtransfoPoly operator- (GtransfoPoly const &right) const
 Subtraction. More...
 
std::unique_ptr< GtransfocomposeAndReduce (GtransfoPoly const &right) const
 Return a reduced composition of newTransfo = this(right()), or nullptr if it cannot be reduced. More...
 
virtual std::unique_ptr< GtransfocomposeAndReduce (Gtransfo const &right) const
 Return a reduced composition of newTransfo = this(right()), or nullptr if it cannot be reduced. More...
 
double coeff (const unsigned powX, const unsigned powY, const unsigned whichCoord) const
 access to coefficients (read only) More...
 
double & coeff (const unsigned powX, const unsigned powY, const unsigned whichCoord)
 write access More...
 
double coeffOrZero (const unsigned powX, const unsigned powY, const unsigned whichCoord) const
 read access, zero if beyond order More...
 
double determinant () const
 
double paramRef (const int i) const override
 
double & paramRef (const int i) override
 
void paramDerivatives (Point const &where, double *dx, double *dy) const override
 Derivative w.r.t parameters. More...
 
std::shared_ptr< ast::MappingtoAstMap (jointcal::Frame const &domain) const override
 Create an equivalent AST mapping for this transformation, including an analytic inverse if possible. More...
 
void write (std::ostream &s) const override
 
void write (const std::string &fileName) const
 
void read (std::istream &s)
 
std::string __str__ ()
 
void transformStar (FatPoint &in) const
 allows to write MyTransfo(MyStar) More...
 
virtual double getJacobian (Point const &point) const
 returns the local jacobian. More...
 
virtual double getJacobian (const double x, const double y) const
 returns the local jacobian. More...
 
virtual void transformErrors (Point const &where, const double *vIn, double *vOut) const
 transform errors (represented as double[3] in order V(xx),V(yy),Cov(xy)) More...
 
void getParams (double *params) const
 params should be at least Npar() long More...
 
void offsetParams (Eigen::VectorXd const &delta)
 
virtual std::unique_ptr< GtransforoughInverse (const Frame &region) const
 Rough inverse. More...
 

Protected Member Functions

double & a11 ()
 
double & a12 ()
 
double & a21 ()
 
double & a22 ()
 
double & dx ()
 
double & dy ()
 

Friends

class Gtransfo
 
class GtransfoIdentity
 
class GtransfoPoly
 

Detailed Description

implements the linear transformations (6 real coefficients).

Definition at line 414 of file Gtransfo.h.

Constructor & Destructor Documentation

◆ GtransfoLin() [1/4]

lsst::jointcal::GtransfoLin::GtransfoLin ( )
inline

the default constructor constructs the do-nothing transformation.

Definition at line 419 of file Gtransfo.h.

419 : GtransfoPoly(1){};
friend class GtransfoPoly
Definition: Gtransfo.h:469

◆ GtransfoLin() [2/4]

lsst::jointcal::GtransfoLin::GtransfoLin ( GtransfoPoly const &  gtransfoPoly)
explicit

This triggers an exception if P.getOrder() != 1.

Definition at line 1172 of file Gtransfo.cc.

1172  : GtransfoPoly(1) {
1173  if (gtransfoPoly.getOrder() != 1)
1175  "Trying to build a GtransfoLin from a higher order transfo. Aborting. ");
1176  (GtransfoPoly &)(*this) = gtransfoPoly;
1177 }
friend class GtransfoPoly
Definition: Gtransfo.h:469
Reports invalid arguments.
Definition: Runtime.h:66

◆ GtransfoLin() [3/4]

lsst::jointcal::GtransfoLin::GtransfoLin ( const double  ox,
const double  oy,
const double  aa11,
const double  aa12,
const double  aa21,
const double  aa22 
)

Construct a GtransfoLin from parameters.

Definition at line 1161 of file Gtransfo.cc.

1163  : GtransfoPoly(1) {
1164  dx() = Dx;
1165  a11() = A11;
1166  a12() = A12;
1167  dy() = Dy;
1168  a21() = A21;
1169  a22() = A22;
1170 }
friend class GtransfoPoly
Definition: Gtransfo.h:469

◆ GtransfoLin() [4/4]

lsst::jointcal::GtransfoLin::GtransfoLin ( GtransfoIdentity const &  )
inline

Handy converter:

Definition at line 446 of file Gtransfo.h.

446 : GtransfoPoly(1){};
friend class GtransfoPoly
Definition: Gtransfo.h:469

Member Function Documentation

◆ __str__()

std::string lsst::jointcal::Gtransfo::__str__ ( )
inlineinherited

Definition at line 94 of file Gtransfo.h.

94  {
96  dump(s);
97  return s.str();
98  }
T str(T... args)
solver_t * s
virtual void dump(std::ostream &stream=std::cout) const =0
dumps the transfo coefficients to stream.

◆ A11()

double lsst::jointcal::GtransfoLin::A11 ( ) const
inline

Definition at line 452 of file Gtransfo.h.

452 { return coeff(1, 0, 0); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ a11()

double& lsst::jointcal::GtransfoLin::a11 ( )
inlineprotected

Definition at line 460 of file Gtransfo.h.

460 { return coeff(1, 0, 0); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ A12()

double lsst::jointcal::GtransfoLin::A12 ( ) const
inline

Definition at line 453 of file Gtransfo.h.

453 { return coeff(0, 1, 0); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ a12()

double& lsst::jointcal::GtransfoLin::a12 ( )
inlineprotected

Definition at line 461 of file Gtransfo.h.

461 { return coeff(0, 1, 0); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ A21()

double lsst::jointcal::GtransfoLin::A21 ( ) const
inline

Definition at line 454 of file Gtransfo.h.

454 { return coeff(1, 0, 1); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ a21()

double& lsst::jointcal::GtransfoLin::a21 ( )
inlineprotected

Definition at line 462 of file Gtransfo.h.

462 { return coeff(1, 0, 1); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ A22()

double lsst::jointcal::GtransfoLin::A22 ( ) const
inline

Definition at line 455 of file Gtransfo.h.

455 { return coeff(0, 1, 1); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ a22()

double& lsst::jointcal::GtransfoLin::a22 ( )
inlineprotected

Definition at line 463 of file Gtransfo.h.

463 { return coeff(0, 1, 1); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ apply() [1/4]

void lsst::jointcal::Gtransfo::apply ( Point const &  in,
Point out 
) const
inlineinherited

applies the tranfo to in and writes into out. Is indeed virtual.

Definition at line 71 of file Gtransfo.h.

71 { apply(in.x, in.y, out.x, out.y); }
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ apply() [2/4]

Point lsst::jointcal::Gtransfo::apply ( Point const &  in) const
inlineinherited

All these apply(..) shadow the virtual one in derived classes, unless one writes "using Gtransfo::apply".

Definition at line 75 of file Gtransfo.h.

75  {
76  double xout, yout;
77  apply(in.x, in.y, xout, yout);
78  return Point(xout, yout);
79  }
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ apply() [3/4]

Frame lsst::jointcal::Gtransfo::apply ( Frame const &  inputframe,
bool  inscribed 
) const
inherited

Transform a bounding box, taking either the inscribed or circumscribed box.

Parameters
[in]inputframeThe frame to be transformed.
[in]inscribedReturn the inscribed (true) or circumscribed (false) box.
Returns
The transformed frame.

Definition at line 74 of file Gtransfo.cc.

74  {
75  // 2 opposite corners
76  double xtmin1, xtmax1, ytmin1, ytmax1;
77  apply(inputframe.xMin, inputframe.yMin, xtmin1, ytmin1);
78  apply(inputframe.xMax, inputframe.yMax, xtmax1, ytmax1);
79  Frame fr1(std::min(xtmin1, xtmax1), std::min(ytmin1, ytmax1), std::max(xtmin1, xtmax1),
80  std::max(ytmin1, ytmax1));
81  // 2 other corners
82  double xtmin2, xtmax2, ytmin2, ytmax2;
83  apply(inputframe.xMin, inputframe.yMax, xtmin2, ytmax2);
84  apply(inputframe.xMax, inputframe.yMin, xtmax2, ytmin2);
85  Frame fr2(std::min(xtmin2, xtmax2), std::min(ytmin2, ytmax2), std::max(xtmin2, xtmax2),
86  std::max(ytmin2, ytmax2));
87 
88  if (inscribed) return fr1 * fr2;
89  return fr1 + fr2;
90 }
T min(T... args)
T max(T... args)
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ apply() [4/4]

void lsst::jointcal::GtransfoPoly::apply ( const double  xIn,
const double  yIn,
double &  xOut,
double &  yOut 
) const
overridevirtualinherited

Implements lsst::jointcal::Gtransfo.

Definition at line 546 of file Gtransfo.cc.

546  {
547  /*
548  This routine computes the monomials only once for both
549  polynomials. This is why GtransfoPoly does not use an auxilary
550  class (such as PolyXY) to handle each polynomial.
551 
552  The code works even if &xIn == &xOut (or &yIn == &yOut)
553  It uses Variable Length Allocation (VLA) rather than a vector<double>
554  because allocating the later costs about 50 ns. All VLA uses are tagged.
555  */
556  double monomials[_nterms]; // this is VLA, which is (perhaps) not casher C++
557  computeMonomials(xIn, yIn, monomials);
558 
559  xOut = 0;
560  yOut = 0;
561  const double *c = &_coeffs[0];
562  const double *pm = &monomials[0];
563  // the ordering of the coefficients and the monomials are identical.
564  for (int k = _nterms; k--;) xOut += (*(pm++)) * (*(c++));
565  pm = &monomials[0];
566  for (int k = _nterms; k--;) yOut += (*(pm++)) * (*(c++));
567 }

◆ clone()

std::unique_ptr<Gtransfo> lsst::jointcal::GtransfoLin::clone ( ) const
inlinevirtual

returns a copy (allocated by new) of the transformation.

Reimplemented from lsst::jointcal::GtransfoPoly.

Definition at line 448 of file Gtransfo.h.

448 { return std::unique_ptr<Gtransfo>(new GtransfoLin(*this)); }
GtransfoLin()
the default constructor constructs the do-nothing transformation.
Definition: Gtransfo.h:419
STL class.

◆ coeff() [1/2]

double lsst::jointcal::GtransfoPoly::coeff ( const unsigned  powX,
const unsigned  powY,
const unsigned  whichCoord 
) const
inherited

access to coefficients (read only)

Definition at line 711 of file Gtransfo.cc.

711  {
712  assert((degX + degY <= _order) && whichCoord < 2);
713  /* this assertion above is enough to ensure that the index used just
714  below is within bounds since the reserved length is
715  2*_nterms=(order+1)*(order+2) */
716  return _coeffs[(degX + degY) * (degX + degY + 1) / 2 + degY + whichCoord * _nterms];
717 }

◆ coeff() [2/2]

double & lsst::jointcal::GtransfoPoly::coeff ( const unsigned  powX,
const unsigned  powY,
const unsigned  whichCoord 
)
inherited

write access

Definition at line 719 of file Gtransfo.cc.

719  {
720  assert((degX + degY <= _order) && whichCoord < 2);
721  return _coeffs[(degX + degY) * (degX + degY + 1) / 2 + degY + whichCoord * _nterms];
722 }

◆ coeffOrZero()

double lsst::jointcal::GtransfoPoly::coeffOrZero ( const unsigned  powX,
const unsigned  powY,
const unsigned  whichCoord 
) const
inherited

read access, zero if beyond order

Definition at line 724 of file Gtransfo.cc.

724  {
725  // assert((degX+degY<=order) && whichCoord<2);
726  assert(whichCoord < 2);
727  if (degX + degY <= _order)
728  return _coeffs[(degX + degY) * (degX + degY + 1) / 2 + degY + whichCoord * _nterms];
729  return 0;
730 }

◆ composeAndReduce() [1/2]

std::unique_ptr< Gtransfo > lsst::jointcal::Gtransfo::composeAndReduce ( Gtransfo const &  right) const
virtualinherited

Return a reduced composition of newTransfo = this(right()), or nullptr if it cannot be reduced.

"Reduced" in this context means that they are capable of being merged into a single transform, for example, for two polynomials:

\[ f(x) = 1 + x^2, g(x) = -1 + 3x \]

we would have h = f.composeAndReduce(g) == 2 - 6x + 9x^2.

To be overloaded by derived classes if they can properly reduce the composition.

Parameters
rightThe transform to apply first.
Returns
The new reduced and composed gtransfo, or nullptr if no such reduction is possible.

Reimplemented in lsst::jointcal::GtransfoIdentity.

Definition at line 92 of file Gtransfo.cc.

93  { // by default no way to compose
94  return std::unique_ptr<Gtransfo>(nullptr);
95 }
STL class.

◆ composeAndReduce() [2/2]

std::unique_ptr< Gtransfo > lsst::jointcal::GtransfoPoly::composeAndReduce ( GtransfoPoly const &  right) const
inherited

Return a reduced composition of newTransfo = this(right()), or nullptr if it cannot be reduced.

"Reduced" in this context means that they are capable of being merged into a single transform, for example, for two polynomials:

\[ f(x) = 1 + x^2, g(x) = -1 + 3x \]

we would have h = f.composeAndReduce(g) == 2 - 6x + 9x^2.

To be overloaded by derived classes if they can properly reduce the composition.

Parameters
rightThe transform to apply first.
Returns
The new reduced and composed gtransfo, or nullptr if no such reduction is possible.

Definition at line 898 of file Gtransfo.cc.

898  {
899  if (getOrder() == 1 && right.getOrder() == 1)
900  return std::make_unique<GtransfoLin>((*this) * (right)); // does the composition
901  else
902  return std::make_unique<GtransfoPoly>((*this) * (right)); // does the composition
903 }
T right(T... args)
unsigned getOrder() const
Returns the polynomial order.
Definition: Gtransfo.h:302

◆ computeDerivative()

void lsst::jointcal::GtransfoLin::computeDerivative ( Point const &  where,
GtransfoLin derivative,
const double  step = 0.01 
) const
virtual

specialised analytic routine

Reimplemented from lsst::jointcal::GtransfoPoly.

Definition at line 1194 of file Gtransfo.cc.

1194  {
1195  derivative = *this;
1196  derivative.coeff(0, 0, 0) = 0;
1197  derivative.coeff(0, 0, 1) = 0;
1198 }

◆ determinant()

double lsst::jointcal::GtransfoPoly::determinant ( ) const
inherited

Definition at line 782 of file Gtransfo.cc.

782  {
783  if (_order >= 1) return coeff(1, 0, 0) * coeff(0, 1, 1) - coeff(0, 1, 0) * coeff(1, 0, 1);
784  return 0;
785 }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ dump()

void lsst::jointcal::GtransfoPoly::dump ( std::ostream stream = std::cout) const
overridevirtualinherited

print out of coefficients in a readable form.

Implements lsst::jointcal::Gtransfo.

Definition at line 763 of file Gtransfo.cc.

763  {
764  auto oldPrecision = stream.precision();
765  stream.precision(12);
766  for (unsigned ic = 0; ic < 2; ++ic) {
767  if (ic == 0)
768  stream << "newx = ";
769  else
770  stream << "newy = ";
771  for (unsigned p = 0; p <= _order; ++p)
772  for (unsigned py = 0; py <= p; ++py) {
773  if (p + py != 0) stream << " + ";
774  stream << coeff(p - py, py, ic) << monomialString(p - py, py);
775  }
776  stream << endl;
777  }
778  if (_order > 0) stream << " Linear determinant = " << determinant() << endl;
779  stream.precision(oldPrecision);
780 }
T endl(T... args)
T precision(T... args)
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711
double determinant() const
Definition: Gtransfo.cc:782

◆ Dx()

double lsst::jointcal::GtransfoLin::Dx ( ) const
inline

Definition at line 456 of file Gtransfo.h.

456 { return coeff(0, 0, 0); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ dx()

double& lsst::jointcal::GtransfoLin::dx ( )
inlineprotected

Definition at line 464 of file Gtransfo.h.

464 { return coeff(0, 0, 0); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ Dy()

double lsst::jointcal::GtransfoLin::Dy ( ) const
inline

Definition at line 457 of file Gtransfo.h.

457 { return coeff(0, 0, 1); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ dy()

double& lsst::jointcal::GtransfoLin::dy ( )
inlineprotected

Definition at line 465 of file Gtransfo.h.

465 { return coeff(0, 0, 1); }
double coeff(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
access to coefficients (read only)
Definition: Gtransfo.cc:711

◆ fit()

double lsst::jointcal::GtransfoPoly::fit ( StarMatchList const &  starMatchList)
overridevirtualinherited

guess what

Implements lsst::jointcal::Gtransfo.

Reimplemented in lsst::jointcal::GtransfoLinRot, and lsst::jointcal::GtransfoLinShift.

Definition at line 880 of file Gtransfo.cc.

880  {
881  if (starMatchList.size() < _nterms) {
882  LOGLS_FATAL(_log, "GtransfoPoly::fit trying to fit a polynomial transfo of order "
883  << _order << " with only " << starMatchList.size() << " matches.");
884  return -1;
885  }
886 
887  GtransfoPoly conditionner = shiftAndNormalize(starMatchList);
888 
889  computeFit(starMatchList, conditionner, false); // get a rough solution
890  computeFit(starMatchList, conditionner, true); // weight with it
891  double chi2 = computeFit(starMatchList, conditionner, true); // once more
892 
893  (*this) = (*this) * conditionner;
894  if (starMatchList.size() == _nterms) return 0;
895  return chi2;
896 }
GtransfoPoly(const unsigned order=1)
Default transfo : identity for all orders (>=1 ).
Definition: Gtransfo.cc:447
#define LOGLS_FATAL(logger, message)
Log a fatal-level message using an iostream-based interface.
Definition: Log.h:697

◆ getJacobian() [1/2]

virtual double lsst::jointcal::Gtransfo::getJacobian ( Point const &  point) const
inlinevirtualinherited

returns the local jacobian.

Definition at line 111 of file Gtransfo.h.

111 { return getJacobian(point.x, point.y); }
virtual double getJacobian(Point const &point) const
returns the local jacobian.
Definition: Gtransfo.h:111

◆ getJacobian() [2/2]

double lsst::jointcal::Gtransfo::getJacobian ( const double  x,
const double  y 
) const
virtualinherited

returns the local jacobian.

Definition at line 97 of file Gtransfo.cc.

97  {
98  double x2, y2;
99  double eps = x * 0.01;
100  if (eps == 0) eps = 0.01;
101  apply(x, y, x2, y2);
102  double dxdx, dydx;
103  apply(x + eps, y, dxdx, dydx);
104  dxdx -= x2;
105  dydx -= y2;
106  double dxdy, dydy;
107  apply(x, y + eps, dxdy, dydy);
108  dxdy -= x2;
109  dydy -= y2;
110  return ((dxdx * dydy - dxdy * dydx) / (eps * eps));
111 }
int y
Definition: SpanSet.cc:49
double x
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ getNpar()

int lsst::jointcal::GtransfoPoly::getNpar ( ) const
inlineoverridevirtualinherited

total number of parameters

Reimplemented from lsst::jointcal::Gtransfo.

Reimplemented in lsst::jointcal::GtransfoLinScale, lsst::jointcal::GtransfoLinRot, and lsst::jointcal::GtransfoLinShift.

Definition at line 316 of file Gtransfo.h.

316 { return 2 * _nterms; }

◆ getOrder()

unsigned lsst::jointcal::GtransfoPoly::getOrder ( ) const
inlineinherited

Returns the polynomial order.

Definition at line 302 of file Gtransfo.h.

302 { return _order; }

◆ getParams()

void lsst::jointcal::Gtransfo::getParams ( double *  params) const
inherited

params should be at least Npar() long

Definition at line 210 of file Gtransfo.cc.

210  {
211  int npar = getNpar();
212  for (int i = 0; i < npar; ++i) params[i] = paramRef(i);
213 }
virtual int getNpar() const
returns the number of parameters (to compute chi2&#39;s)
Definition: Gtransfo.h:180
virtual double paramRef(const int i) const
Definition: Gtransfo.cc:220

◆ inverseTransfo()

std::unique_ptr< Gtransfo > lsst::jointcal::GtransfoLin::inverseTransfo ( const double  precision,
const Frame region 
) const
virtual

returns an inverse transfo. Numerical if not overloaded.

precision and region refer to the "input" side of this, and hence to the output side of the returned Gtransfo.

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 1228 of file Gtransfo.cc.

1228  {
1230 }
GtransfoLin inverted() const
returns the inverse: T1 = T2.inverted();
Definition: Gtransfo.cc:1202
GtransfoLin()
the default constructor constructs the do-nothing transformation.
Definition: Gtransfo.h:419
STL class.

◆ inverted()

GtransfoLin lsst::jointcal::GtransfoLin::inverted ( ) const

returns the inverse: T1 = T2.inverted();

Definition at line 1202 of file Gtransfo.cc.

1202  {
1203  //
1204  // (T1,M1) * (T2,M2) = 1 i.e (0,1) implies
1205  // T1 = -M1 * T2
1206  // M1 = M2^(-1)
1207  //
1208 
1209  double a11 = A11();
1210  double a12 = A12();
1211  double a21 = A21();
1212  double a22 = A22();
1213  double d = (a11 * a22 - a12 * a21);
1214  if (d == 0) {
1215  LOGL_FATAL(_log,
1216  "GtransfoLin::invert singular transformation: transfo contents will be dumped to stderr.");
1217  dump(cerr);
1218  }
1219 
1220  GtransfoLin result(0, 0, a22 / d, -a12 / d, -a21 / d, a11 / d);
1221  double rdx, rdy;
1222  result.apply(Dx(), Dy(), rdx, rdy);
1223  result.dx() = -rdx;
1224  result.dy() = -rdy;
1225  return result;
1226 }
py::object result
Definition: schema.cc:284
GtransfoLin()
the default constructor constructs the do-nothing transformation.
Definition: Gtransfo.h:419
#define LOGL_FATAL(logger, message...)
Log a fatal-level message using a varargs/printf style interface.
Definition: Log.h:577
void dump(std::ostream &stream=std::cout) const override
print out of coefficients in a readable form.
Definition: Gtransfo.cc:763

◆ linearApproximation()

GtransfoLin lsst::jointcal::GtransfoLin::linearApproximation ( Point const &  where,
const double  step = 0.01 
) const
virtual

linear (local) approximation.

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 1200 of file Gtransfo.cc.

1200 { return *this; }

◆ offsetParams()

void lsst::jointcal::Gtransfo::offsetParams ( Eigen::VectorXd const &  delta)
inherited

Definition at line 215 of file Gtransfo.cc.

215  {
216  int npar = getNpar();
217  for (int i = 0; i < npar; ++i) paramRef(i) += delta[i];
218 }
virtual int getNpar() const
returns the number of parameters (to compute chi2&#39;s)
Definition: Gtransfo.h:180
virtual double paramRef(const int i) const
Definition: Gtransfo.cc:220

◆ operator*() [1/2]

GtransfoPoly lsst::jointcal::GtransfoPoly::operator* ( GtransfoPoly const &  right) const
inherited

Composition (internal stuff in quadruple precision)

Definition at line 1003 of file Gtransfo.cc.

1003  {
1004  // split each transfo into 2d polynomials
1005  PolyXY plx(*this, 0);
1006  PolyXY ply(*this, 1);
1007  PolyXY prx(right, 0);
1008  PolyXY pry(right, 1);
1009 
1010  // compute the compositions
1011  PolyXY rx(composition(plx, prx, pry));
1012  PolyXY ry(composition(ply, prx, pry));
1013 
1014  // copy the results the hard way.
1015  GtransfoPoly result(_order * right._order);
1016  for (unsigned px = 0; px <= result._order; ++px)
1017  for (unsigned py = 0; py <= result._order - px; ++py) {
1018  result.coeff(px, py, 0) = rx.coeff(px, py);
1019  result.coeff(px, py, 1) = ry.coeff(px, py);
1020  }
1021  return result;
1022 }
GtransfoPoly(const unsigned order=1)
Default transfo : identity for all orders (>=1 ).
Definition: Gtransfo.cc:447
py::object result
Definition: schema.cc:284
T right(T... args)

◆ operator*() [2/2]

GtransfoLin lsst::jointcal::GtransfoLin::operator* ( GtransfoLin const &  right) const

enables to combine linear tranformations: T1=T2*T3 is legal.

Definition at line 1179 of file Gtransfo.cc.

1179  {
1180  // There is a general routine in GtransfoPoly that would do the job:
1181  // return GtransfoLin(GtransfoPoly::operator*(right));
1182  // however, we are using this composition of linear stuff heavily in
1183  // Gtransfo::linearApproximation, itself used in inverseTransfo::apply.
1184  // So, for sake of efficiency, and since it is easy, we take a shortcut:
1186  apply(right.Dx(), right.Dy(), result.dx(), result.dy());
1187  result.a11() = A11() * right.A11() + A12() * right.A21();
1188  result.a12() = A11() * right.A12() + A12() * right.A22();
1189  result.a21() = A21() * right.A11() + A22() * right.A21();
1190  result.a22() = A21() * right.A12() + A22() * right.A22();
1191  return result;
1192 }
py::object result
Definition: schema.cc:284
T right(T... args)
GtransfoLin()
the default constructor constructs the do-nothing transformation.
Definition: Gtransfo.h:419
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const override
Definition: Gtransfo.cc:546

◆ operator+()

GtransfoPoly lsst::jointcal::GtransfoPoly::operator+ ( GtransfoPoly const &  right) const
inherited

Addition.

Definition at line 1024 of file Gtransfo.cc.

1024  {
1025  if (_order >= right._order) {
1026  GtransfoPoly res(*this);
1027  for (unsigned i = 0; i <= right._order; ++i)
1028  for (unsigned j = 0; j <= right._order - i; ++j) {
1029  res.coeff(i, j, 0) += right.coeff(i, j, 0);
1030  res.coeff(i, j, 1) += right.coeff(i, j, 1);
1031  }
1032  return res;
1033  } else
1034  return (right + (*this));
1035 }
GtransfoPoly(const unsigned order=1)
Default transfo : identity for all orders (>=1 ).
Definition: Gtransfo.cc:447
T right(T... args)

◆ operator-()

GtransfoPoly lsst::jointcal::GtransfoPoly::operator- ( GtransfoPoly const &  right) const
inherited

Subtraction.

Definition at line 1037 of file Gtransfo.cc.

1037  {
1038  GtransfoPoly res(std::max(_order, right._order));
1039  for (unsigned i = 0; i <= res._order; ++i)
1040  for (unsigned j = 0; j <= res._order - i; ++j) {
1041  res.coeff(i, j, 0) = coeffOrZero(i, j, 0) - right.coeffOrZero(i, j, 0);
1042  res.coeff(i, j, 1) = coeffOrZero(i, j, 1) - right.coeffOrZero(i, j, 1);
1043  }
1044  return res;
1045 }
GtransfoPoly(const unsigned order=1)
Default transfo : identity for all orders (>=1 ).
Definition: Gtransfo.cc:447
T right(T... args)
double coeffOrZero(const unsigned powX, const unsigned powY, const unsigned whichCoord) const
read access, zero if beyond order
Definition: Gtransfo.cc:724
T max(T... args)

◆ paramDerivatives()

void lsst::jointcal::GtransfoPoly::paramDerivatives ( Point const &  where,
double *  dx,
double *  dy 
) const
overridevirtualinherited

Derivative w.r.t parameters.

Derivatives should be al least 2*NPar long. first Npar, for x, last Npar for y.

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 743 of file Gtransfo.cc.

744  { /* first half : dxout/dpar, second half : dyout/dpar */
745  computeMonomials(where.x, where.y, dx);
746  for (unsigned k = 0; k < _nterms; ++k) {
747  dy[_nterms + k] = dx[k];
748  dx[_nterms + k] = dy[k] = 0;
749  }
750 }

◆ paramRef() [1/2]

double lsst::jointcal::GtransfoPoly::paramRef ( const int  i) const
overridevirtualinherited

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 733 of file Gtransfo.cc.

733  {
734  assert(unsigned(i) < 2 * _nterms);
735  return _coeffs[i];
736 }

◆ paramRef() [2/2]

double & lsst::jointcal::GtransfoPoly::paramRef ( const int  i)
overridevirtualinherited

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 738 of file Gtransfo.cc.

738  {
739  assert(unsigned(i) < 2 * _nterms);
740  return _coeffs[i];
741 }

◆ read()

void lsst::jointcal::GtransfoPoly::read ( std::istream s)
inherited

Definition at line 1062 of file Gtransfo.cc.

1062  {
1063  int format;
1064  s >> format;
1065  if (format != 1)
1066  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, " GtransfoPoly::read : format is not 1 ");
1067 
1068  string order;
1069  s >> order >> _order;
1070  if (order != "order")
1071  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
1072  " GtransfoPoly::read : expecting \"order\" and found " + order);
1073  setOrder(_order);
1074  for (unsigned k = 0; k < 2 * _nterms; ++k) s >> _coeffs[k];
1075 }
void setOrder(const unsigned order)
Sets the polynomial order (the highest sum of exponents of the largest monomial). ...
Definition: Gtransfo.cc:525
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:129
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

◆ roughInverse()

std::unique_ptr< Gtransfo > lsst::jointcal::Gtransfo::roughInverse ( const Frame region) const
virtualinherited

Rough inverse.

Stored by the numerical inverter to guess starting point for the trials. Just here to enable overloading.

Reimplemented in lsst::jointcal::TanRaDecToPixel, lsst::jointcal::TanPixelToRaDec, and lsst::jointcal::GtransfoInverse.

Definition at line 190 of file Gtransfo.cc.

190  {
191  // "in" and "out" refer to the inverse direction.
192  Point centerOut = region.getCenter();
193  Point centerIn = apply(centerOut);
194  GtransfoLin der;
195  computeDerivative(centerOut, der, std::sqrt(region.getArea()) / 5.);
196  der = der.inverted();
197  der = GtransfoLinShift(centerOut.x, centerOut.y) * der * GtransfoLinShift(-centerIn.x, -centerIn.y);
198  return std::unique_ptr<Gtransfo>(new GtransfoLin(der));
199 }
virtual void computeDerivative(Point const &where, GtransfoLin &derivative, const double step=0.01) const
Computes the local Derivative of a transfo, w.r.t.
Definition: Gtransfo.cc:116
STL class.
T sqrt(T... args)
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ toAstMap()

std::shared_ptr< ast::Mapping > lsst::jointcal::GtransfoPoly::toAstMap ( jointcal::Frame const &  domain) const
overridevirtualinherited

Create an equivalent AST mapping for this transformation, including an analytic inverse if possible.

Parameters
domainThe domain of the transfo, to help find an inverse.
Returns
An AST Mapping that represents this transformation.

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 1047 of file Gtransfo.cc.

1047  {
1048  auto inverse = inversePolyTransfo(*this, domain, 1e-7, _order + 2, 100);
1049  return std::make_shared<ast::PolyMap>(toAstPolyMapCoefficients(), inverse->toAstPolyMapCoefficients());
1050 }
std::shared_ptr< GtransfoPoly > inversePolyTransfo(Gtransfo const &forward, Frame const &domain, double const precision, int const maxOrder=9, unsigned const nSteps=50)
Approximate the inverse by a polynomial, to some precision.
Definition: Gtransfo.cc:1096

◆ transformErrors()

void lsst::jointcal::Gtransfo::transformErrors ( Point const &  where,
const double *  vIn,
double *  vOut 
) const
virtualinherited

transform errors (represented as double[3] in order V(xx),V(yy),Cov(xy))

Definition at line 157 of file Gtransfo.cc.

157  {
158  GtransfoLin der;
159  computeDerivative(where, der, 0.01);
160  double a11 = der.A11();
161  double a22 = der.A22();
162  double a21 = der.A21();
163  double a12 = der.A12();
164 
165  /* (a11 a12) (vxx vxy)
166  M = ( ) and V = ( )
167  (a21 a22) (xvy vyy)
168 
169  Vxx = Vin[0], vyy = Vin[1], Vxy = Vin[2];
170  we want to compute M*V*tp(M)
171  A lin alg light package would be perfect...
172  */
173  int xx = 0;
174  int yy = 1;
175  int xy = 2;
176  // M*V :
177 
178  double b11 = a11 * vIn[xx] + a12 * vIn[xy];
179  double b22 = a21 * vIn[xy] + a22 * vIn[yy];
180  double b12 = a11 * vIn[xy] + a12 * vIn[yy];
181  double b21 = a21 * vIn[xx] + a22 * vIn[xy];
182 
183  // (M*V) * tp(M)
184 
185  vOut[xx] = b11 * a11 + b12 * a12;
186  vOut[xy] = b11 * a21 + b12 * a22;
187  vOut[yy] = b21 * a21 + b22 * a22;
188 }
virtual void computeDerivative(Point const &where, GtransfoLin &derivative, const double step=0.01) const
Computes the local Derivative of a transfo, w.r.t.
Definition: Gtransfo.cc:116

◆ transformPosAndErrors()

void lsst::jointcal::GtransfoPoly::transformPosAndErrors ( const FatPoint in,
FatPoint out 
) const
overridevirtualinherited

a mix of apply and Derivative

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 627 of file Gtransfo.cc.

627  {
628  /*
629  The results from this routine were compared to what comes out
630  from apply and transformErrors. The Derivative routine was
631  checked against numerical derivatives from
632  Gtransfo::Derivative. (P.A dec 2009).
633 
634  This routine could be made much simpler by calling apply and
635  Derivative (i.e. you just suppress it, and the fallback is the
636  generic version in Gtransfo). BTW, I checked that both routines
637  provide the same result. This version is however faster
638  (monomials get recycled).
639  */
640  double monomials[_nterms]; // VLA
641 
642  FatPoint res; // to store the result, because nothing forbids &in == &out.
643 
644  double dermx[2 * _nterms]; // monomials for derivative w.r.t. x (VLA)
645  double *dermy = dermx + _nterms; // same for y
646  double xin = in.x;
647  double yin = in.y;
648 
649  double xx = 1;
650  double xxm1 = 1; // xx^(ix-1)
651  for (unsigned ix = 0; ix <= _order; ++ix) {
652  unsigned k = (ix) * (ix + 1) / 2;
653  // iy = 0
654  dermx[k] = ix * xxm1;
655  dermy[k] = 0;
656  monomials[k] = xx;
657  k += ix + 2;
658  double yy = yin;
659  double yym1 = 1; // yy^(iy-1)
660  for (unsigned iy = 1; iy <= _order - ix; ++iy) {
661  monomials[k] = xx * yy;
662  dermx[k] = ix * xxm1 * yy;
663  dermy[k] = iy * xx * yym1;
664  yym1 *= yin;
665  yy *= yin;
666  k += ix + iy + 2;
667  }
668  xx *= xin;
669  if (ix >= 1) xxm1 *= xin;
670  }
671 
672  // output position
673  double xout = 0, yout = 0;
674  const double *c = &_coeffs[0];
675  const double *pm = &monomials[0];
676  for (int k = _nterms; k--;) xout += (*(pm++)) * (*(c++));
677  pm = &monomials[0];
678  for (int k = _nterms; k--;) yout += (*(pm++)) * (*(c++));
679  res.x = xout;
680  res.y = yout;
681 
682  // derivatives
683  c = &_coeffs[0];
684  const double *mx = &dermx[0];
685  const double *my = &dermy[0];
686  double a11 = 0, a12 = 0;
687  for (int k = _nterms; k--;) {
688  a11 += (*(mx++)) * (*c);
689  a12 += (*(my++)) * (*(c++));
690  }
691 
692  double a21 = 0, a22 = 0;
693  mx = &dermx[0];
694  my = &dermy[0];
695  for (int k = _nterms; k--;) {
696  a21 += (*(mx++)) * (*c);
697  a22 += (*(my++)) * (*(c++));
698  }
699 
700  // output co-variance
701  res.vx = a11 * (a11 * in.vx + 2 * a12 * in.vxy) + a12 * a12 * in.vy;
702  res.vy = a21 * a21 * in.vx + a22 * a22 * in.vy + 2. * a21 * a22 * in.vxy;
703  res.vxy = a21 * a11 * in.vx + a22 * a12 * in.vy + (a21 * a12 + a11 * a22) * in.vxy;
704  out = res;
705 }

◆ transformStar()

void lsst::jointcal::Gtransfo::transformStar ( FatPoint in) const
inlineinherited

allows to write MyTransfo(MyStar)

Definition at line 108 of file Gtransfo.h.

108 { transformPosAndErrors(in, in); }
virtual void transformPosAndErrors(const FatPoint &in, FatPoint &out) const
Definition: Gtransfo.cc:140

◆ write() [1/2]

void lsst::jointcal::Gtransfo::write ( const std::string fileName) const
inherited

Definition at line 239 of file Gtransfo.cc.

239  {
240  ofstream s(fileName.c_str());
241  write(s);
242  bool ok = !s.fail();
243  s.close();
244  if (!ok)
245  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
246  "Gtransfo::write, something went wrong for file " + fileName);
247 }
void write(const std::string &fileName) const
Definition: Gtransfo.cc:239
STL class.
solver_t * s
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
T c_str(T... args)

◆ write() [2/2]

void lsst::jointcal::GtransfoPoly::write ( std::ostream s) const
overridevirtualinherited

Reimplemented from lsst::jointcal::Gtransfo.

Definition at line 1052 of file Gtransfo.cc.

1052  {
1053  s << " GtransfoPoly 1" << endl;
1054  s << "order " << _order << endl;
1055  int oldprec = s.precision();
1056  s << setprecision(12);
1057  for (unsigned k = 0; k < 2 * _nterms; ++k) s << _coeffs[k] << ' ';
1058  s << endl;
1059  s << setprecision(oldprec);
1060 }
T endl(T... args)
T precision(T... args)
T setprecision(T... args)

Friends And Related Function Documentation

◆ Gtransfo

friend class Gtransfo
friend

Definition at line 467 of file Gtransfo.h.

◆ GtransfoIdentity

friend class GtransfoIdentity
friend

Definition at line 468 of file Gtransfo.h.

◆ GtransfoPoly

friend class GtransfoPoly
friend

Definition at line 469 of file Gtransfo.h.


The documentation for this class was generated from the following files: