31#include "Eigen/Sparse"
56 double wxx = refStar.
vy / det;
57 double wyy = refStar.
vx / det;
58 double wxy = -refStar.
vxy / det;
59 return wxx *
std::pow(refStar.
x, 2) + 2 * wxy * refStar.
x * refStar.
y + wyy *
std::pow(refStar.
y, 2);
69 _astrometryModel(
std::
move(astrometryModel)),
70 _epoch(_associations->getEpoch()),
86 fittedStarInTP = sky2TP.
apply(fittedStar);
88 return fittedStarInTP;
94static void tweakAstromMeasurementErrors(FatPoint &P, MeasuredStar
const &Ms,
double error) {
95 static bool called =
false;
96 static double increment = 0;
143 Eigen::Matrix2d
transW(2, 2);
144 Eigen::Matrix2d alpha(2, 2);
150 for (
auto &
i : catalog) {
152 if (!
ms.isValid())
continue;
155 tweakAstromMeasurementErrors(
inPos,
ms, _posError);
159 if (_fittingDistortions)
167 LOGLS_WARN(
_log,
"Inconsistent measurement errors: drop measurement at "
178 alpha(1, 0) =
transW(0, 1) / alpha(0, 0);
226 if (
val == 0)
continue;
247 if (!_fittingPos)
return;
251 Eigen::Matrix2d
W(2, 2);
252 Eigen::Matrix2d alpha(2, 2);
253 Eigen::Matrix2d
H(2, 2),
halpha(2, 2),
HW(2, 2);
256 Eigen::Index indices[2];
265 for (
auto const &
i : fittedStarList) {
267 auto rs =
fs.getRefStar();
268 if (
rs ==
nullptr)
continue;
276 H(0, 0) = -
der.A11();
277 H(1, 0) = -
der.A12();
278 H(0, 1) = -
der.A21();
279 H(1, 1) = -
der.A22();
283 LOGLS_WARN(
_log,
"RefStar error matrix not positive definite for: " << *
rs);
291 alpha(0, 0) =
sqrt(
W(0, 0));
293 alpha(1, 0) =
W(0, 1) / alpha(0, 0);
294 alpha(1, 1) = 1. /
sqrt(
det *
W(0, 0));
296 indices[0] =
fs.getIndexInMatrix();
297 indices[1] =
fs.getIndexInMatrix() + 1;
315 for (
unsigned ic = 0;
ic < 2; ++
ic) {
317 if (
val == 0)
continue;
340 Eigen::Matrix2Xd
transW(2, 2);
342 auto &catalog =
ccdImage.getCatalogForFit();
343 for (
auto const &
ms : catalog) {
344 if (!
ms->isValid())
continue;
347 tweakAstromMeasurementErrors(
inPos, *
ms, _posError);
354 LOGLS_WARN(
_log,
" Inconsistent measurement errors :drop measurement at "
358 transW(0, 0) = outPos.
vy / det;
359 transW(1, 1) = outPos.
vx / det;
360 transW(0, 1) = transW(1, 0) = -outPos.
vxy / det;
363 Point fittedStarInTP = transformFittedStar(*fs, *sky2TP, deltaYears);
365 Eigen::Vector2d res(fittedStarInTP.x - outPos.
x, fittedStarInTP.y - outPos.
y);
366 double chi2Val = res.transpose() * transW * res;
373 for (
auto const &
ccdImage : ccdImageList) {
388 for (
auto const &
fs : fittedStarList) {
389 auto rs =
fs->getRefStar();
390 if (
rs ==
nullptr)
continue;
391 proj.setTangentPoint(*
fs);
405 if (_fittingDistortions) {
410 Eigen::Index
fsIndex =
fs->getIndexInMatrix();
426 _fittingDistortions = (
_whatToFit.
find(
"Distortions") != std::string::npos);
427 _fittingPos = (
_whatToFit.
find(
"Positions") != std::string::npos);
457 "AstrometryFit::offsetParams : the provided vector length is not compatible with "
458 "the current whatToFit setting");
459 if (_fittingDistortions) _astrometryModel->offsetParams(delta);
463 for (
auto const &
i : fittedStarList) {
468 Eigen::Index index =
fs.getIndexInMatrix();
469 fs.x += delta(index);
470 fs.y += delta(index + 1);
481 const char *
what2fit[] = {
"Positions",
"Distortions",
"Positions Distortions"};
521 ofile <<
"contribution to chi2 (2D dofs)" <<
separator <<
"number of measurements of this fittedStar"
526 for (
auto const &
ccdImage : ccdImageList) {
532 for (
auto const &
ms : cat) {
533 if (!
ms->isValid())
continue;
536 tweakAstromMeasurementErrors(
inPos, *
ms, _posError);
586 <<
"number of measurements of this FittedStar" <<
std::endl;
591 for (
auto const &
i : fittedStarList) {
593 auto rs =
fs.getRefStar();
594 if (
rs ==
nullptr)
continue;
Eigen::SparseMatrix< double, 0, Eigen::Index > SparseMatrixD
#define LSST_EXCEPT(type,...)
#define LOGLS_WARN(logger, message)
#define LOGLS_INFO(logger, message)
#define LOGLS_DEBUG(logger, message)
void checkStuff()
DEBUGGING routine.
void leastSquareDerivativesMeasurement(CcdImage const &ccdImage, TripletList &tripletList, Eigen::VectorXd &grad, MeasuredStarList const *msList=nullptr) const override
Compute the derivatives of the measured stars and model for one CcdImage.
void accumulateStatImageList(CcdImageList const &ccdImageList, Chi2Accumulator &accum) const override
Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for measurements.
void accumulateStatRefStars(Chi2Accumulator &accum) const override
Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for RefStars.
void saveChi2RefContributions(std::string const &filename) const override
Save a CSV file containing residuals of reference terms.
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by the requested quantities.
AstrometryFit(std::shared_ptr< Associations > associations, std::shared_ptr< AstrometryModel > astrometryModel, double posError)
this is the only constructor
void assignIndices(std::string const &whatToFit) override
Set parameters to fit and assign indices in the big matrix.
void leastSquareDerivativesReference(FittedStarList const &fittedStarList, TripletList &tripletList, Eigen::VectorXd &grad) const override
Compute the derivatives of the reference terms.
void getIndicesOfMeasuredStar(MeasuredStar const &measuredStar, IndexVector &indices) const override
this routine is to be used only in the framework of outlier removal
void saveChi2MeasContributions(std::string const &filename) const override
Save a CSV file containing residuals of measurement terms.
virtual class needed in the abstraction of the distortion model
virtual void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const =0
The same as above but without the parameter derivatives (used to evaluate chi^2)
virtual void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint, Eigen::MatrixX2d &H) const =0
Actually applies the AstrometryMapping and evaluates the derivatives w.r.t the fitted parameters.
virtual void getMappingIndices(IndexVector &indices) const =0
Sets how this set of parameters (of length Npar()) map into the "grand" fit Expects that indices has ...
virtual std::size_t getNpar() const =0
Number of parameters in total.
Handler of an actual image from a single CCD.
Base class for Chi2Statistic and Chi2List, to allow addEntry inside Fitter for either class.
virtual void addEntry(double inc, std::size_t dof, std::shared_ptr< BaseStar > star)=0
A Point with uncertainties.
FittedStars are objects whose position or flux is going to be fitted, and which come from the associa...
A list of FittedStar s. Such a list is typically constructed by Associations.
void leastSquareDerivatives(TripletList &tripletList, Eigen::VectorXd &grad) const
Evaluates the chI^2 derivatives (Jacobian and gradient) for the current whatToFit setting.
Eigen::Index _nModelParams
std::shared_ptr< Associations > _associations
Eigen::Index _nStarParams
Sources measured on images.
A list of MeasuredStar. They are usually filled in Associations::createCcdImage.
This one is the Tangent Plane (called gnomonic) projection (from celestial sphere to tangent plane)
std::unique_ptr< AstrometryTransform > compose(AstrometryTransform const &left, AstrometryTransform const &right)
Returns a pointer to a composition of transforms, representing left(right()).
T setprecision(T... args)