LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
SimpleAstrometryMapping.cc
Go to the documentation of this file.
1// -*- LSST-C++ -*-
2/*
3 * This file is part of jointcal.
4 *
5 * Developed for the LSST Data Management System.
6 * This product includes software developed by the LSST Project
7 * (https://www.lsst.org).
8 * See the COPYRIGHT file at the top-level directory of this distribution
9 * for details of code ownership.
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25#include <utility>
26
30
31namespace lsst {
32namespace jointcal {
33
35 if (indices.size() < getNpar()) {
36 indices.resize(getNpar());
37 }
38 for (std::size_t k = 0; k < getNpar(); ++k) {
39 indices[k] = index + k;
40 }
41}
42
44 transform->transformPosAndErrors(where, outPoint);
45 FatPoint tmp;
46 errorProp->transformPosAndErrors(where, tmp);
47 outPoint.vx = tmp.vx;
48 outPoint.vy = tmp.vy;
49 outPoint.vxy = tmp.vxy;
50}
51
52void SimpleAstrometryMapping::positionDerivative(Point const &where, Eigen::Matrix2d &derivative,
53 double epsilon) const {
54 errorProp->computeDerivative(where, *lin, epsilon);
55 derivative(0, 0) = lin->getCoefficient(1, 0, 0);
56 //
57 /* This does not work : it was proved by rotating the frame
58 see the compilation switch ROTATE_T2 in constrainedAstrometryModel.cc
59 derivative(1,0) = lin->getCoefficient(1,0,1);
60 derivative(0,1) = lin->getCoefficient(0,1,0);
61 */
62 derivative(1, 0) = lin->getCoefficient(0, 1, 0);
63 derivative(0, 1) = lin->getCoefficient(1, 0, 1);
64 derivative(1, 1) = lin->getCoefficient(0, 1, 1);
65}
66
68 Eigen::MatrixX2d &H) const {
69 transformPosAndErrors(where, outPoint);
70 transform->paramDerivatives(where, &H(0, 0), &H(0, 1));
71}
72
74
76 AstrometryTransformPolynomial const &transform)
77 : SimpleAstrometryMapping(transform), _centerAndScale(std::move(CenterAndScale)) {
78 // We assume that the initialization was done properly, for example that
79 // transform = pixToTangentPlane*CenterAndScale.inverted(), so we do not touch transform.
80 /* store the (spatial) derivative of _centerAndScale. For the extra
81 diagonal terms, just copied the ones in positionDerivatives */
82 preDer(0, 0) = _centerAndScale.getCoefficient(1, 0, 0);
83 preDer(1, 0) = _centerAndScale.getCoefficient(0, 1, 0);
84 preDer(0, 1) = _centerAndScale.getCoefficient(1, 0, 1);
85 preDer(1, 1) = _centerAndScale.getCoefficient(0, 1, 1);
86
87 // check of matrix indexing (once for all)
88 MatrixX2d H(3, 2);
89 assert((&H(1, 0) - &H(0, 0)) == 1);
90}
91
92void SimplePolyMapping::positionDerivative(Point const &where, Eigen::Matrix2d &derivative,
93 double epsilon) const {
94 Point tmp = _centerAndScale.apply(where);
95 errorProp->computeDerivative(tmp, *lin, epsilon);
96 derivative(0, 0) = lin->getCoefficient(1, 0, 0);
97 //
98 /* This does not work : it was proved by rotating the frame
99 see the compilation switch ROTATE_T2 in constrainedAstrometryModel.cc
100 derivative(1,0) = lin->getCoefficient(1,0,1);
101 derivative(0,1) = lin->getCoefficient(0,1,0);
102 */
103 derivative(1, 0) = lin->getCoefficient(0, 1, 0);
104 derivative(0, 1) = lin->getCoefficient(1, 0, 1);
105 derivative(1, 1) = lin->getCoefficient(0, 1, 1);
106 derivative = preDer * derivative;
107}
108
110 Eigen::MatrixX2d &H) const {
111 FatPoint mid;
112 _centerAndScale.transformPosAndErrors(where, mid);
113 transform->transformPosAndErrors(mid, outPoint);
114 FatPoint tmp;
115 errorProp->transformPosAndErrors(mid, tmp);
116 outPoint.vx = tmp.vx;
117 outPoint.vy = tmp.vy;
118 outPoint.vxy = tmp.vxy;
119 transform->paramDerivatives(mid, &H(0, 0), &H(0, 1));
120}
121
122void SimplePolyMapping::transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const {
123 FatPoint mid;
124 _centerAndScale.transformPosAndErrors(where, mid);
125 transform->transformPosAndErrors(mid, outPoint);
126 FatPoint tmp;
127 errorProp->transformPosAndErrors(mid, tmp);
128 outPoint.vx = tmp.vx;
129 outPoint.vy = tmp.vy;
130 outPoint.vxy = tmp.vxy;
131}
132
134 // Cannot fail given the contructor:
135 const auto *fittedPoly =
136 dynamic_cast<const AstrometryTransformPolynomial *>(&(*transform));
137 actualResult = (*fittedPoly) * _centerAndScale;
138 return actualResult;
139}
140
141} // namespace jointcal
142} // namespace lsst
Eigen::Matrix< double, Eigen::Dynamic, 2 > MatrixX2d
Definition: Eigenstuff.h:33
table::Key< int > transform
a virtual (interface) class for geometric transformations.
implements the linear transformations (6 real coefficients).
void apply(double xIn, double yIn, double &xOut, double &yOut) const override
double getCoefficient(std::size_t powX, std::size_t powY, std::size_t whichCoord) const
Get the coefficient of a given power in x and y, for either the x or y coordinate.
virtual void transformPosAndErrors(const FatPoint &in, FatPoint &out) const override
a mix of apply and Derivative
A Point with uncertainties.
Definition: FatPoint.h:34
A point in a plane.
Definition: Point.h:37
Class for a simple mapping implementing a generic AstrometryTransform.
std::shared_ptr< AstrometryTransform > errorProp
void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint, Eigen::MatrixX2d &H) const override
Actually applies the AstrometryMapping and evaluates the derivatives w.r.t the fitted parameters.
void print(std::ostream &out) const override
Print a string representation of the contents of this mapping, for debugging.
std::size_t getNpar() const override
Number of parameters in total.
std::shared_ptr< AstrometryTransform > transform
void getMappingIndices(IndexVector &indices) const override
Sets how this set of parameters (of length Npar()) map into the "grand" fit Expects that indices has ...
std::unique_ptr< AstrometryTransformLinear > lin
void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const override
The same as above but without the parameter derivatives (used to evaluate chi^2)
void positionDerivative(Point const &where, Eigen::Matrix2d &derivative, double epsilon) const override
The derivative w.r.t. position.
void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint, Eigen::MatrixX2d &H) const override
Calls the transforms and implements the centering and scaling of coordinates.
void positionDerivative(Point const &where, Eigen::Matrix2d &derivative, double epsilon) const override
The derivative w.r.t. position.
SimplePolyMapping(AstrometryTransformLinear CenterAndScale, AstrometryTransformPolynomial const &transform)
The transformation will be initialized to transform, so that the effective transformation reads trans...
AstrometryTransform const & getTransform() const override
Access to the (fitted) transform.
void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const override
The same as above but without the parameter derivatives (used to evaluate chi^2)
T move(T... args)
STL namespace.
T resize(T... args)
T size(T... args)