LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Public Member Functions | Protected Member Functions | Friends | List of all members
lsst::jointcal::AstrometryTransformLinear Class Reference

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

#include <AstrometryTransform.h>

Inheritance diagram for lsst::jointcal::AstrometryTransformLinear:
lsst::jointcal::AstrometryTransformPolynomial lsst::jointcal::AstrometryTransform lsst::jointcal::AstrometryTransformLinearRot lsst::jointcal::AstrometryTransformLinearScale lsst::jointcal::AstrometryTransformLinearShift

Public Member Functions

 AstrometryTransformLinear ()
 the default constructor constructs the do-nothing transformation. More...
 
 AstrometryTransformLinear (AstrometryTransformPolynomial const &transform)
 This triggers an exception if P.getOrder() != 1. More...
 
AstrometryTransformLinear operator* (AstrometryTransformLinear const &right) const
 enables to combine linear tranformations: T1=T2*T3 is legal. More...
 
AstrometryTransformLinear inverted () const
 returns the inverse: T1 = T2.inverted(); More...
 
void computeDerivative (Point const &where, AstrometryTransformLinear &derivative, const double step=0.01) const
 specialised analytic routine More...
 
AstrometryTransformLinear linearApproximation (Point const &where, const double step=0.01) const
 linear (local) approximation. More...
 
 AstrometryTransformLinear (const double ox, const double oy, const double aa11, const double aa12, const double aa21, const double aa22)
 Construct a AstrometryTransformLinear from parameters. More...
 
 AstrometryTransformLinear (AstrometryTransformIdentity const &)
 Handy converter: More...
 
std::unique_ptr< AstrometryTransformclone () const
 returns a copy (allocated by new) of the transformation. More...
 
std::unique_ptr< AstrometryTransforminverseTransform (const double precision, const Frame &region) const
 returns an inverse transform. Numerical if not overloaded. More...
 
double A11 () const
 
double A12 () const
 
double A21 () const
 
double A22 () const
 
double Dx () const
 
double Dy () const
 
std::size_t 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 AstrometryTransform::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...
 
std::size_t 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...
 
AstrometryTransformPolynomial operator* (AstrometryTransformPolynomial const &right) const
 Composition (internal stuff in quadruple precision) More...
 
AstrometryTransformPolynomial operator+ (AstrometryTransformPolynomial const &right) const
 Addition. More...
 
AstrometryTransformPolynomial operator- (AstrometryTransformPolynomial const &right) const
 Subtraction. More...
 
std::unique_ptr< AstrometryTransformcomposeAndReduce (AstrometryTransformPolynomial const &right) const
 Return a reduced composition of newTransform = this(right()), or nullptr if it cannot be reduced. More...
 
virtual std::unique_ptr< AstrometryTransformcomposeAndReduce (AstrometryTransform const &right) const
 Return a reduced composition of newTransform = this(right()), or nullptr if it cannot be reduced. More...
 
double coeff (std::size_t powX, std::size_t powY, std::size_t whichCoord) const
 access to coefficients (read only) More...
 
double & coeff (std::size_t powX, std::size_t powY, std::size_t whichCoord)
 write access More...
 
double coeffOrZero (std::size_t powX, std::size_t powY, std::size_t whichCoord) const
 read access, zero if beyond order More...
 
double determinant () const
 
double paramRef (Eigen::Index const i) const override
 
double & paramRef (Eigen::Index const 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
 
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< AstrometryTransformroughInverse (const Frame &region) const
 Rough inverse. More...
 

Protected Member Functions

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

Friends

class AstrometryTransform
 
class AstrometryTransformIdentity
 
class AstrometryTransformPolynomial
 

Detailed Description

implements the linear transformations (6 real coefficients).

Definition at line 426 of file AstrometryTransform.h.

Constructor & Destructor Documentation

◆ AstrometryTransformLinear() [1/4]

lsst::jointcal::AstrometryTransformLinear::AstrometryTransformLinear ( )
inline

the default constructor constructs the do-nothing transformation.

Definition at line 431 of file AstrometryTransform.h.

◆ AstrometryTransformLinear() [2/4]

lsst::jointcal::AstrometryTransformLinear::AstrometryTransformLinear ( AstrometryTransformPolynomial const &  transform)
explicit

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

Definition at line 1211 of file AstrometryTransform.cc.

1213  if (transform.getOrder() != 1)
1215  "Trying to build a AstrometryTransformLinear from a higher order transform. Aborting. ");
1217 }
Reports invalid arguments.
Definition: Runtime.h:66
table::Key< int > transform

◆ AstrometryTransformLinear() [3/4]

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

Construct a AstrometryTransformLinear from parameters.

Definition at line 1200 of file AstrometryTransform.cc.

1203  dx() = Dx;
1204  a11() = A11;
1205  a12() = A12;
1206  dy() = Dy;
1207  a21() = A21;
1208  a22() = A22;
1209 }

◆ AstrometryTransformLinear() [4/4]

lsst::jointcal::AstrometryTransformLinear::AstrometryTransformLinear ( AstrometryTransformIdentity const &  )
inline

Handy converter:

Definition at line 459 of file AstrometryTransform.h.

Member Function Documentation

◆ __str__()

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

Definition at line 94 of file AstrometryTransform.h.

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

◆ A11()

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

Definition at line 467 of file AstrometryTransform.h.

467 { return coeff(1, 0, 0); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ a11()

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

Definition at line 475 of file AstrometryTransform.h.

475 { return coeff(1, 0, 0); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ A12()

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

Definition at line 468 of file AstrometryTransform.h.

468 { return coeff(0, 1, 0); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ a12()

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

Definition at line 476 of file AstrometryTransform.h.

476 { return coeff(0, 1, 0); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ A21()

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

Definition at line 469 of file AstrometryTransform.h.

469 { return coeff(1, 0, 1); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ a21()

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

Definition at line 477 of file AstrometryTransform.h.

477 { return coeff(1, 0, 1); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ A22()

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

Definition at line 470 of file AstrometryTransform.h.

470 { return coeff(0, 1, 1); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ a22()

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

Definition at line 478 of file AstrometryTransform.h.

478 { return coeff(0, 1, 1); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ apply() [1/4]

void lsst::jointcal::AstrometryTransform::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 AstrometryTransform.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::AstrometryTransform::apply ( Point const &  in) const
inlineinherited

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

Definition at line 75 of file AstrometryTransform.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::AstrometryTransform::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 75 of file AstrometryTransform.cc.

75  {
76  // 2 opposite corners
77  double xtmin1, xtmax1, ytmin1, ytmax1;
78  apply(inputframe.xMin, inputframe.yMin, xtmin1, ytmin1);
79  apply(inputframe.xMax, inputframe.yMax, xtmax1, ytmax1);
80  Frame fr1(std::min(xtmin1, xtmax1), std::min(ytmin1, ytmax1), std::max(xtmin1, xtmax1),
81  std::max(ytmin1, ytmax1));
82  // 2 other corners
83  double xtmin2, xtmax2, ytmin2, ytmax2;
84  apply(inputframe.xMin, inputframe.yMax, xtmin2, ytmax2);
85  apply(inputframe.xMax, inputframe.yMin, xtmax2, ytmin2);
86  Frame fr2(std::min(xtmin2, xtmax2), std::min(ytmin2, ytmax2), std::max(xtmin2, xtmax2),
87  std::max(ytmin2, ytmax2));
88 
89  if (inscribed) return fr1 * fr2;
90  return fr1 + fr2;
91 }
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::AstrometryTransformPolynomial::apply ( const double  xIn,
const double  yIn,
double &  xOut,
double &  yOut 
) const
overridevirtualinherited

Implements lsst::jointcal::AstrometryTransform.

Definition at line 570 of file AstrometryTransform.cc.

571  {
572  /*
573  This routine computes the monomials only once for both
574  polynomials. This is why AstrometryTransformPolynomial does not use an auxilary
575  class (such as PolyXY) to handle each polynomial.
576 
577  The code works even if &xIn == &xOut (or &yIn == &yOut)
578  It uses Variable Length Allocation (VLA) rather than a vector<double>
579  because allocating the later costs about 50 ns. All VLA uses are tagged.
580  */
581  double monomials[_nterms]; // this is VLA, which is (perhaps) not casher C++
582  computeMonomials(xIn, yIn, monomials);
583 
584  xOut = 0;
585  yOut = 0;
586  const double *c = &_coeffs[0];
587  const double *pm = &monomials[0];
588  // the ordering of the coefficients and the monomials are identical.
589  for (int k = _nterms; k--;) xOut += (*(pm++)) * (*(c++));
590  pm = &monomials[0];
591  for (int k = _nterms; k--;) yOut += (*(pm++)) * (*(c++));
592 }

◆ clone()

std::unique_ptr<AstrometryTransform> lsst::jointcal::AstrometryTransformLinear::clone ( ) const
inlinevirtual

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

Reimplemented from lsst::jointcal::AstrometryTransformPolynomial.

Definition at line 461 of file AstrometryTransform.h.

461  {
463  }
AstrometryTransformLinear()
the default constructor constructs the do-nothing transformation.
STL class.

◆ coeff() [1/2]

double lsst::jointcal::AstrometryTransformPolynomial::coeff ( std::size_t  powX,
std::size_t  powY,
std::size_t  whichCoord 
) const
inherited

access to coefficients (read only)

Definition at line 738 of file AstrometryTransform.cc.

739  {
740  assert((degX + degY <= _order) && whichCoord < 2);
741  /* this assertion above is enough to ensure that the index used just
742  below is within bounds since the reserved length is
743  2*_nterms=(order+1)*(order+2) */
744  return _coeffs[(degX + degY) * (degX + degY + 1) / 2 + degY + whichCoord * _nterms];
745 }

◆ coeff() [2/2]

double & lsst::jointcal::AstrometryTransformPolynomial::coeff ( std::size_t  powX,
std::size_t  powY,
std::size_t  whichCoord 
)
inherited

write access

Definition at line 747 of file AstrometryTransform.cc.

748  {
749  assert((degX + degY <= _order) && whichCoord < 2);
750  return _coeffs[(degX + degY) * (degX + degY + 1) / 2 + degY + whichCoord * _nterms];
751 }

◆ coeffOrZero()

double lsst::jointcal::AstrometryTransformPolynomial::coeffOrZero ( std::size_t  powX,
std::size_t  powY,
std::size_t  whichCoord 
) const
inherited

read access, zero if beyond order

Definition at line 753 of file AstrometryTransform.cc.

754  {
755  // assert((degX+degY<=order) && whichCoord<2);
756  assert(whichCoord < 2);
757  if (degX + degY <= _order)
758  return _coeffs[(degX + degY) * (degX + degY + 1) / 2 + degY + whichCoord * _nterms];
759  return 0;
760 }

◆ composeAndReduce() [1/2]

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

Return a reduced composition of newTransform = 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 AstrometryTransform, or nullptr if no such reduction is possible.

Reimplemented in lsst::jointcal::AstrometryTransformIdentity.

Definition at line 93 of file AstrometryTransform.cc.

94  { // by default no way to compose
96 }
STL class.

◆ composeAndReduce() [2/2]

std::unique_ptr< AstrometryTransform > lsst::jointcal::AstrometryTransformPolynomial::composeAndReduce ( AstrometryTransformPolynomial const &  right) const
inherited

Return a reduced composition of newTransform = 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 AstrometryTransform, or nullptr if no such reduction is possible.

Definition at line 930 of file AstrometryTransform.cc.

931  {
932  if (getOrder() == 1 && right.getOrder() == 1)
933  return std::make_unique<AstrometryTransformLinear>((*this) * (right)); // does the composition
934  else
935  return std::make_unique<AstrometryTransformPolynomial>((*this) * (right)); // does the composition
936 }
T right(T... args)
std::size_t getOrder() const
Returns the polynomial order.

◆ computeDerivative()

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

specialised analytic routine

Reimplemented from lsst::jointcal::AstrometryTransformPolynomial.

Definition at line 1234 of file AstrometryTransform.cc.

1235  {
1236  derivative = *this;
1237  derivative.coeff(0, 0, 0) = 0;
1238  derivative.coeff(0, 0, 1) = 0;
1239 }

◆ determinant()

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

Definition at line 812 of file AstrometryTransform.cc.

812  {
813  if (_order >= 1) return coeff(1, 0, 0) * coeff(0, 1, 1) - coeff(0, 1, 0) * coeff(1, 0, 1);
814  return 0;
815 }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ dump()

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

print out of coefficients in a readable form.

Implements lsst::jointcal::AstrometryTransform.

Definition at line 793 of file AstrometryTransform.cc.

793  {
794  auto oldPrecision = stream.precision();
795  stream.precision(12);
796  for (std::size_t ic = 0; ic < 2; ++ic) {
797  if (ic == 0)
798  stream << "newx = ";
799  else
800  stream << "newy = ";
801  for (std::size_t p = 0; p <= _order; ++p)
802  for (std::size_t py = 0; py <= p; ++py) {
803  if (p + py != 0) stream << " + ";
804  stream << coeff(p - py, py, ic) << monomialString(p - py, py);
805  }
806  stream << endl;
807  }
808  if (_order > 0) stream << " Linear determinant = " << determinant() << endl;
809  stream.precision(oldPrecision);
810 }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)
T endl(T... args)
T precision(T... args)

◆ Dx()

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

Definition at line 471 of file AstrometryTransform.h.

471 { return coeff(0, 0, 0); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ dx()

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

Definition at line 479 of file AstrometryTransform.h.

479 { return coeff(0, 0, 0); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ Dy()

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

Definition at line 472 of file AstrometryTransform.h.

472 { return coeff(0, 0, 1); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ dy()

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

Definition at line 480 of file AstrometryTransform.h.

480 { return coeff(0, 0, 1); }
double coeff(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
access to coefficients (read only)

◆ fit()

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

guess what

Implements lsst::jointcal::AstrometryTransform.

Reimplemented in lsst::jointcal::AstrometryTransformLinearRot, and lsst::jointcal::AstrometryTransformLinearShift.

Definition at line 912 of file AstrometryTransform.cc.

912  {
913  if (starMatchList.size() < _nterms) {
914  LOGLS_FATAL(_log, "AstrometryTransformPolynomial::fit trying to fit a polynomial transform of order "
915  << _order << " with only " << starMatchList.size() << " matches.");
916  return -1;
917  }
918 
919  AstrometryTransformPolynomial conditionner = shiftAndNormalize(starMatchList);
920 
921  computeFit(starMatchList, conditionner, false); // get a rough solution
922  computeFit(starMatchList, conditionner, true); // weight with it
923  double chi2 = computeFit(starMatchList, conditionner, true); // once more
924 
925  (*this) = (*this) * conditionner;
926  if (starMatchList.size() == _nterms) return 0;
927  return chi2;
928 }
AstrometryTransformPolynomial(std::size_t order=1)
Default transform : identity for all orders (>=1 ).
#define LOGLS_FATAL(logger, message)
Log a fatal-level message using an iostream-based interface.
Definition: Log.h:688

◆ getJacobian() [1/2]

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

returns the local jacobian.

Definition at line 110 of file AstrometryTransform.h.

110 { return getJacobian(point.x, point.y); }
virtual double getJacobian(Point const &point) const
returns the local jacobian.

◆ getJacobian() [2/2]

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

returns the local jacobian.

Definition at line 98 of file AstrometryTransform.cc.

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

◆ getNpar()

std::size_t lsst::jointcal::AstrometryTransformPolynomial::getNpar ( ) const
inlineoverridevirtualinherited

total number of parameters

Reimplemented from lsst::jointcal::AstrometryTransform.

Reimplemented in lsst::jointcal::AstrometryTransformLinearScale, lsst::jointcal::AstrometryTransformLinearRot, and lsst::jointcal::AstrometryTransformLinearShift.

Definition at line 323 of file AstrometryTransform.h.

323 { return 2 * _nterms; }

◆ getOrder()

std::size_t lsst::jointcal::AstrometryTransformPolynomial::getOrder ( ) const
inlineinherited

Returns the polynomial order.

Definition at line 309 of file AstrometryTransform.h.

309 { return _order; }

◆ getParams()

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

params should be at least Npar() long

Definition at line 215 of file AstrometryTransform.cc.

215  {
216  std::size_t npar = getNpar();
217  for (std::size_t i = 0; i < npar; ++i) params[i] = paramRef(i);
218 }
virtual std::size_t getNpar() const
returns the number of parameters (to compute chi2&#39;s)
virtual double paramRef(Eigen::Index const i) const

◆ inverseTransform()

std::unique_ptr< AstrometryTransform > lsst::jointcal::AstrometryTransformLinear::inverseTransform ( const double  precision,
const Frame region 
) const
virtual

returns an inverse transform. Numerical if not overloaded.

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

Reimplemented from lsst::jointcal::AstrometryTransform.

Definition at line 1272 of file AstrometryTransform.cc.

1273  {
1275 }
AstrometryTransformLinear()
the default constructor constructs the do-nothing transformation.
STL class.
AstrometryTransformLinear inverted() const
returns the inverse: T1 = T2.inverted();

◆ inverted()

AstrometryTransformLinear lsst::jointcal::AstrometryTransformLinear::inverted ( ) const

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

Definition at line 1245 of file AstrometryTransform.cc.

1245  {
1246  //
1247  // (T1,M1) * (T2,M2) = 1 i.e (0,1) implies
1248  // T1 = -M1 * T2
1249  // M1 = M2^(-1)
1250  //
1251 
1252  double a11 = A11();
1253  double a12 = A12();
1254  double a21 = A21();
1255  double a22 = A22();
1256  double d = (a11 * a22 - a12 * a21);
1257  if (d == 0) {
1258  LOGL_FATAL(_log,
1259  "AstrometryTransformLinear::invert singular transformation: transform contents will be "
1260  "dumped to stderr.");
1261  dump(cerr);
1262  }
1263 
1264  AstrometryTransformLinear result(0, 0, a22 / d, -a12 / d, -a21 / d, a11 / d);
1265  double rdx, rdy;
1266  result.apply(Dx(), Dy(), rdx, rdy);
1267  result.dx() = -rdx;
1268  result.dy() = -rdy;
1269  return result;
1270 }
void dump(std::ostream &stream=std::cout) const override
print out of coefficients in a readable form.
#define LOGL_FATAL(logger, message...)
Log a fatal-level message using a varargs/printf style interface.
Definition: Log.h:568
AstrometryTransformLinear()
the default constructor constructs the do-nothing transformation.
py::object result
Definition: _schema.cc:429

◆ linearApproximation()

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

linear (local) approximation.

Reimplemented from lsst::jointcal::AstrometryTransform.

Definition at line 1241 of file AstrometryTransform.cc.

1241  {
1242  return *this;
1243 }

◆ offsetParams()

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

Definition at line 220 of file AstrometryTransform.cc.

220  {
221  std::size_t npar = getNpar();
222  for (std::size_t i = 0; i < npar; ++i) paramRef(i) += delta[i];
223 }
virtual std::size_t getNpar() const
returns the number of parameters (to compute chi2&#39;s)
virtual double paramRef(Eigen::Index const i) const

◆ operator*() [1/2]

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

Composition (internal stuff in quadruple precision)

Definition at line 1035 of file AstrometryTransform.cc.

1036  {
1037  // split each transform into 2d polynomials
1038  PolyXY plx(*this, 0);
1039  PolyXY ply(*this, 1);
1040  PolyXY prx(right, 0);
1041  PolyXY pry(right, 1);
1042 
1043  // compute the compositions
1044  PolyXY rx(composition(plx, prx, pry));
1045  PolyXY ry(composition(ply, prx, pry));
1046 
1047  // copy the results the hard way.
1048  AstrometryTransformPolynomial result(_order * right._order);
1049  for (std::size_t px = 0; px <= result._order; ++px)
1050  for (std::size_t py = 0; py <= result._order - px; ++py) {
1051  result.coeff(px, py, 0) = rx.coeff(px, py);
1052  result.coeff(px, py, 1) = ry.coeff(px, py);
1053  }
1054  return result;
1055 }
AstrometryTransformPolynomial(std::size_t order=1)
Default transform : identity for all orders (>=1 ).
T right(T... args)
py::object result
Definition: _schema.cc:429

◆ operator*() [2/2]

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

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

Definition at line 1219 of file AstrometryTransform.cc.

1219  {
1220  // There is a general routine in AstrometryTransformPolynomial that would do the job:
1221  // return AstrometryTransformLinear(AstrometryTransformPolynomial::operator*(right));
1222  // however, we are using this composition of linear stuff heavily in
1223  // AstrometryTransform::linearApproximation, itself used in inverseTransform::apply.
1224  // So, for sake of efficiency, and since it is easy, we take a shortcut:
1226  apply(right.Dx(), right.Dy(), result.dx(), result.dy());
1227  result.a11() = A11() * right.A11() + A12() * right.A21();
1228  result.a12() = A11() * right.A12() + A12() * right.A22();
1229  result.a21() = A21() * right.A11() + A22() * right.A21();
1230  result.a22() = A21() * right.A12() + A22() * right.A22();
1231  return result;
1232 }
void apply(const double xIn, const double yIn, double &xOut, double &yOut) const override
T right(T... args)
AstrometryTransformLinear()
the default constructor constructs the do-nothing transformation.
py::object result
Definition: _schema.cc:429

◆ operator+()

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

Addition.

Definition at line 1057 of file AstrometryTransform.cc.

1058  {
1059  if (_order >= right._order) {
1060  AstrometryTransformPolynomial res(*this);
1061  for (std::size_t i = 0; i <= right._order; ++i)
1062  for (std::size_t j = 0; j <= right._order - i; ++j) {
1063  res.coeff(i, j, 0) += right.coeff(i, j, 0);
1064  res.coeff(i, j, 1) += right.coeff(i, j, 1);
1065  }
1066  return res;
1067  } else
1068  return (right + (*this));
1069 }
AstrometryTransformPolynomial(std::size_t order=1)
Default transform : identity for all orders (>=1 ).
T right(T... args)

◆ operator-()

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

Subtraction.

Definition at line 1071 of file AstrometryTransform.cc.

1072  {
1073  AstrometryTransformPolynomial res(std::max(_order, right._order));
1074  for (std::size_t i = 0; i <= res._order; ++i)
1075  for (std::size_t j = 0; j <= res._order - i; ++j) {
1076  res.coeff(i, j, 0) = coeffOrZero(i, j, 0) - right.coeffOrZero(i, j, 0);
1077  res.coeff(i, j, 1) = coeffOrZero(i, j, 1) - right.coeffOrZero(i, j, 1);
1078  }
1079  return res;
1080 }
AstrometryTransformPolynomial(std::size_t order=1)
Default transform : identity for all orders (>=1 ).
T right(T... args)
T max(T... args)
double coeffOrZero(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
read access, zero if beyond order

◆ paramDerivatives()

void lsst::jointcal::AstrometryTransformPolynomial::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::AstrometryTransform.

Definition at line 773 of file AstrometryTransform.cc.

774  { /* first half : dxout/dpar, second half : dyout/dpar */
775  computeMonomials(where.x, where.y, dx);
776  for (std::size_t k = 0; k < _nterms; ++k) {
777  dy[_nterms + k] = dx[k];
778  dx[_nterms + k] = dy[k] = 0;
779  }
780 }

◆ paramRef() [1/2]

double lsst::jointcal::AstrometryTransformPolynomial::paramRef ( Eigen::Index const  i) const
overridevirtualinherited

Reimplemented from lsst::jointcal::AstrometryTransform.

Definition at line 763 of file AstrometryTransform.cc.

763  {
764  assert(i < 2 * Eigen::Index(_nterms));
765  return _coeffs[i];
766 }

◆ paramRef() [2/2]

double & lsst::jointcal::AstrometryTransformPolynomial::paramRef ( Eigen::Index const  i)
overridevirtualinherited

Reimplemented from lsst::jointcal::AstrometryTransform.

Definition at line 768 of file AstrometryTransform.cc.

768  {
769  assert(i < 2 * Eigen::Index(_nterms));
770  return _coeffs[i];
771 }

◆ read()

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

Definition at line 1097 of file AstrometryTransform.cc.

1097  {
1098  int format;
1099  s >> format;
1100  if (format != 1)
1101  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
1102  " AstrometryTransformPolynomial::read : format is not 1 ");
1103 
1104  string order;
1105  s >> order >> _order;
1106  if (order != "order")
1107  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
1108  " AstrometryTransformPolynomial::read : expecting \"order\" and found " + order);
1109  setOrder(_order);
1110  for (std::size_t k = 0; k < 2 * _nterms; ++k) s >> _coeffs[k];
1111 }
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
void setOrder(std::size_t order)
Sets the polynomial order (the highest sum of exponents of the largest monomial). ...
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

◆ roughInverse()

std::unique_ptr< AstrometryTransform > lsst::jointcal::AstrometryTransform::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::AstrometryTransformInverse.

Definition at line 194 of file AstrometryTransform.cc.

194  {
195  // "in" and "out" refer to the inverse direction.
196  Point centerOut = region.getCenter();
197  Point centerIn = apply(centerOut);
198  AstrometryTransformLinear der;
199  computeDerivative(centerOut, der, std::sqrt(region.getArea()) / 5.);
200  der = der.inverted();
201  der = AstrometryTransformLinearShift(centerOut.x, centerOut.y) * der *
202  AstrometryTransformLinearShift(-centerIn.x, -centerIn.y);
203  return std::unique_ptr<AstrometryTransform>(new AstrometryTransformLinear(der));
204 }
virtual void computeDerivative(Point const &where, AstrometryTransformLinear &derivative, const double step=0.01) const
Computes the local Derivative of a transform, w.r.t.
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::AstrometryTransformPolynomial::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 transform, to help find an inverse.
Returns
An AST Mapping that represents this transformation.

Reimplemented from lsst::jointcal::AstrometryTransform.

Definition at line 1082 of file AstrometryTransform.cc.

1082  {
1083  auto inverse = inversePolyTransform(*this, domain, 1e-7, _order + 2, 100);
1084  return std::make_shared<ast::PolyMap>(toAstPolyMapCoefficients(), inverse->toAstPolyMapCoefficients());
1085 }
std::shared_ptr< AstrometryTransformPolynomial > inversePolyTransform(AstrometryTransform const &forward, Frame const &domain, double const precision, std::size_t maxOrder=9, std::size_t nSteps=50)
Approximate the inverse by a polynomial, to some precision.

◆ transformErrors()

void lsst::jointcal::AstrometryTransform::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 161 of file AstrometryTransform.cc.

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

◆ transformPosAndErrors()

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

a mix of apply and Derivative

Reimplemented from lsst::jointcal::AstrometryTransform.

Definition at line 654 of file AstrometryTransform.cc.

654  {
655  /*
656  The results from this routine were compared to what comes out
657  from apply and transformErrors. The Derivative routine was
658  checked against numerical derivatives from
659  AstrometryTransform::Derivative. (P.A dec 2009).
660 
661  This routine could be made much simpler by calling apply and
662  Derivative (i.e. you just suppress it, and the fallback is the
663  generic version in AstrometryTransform). BTW, I checked that both routines
664  provide the same result. This version is however faster
665  (monomials get recycled).
666  */
667  double monomials[_nterms]; // VLA
668 
669  FatPoint res; // to store the result, because nothing forbids &in == &out.
670 
671  double dermx[2 * _nterms]; // monomials for derivative w.r.t. x (VLA)
672  double *dermy = dermx + _nterms; // same for y
673  double xin = in.x;
674  double yin = in.y;
675 
676  double xx = 1;
677  double xxm1 = 1; // xx^(ix-1)
678  for (std::size_t ix = 0; ix <= _order; ++ix) {
679  std::size_t k = (ix) * (ix + 1) / 2;
680  // iy = 0
681  dermx[k] = ix * xxm1;
682  dermy[k] = 0;
683  monomials[k] = xx;
684  k += ix + 2;
685  double yy = yin;
686  double yym1 = 1; // yy^(iy-1)
687  for (std::size_t iy = 1; iy <= _order - ix; ++iy) {
688  monomials[k] = xx * yy;
689  dermx[k] = ix * xxm1 * yy;
690  dermy[k] = iy * xx * yym1;
691  yym1 *= yin;
692  yy *= yin;
693  k += ix + iy + 2;
694  }
695  xx *= xin;
696  if (ix >= 1) xxm1 *= xin;
697  }
698 
699  // output position
700  double xout = 0, yout = 0;
701  const double *c = &_coeffs[0];
702  const double *pm = &monomials[0];
703  for (int k = _nterms; k--;) xout += (*(pm++)) * (*(c++));
704  pm = &monomials[0];
705  for (int k = _nterms; k--;) yout += (*(pm++)) * (*(c++));
706  res.x = xout;
707  res.y = yout;
708 
709  // derivatives
710  c = &_coeffs[0];
711  const double *mx = &dermx[0];
712  const double *my = &dermy[0];
713  double a11 = 0, a12 = 0;
714  for (int k = _nterms; k--;) {
715  a11 += (*(mx++)) * (*c);
716  a12 += (*(my++)) * (*(c++));
717  }
718 
719  double a21 = 0, a22 = 0;
720  mx = &dermx[0];
721  my = &dermy[0];
722  for (int k = _nterms; k--;) {
723  a21 += (*(mx++)) * (*c);
724  a22 += (*(my++)) * (*(c++));
725  }
726 
727  // output co-variance
728  res.vx = a11 * (a11 * in.vx + 2 * a12 * in.vxy) + a12 * a12 * in.vy;
729  res.vy = a21 * a21 * in.vx + a22 * a22 * in.vy + 2. * a21 * a22 * in.vxy;
730  res.vxy = a21 * a11 * in.vx + a22 * a12 * in.vy + (a21 * a12 + a11 * a22) * in.vxy;
731  out = res;
732 }

◆ transformStar()

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

Definition at line 107 of file AstrometryTransform.h.

107 { transformPosAndErrors(in, in); }
virtual void transformPosAndErrors(const FatPoint &in, FatPoint &out) const

◆ write() [1/2]

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

Definition at line 245 of file AstrometryTransform.cc.

245  {
246  ofstream s(fileName.c_str());
247  write(s);
248  bool ok = !s.fail();
249  s.close();
250  if (!ok)
251  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
252  "AstrometryTransform::write, something went wrong for file " + fileName);
253 }
void write(const std::string &fileName) const
STL class.
#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::AstrometryTransformPolynomial::write ( std::ostream s) const
overridevirtualinherited

Reimplemented from lsst::jointcal::AstrometryTransform.

Definition at line 1087 of file AstrometryTransform.cc.

1087  {
1088  s << " AstrometryTransformPolynomial 1" << endl;
1089  s << "order " << _order << endl;
1090  int oldprec = s.precision();
1091  s << setprecision(12);
1092  for (std::size_t k = 0; k < 2 * _nterms; ++k) s << _coeffs[k] << ' ';
1093  s << endl;
1094  s << setprecision(oldprec);
1095 }
T endl(T... args)
T precision(T... args)
T setprecision(T... args)

Friends And Related Function Documentation

◆ AstrometryTransform

friend class AstrometryTransform
friend

Definition at line 482 of file AstrometryTransform.h.

◆ AstrometryTransformIdentity

friend class AstrometryTransformIdentity
friend

Definition at line 483 of file AstrometryTransform.h.

◆ AstrometryTransformPolynomial

friend class AstrometryTransformPolynomial
friend

Definition at line 484 of file AstrometryTransform.h.


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