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 | List of all members
lsst::jointcal::AstrometryTransform Class Referenceabstract

a virtual (interface) class for geometric transformations. More...

#include <AstrometryTransform.h>

Inheritance diagram for lsst::jointcal::AstrometryTransform:
lsst::jointcal::AstrometryTransformComposition lsst::jointcal::AstrometryTransformIdentity lsst::jointcal::AstrometryTransformInverse lsst::jointcal::AstrometryTransformPolynomial lsst::jointcal::AstrometryTransformSkyWcs lsst::jointcal::BaseTanWcs lsst::jointcal::TanRaDecToPixel lsst::jointcal::UserTransform

Public Member Functions

virtual void apply (const double xIn, const double yIn, double &xOut, double &yOut) const =0
 
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 dump (std::ostream &stream=std::cout) const =0
 dumps the transform coefficients to stream. More...
 
std::string __str__ ()
 
virtual double fit (StarMatchList const &starMatchList)=0
 fits a transform to a std::list of Point pairs (p1,p2, the Point fields in StarMatch). More...
 
void transformStar (FatPoint &in) const
 
virtual double getJacobian (Point const &point) const
 returns the local jacobian. More...
 
virtual std::unique_ptr< AstrometryTransformclone () const =0
 returns a copy (allocated by new) of the transformation. 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...
 
virtual double getJacobian (const double x, const double y) const
 returns the local jacobian. More...
 
virtual void computeDerivative (Point const &where, AstrometryTransformLinear &derivative, const double step=0.01) const
 Computes the local Derivative of a transform, w.r.t. More...
 
virtual AstrometryTransformLinear linearApproximation (Point const &where, const double step=0.01) const
 linear (local) approximation. More...
 
virtual void transformPosAndErrors (const FatPoint &in, FatPoint &out) const
 
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...
 
virtual std::unique_ptr< AstrometryTransforminverseTransform (const double precision, const Frame &region) const
 returns an inverse transform. Numerical if not overloaded. More...
 
void getParams (double *params) const
 params should be at least Npar() long More...
 
void offsetParams (Eigen::VectorXd const &delta)
 
virtual double paramRef (Eigen::Index const i) const
 
virtual double & paramRef (Eigen::Index const i)
 
virtual void paramDerivatives (Point const &where, double *dx, double *dy) const
 Derivative w.r.t parameters. More...
 
virtual std::unique_ptr< AstrometryTransformroughInverse (const Frame &region) const
 Rough inverse. More...
 
virtual std::size_t getNpar () const
 returns the number of parameters (to compute chi2's) More...
 
virtual std::shared_ptr< ast::MappingtoAstMap (jointcal::Frame const &domain) const
 Create an equivalent AST mapping for this transformation, including an analytic inverse if possible. More...
 
void write (const std::string &fileName) const
 
virtual void write (std::ostream &stream) const
 
virtual ~AstrometryTransform ()
 

Detailed Description

a virtual (interface) class for geometric transformations.

We implement here One AstrometryTransform interface class, and actual derived classes. Composition in the usual (mathematical) sense is provided using compose(), and some classes (e.g. AstrometryTransformLinear) handle a * operator. Generic inversion by iteration exists, but it is at least 10 times slower than the corresponding "direct transformation". If a transform has an analytical inverse, then providing inverseTransform is obviously a very good idea. Before resorting to inverseTransform, consider using StarMatchList::inverseTransform(). AstrometryTransformLinear::inverted() and TanPixelToRaDec::inverted() exist. The classes also provide derivation and linear approximation.

Definition at line 65 of file AstrometryTransform.h.

Constructor & Destructor Documentation

◆ ~AstrometryTransform()

virtual lsst::jointcal::AstrometryTransform::~AstrometryTransform ( )
inlinevirtual

Definition at line 197 of file AstrometryTransform.h.

197 {};

Member Function Documentation

◆ __str__()

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

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.

◆ apply() [1/4]

virtual void lsst::jointcal::AstrometryTransform::apply ( const double  xIn,
const double  yIn,
double &  xOut,
double &  yOut 
) const
pure virtual

◆ apply() [2/4]

void lsst::jointcal::AstrometryTransform::apply ( Point const &  in,
Point out 
) const
inline

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() [3/4]

Point lsst::jointcal::AstrometryTransform::apply ( Point const &  in) const
inline

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() [4/4]

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

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

◆ clone()

virtual std::unique_ptr<AstrometryTransform> lsst::jointcal::AstrometryTransform::clone ( ) const
pure virtual

◆ composeAndReduce()

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

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.

◆ computeDerivative()

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

Computes the local Derivative of a transform, w.r.t.

the Derivative is represented by a AstrometryTransformLinear, in which (hopefully), the offset terms are zero.

position.

Step is used for numerical derivation.

Derivative should transform a vector of offsets into a vector of offsets.

Reimplemented in lsst::jointcal::AstrometryTransformLinear, lsst::jointcal::AstrometryTransformPolynomial, and lsst::jointcal::AstrometryTransformIdentity.

Definition at line 117 of file AstrometryTransform.cc.

118  {
119  double x = where.x;
120  double y = where.y;
121  double xp0, yp0;
122  apply(x, y, xp0, yp0);
123 
124  double xp, yp;
125  apply(x + step, y, xp, yp);
126  derivative.a11() = (xp - xp0) / step;
127  derivative.a21() = (yp - yp0) / step;
128  apply(x, y + step, xp, yp);
129  derivative.a12() = (xp - xp0) / step;
130  derivative.a22() = (yp - yp0) / step;
131  derivative.dx() = 0;
132  derivative.dy() = 0;
133 }
int y
Definition: SpanSet.cc:49
int const step
double x
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ dump()

virtual void lsst::jointcal::AstrometryTransform::dump ( std::ostream stream = std::cout) const
pure virtual

◆ fit()

virtual double lsst::jointcal::AstrometryTransform::fit ( StarMatchList const &  starMatchList)
pure virtual

◆ getJacobian() [1/2]

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

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
virtual

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()

virtual std::size_t lsst::jointcal::AstrometryTransform::getNpar ( ) const
inlinevirtual

◆ getParams()

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

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::AstrometryTransform::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 in lsst::jointcal::TanRaDecToPixel, lsst::jointcal::TanSipPixelToRaDec, lsst::jointcal::TanPixelToRaDec, lsst::jointcal::AstrometryTransformLinear, and lsst::jointcal::AstrometryTransformInverse.

Definition at line 302 of file AstrometryTransform.cc.

303  {
304  return std::unique_ptr<AstrometryTransform>(new AstrometryTransformInverse(this, precision, region));
305 }
STL class.

◆ linearApproximation()

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

linear (local) approximation.

Reimplemented in lsst::jointcal::AstrometryTransformLinear, and lsst::jointcal::AstrometryTransformIdentity.

Definition at line 135 of file AstrometryTransform.cc.

136  {
137  Point outwhere = apply(where);
138  AstrometryTransformLinear der;
139  computeDerivative(where, der, step);
140  return AstrometryTransformLinearShift(outwhere.x, outwhere.y) * der *
141  AstrometryTransformLinearShift(-where.x, -where.y);
142 }
virtual void computeDerivative(Point const &where, AstrometryTransformLinear &derivative, const double step=0.01) const
Computes the local Derivative of a transform, w.r.t.
int const step
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ offsetParams()

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

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

◆ paramDerivatives()

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

Derivative w.r.t parameters.

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

Reimplemented in lsst::jointcal::AstrometryTransformPolynomial.

Definition at line 235 of file AstrometryTransform.cc.

235  {
236  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
237  "AstrometryTransform::paramDerivatives() should never be called ");
238 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

◆ paramRef() [1/2]

double lsst::jointcal::AstrometryTransform::paramRef ( Eigen::Index const  i) const
virtual

Reimplemented in lsst::jointcal::AstrometryTransformPolynomial.

Definition at line 225 of file AstrometryTransform.cc.

225  {
226  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
227  std::string("AstrometryTransform::paramRef should never be called "));
228 }
STL class.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

◆ paramRef() [2/2]

double & lsst::jointcal::AstrometryTransform::paramRef ( Eigen::Index const  i)
virtual

Reimplemented in lsst::jointcal::AstrometryTransformPolynomial.

Definition at line 230 of file AstrometryTransform.cc.

230  {
231  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
232  "AstrometryTransform::paramRef should never be called ");
233 }
#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
virtual

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()

virtual std::shared_ptr<ast::Mapping> lsst::jointcal::AstrometryTransform::toAstMap ( jointcal::Frame const &  domain) const
inlinevirtual

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 in lsst::jointcal::AstrometryTransformPolynomial, and lsst::jointcal::AstrometryTransformIdentity.

Definition at line 189 of file AstrometryTransform.h.

189  {
190  throw std::logic_error("toAstMap is not implemented for this class.");
191  }
STL class.

◆ transformErrors()

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

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::AstrometryTransform::transformPosAndErrors ( const FatPoint in,
FatPoint out 
) const
virtual

Reimplemented in lsst::jointcal::TanRaDecToPixel, and lsst::jointcal::AstrometryTransformPolynomial.

Definition at line 144 of file AstrometryTransform.cc.

144  {
145  FatPoint res; // in case in and out are the same address...
146  res = apply(in);
147  AstrometryTransformLinear der;
148  // could save a call here, since Derivative needs the transform of where that we already have
149  // 0.01 may not be a very good idea in all cases. May be we should provide a way of altering that.
150  computeDerivative(in, der, 0.01);
151  double a11 = der.A11();
152  double a22 = der.A22();
153  double a21 = der.A21();
154  double a12 = der.A12();
155  res.vx = a11 * (a11 * in.vx + 2 * a12 * in.vxy) + a12 * a12 * in.vy;
156  res.vy = a21 * a21 * in.vx + a22 * a22 * in.vy + 2. * a21 * a22 * in.vxy;
157  res.vxy = a21 * a11 * in.vx + a22 * a12 * in.vy + (a21 * a12 + a11 * a22) * in.vxy;
158  out = res;
159 }
virtual void computeDerivative(Point const &where, AstrometryTransformLinear &derivative, const double step=0.01) const
Computes the local Derivative of a transform, w.r.t.
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0

◆ transformStar()

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

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

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::AstrometryTransform::write ( std::ostream stream) const
virtual

Reimplemented in lsst::jointcal::AstrometryTransformPolynomial, and lsst::jointcal::AstrometryTransformIdentity.

Definition at line 255 of file AstrometryTransform.cc.

255  {
256  throw LSST_EXCEPT(
257  pex::exceptions::InvalidParameterError,
258  "AstrometryTransform::write(ostream), should never be called. MEans that it is missing in some "
259  "derived class ");
260 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48

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