42 static double sq(
double x) {
return x *
x; }
50 double det = vxx * vyy - vxy * vxy;
63 stream <<
" number of elements " << starMatchList.
size() <<
std::endl;
70 unsigned s = starMatchList.
size();
73 for (
auto const &it : starMatchList) res[count++] = it.computeChi2(transform);
77 static unsigned chi2_cleanup(
StarMatchList &starMatchList,
const double chi2Cut,
80 for (
auto smi = starMatchList.
begin(); smi != starMatchList.
end();) {
81 if (smi->chi2 > chi2Cut) {
82 smi = starMatchList.
erase(smi);
104 _chi2 = _transform->fit(*
this);
114 if (_chi2 <= 0)
return;
115 unsigned npair = int(size());
116 if (npair == 0)
break;
121 for (
auto &starMatch : *
this)
122 chi2_array[count++] = starMatch.chi2 = starMatch.computeChi2(*_transform);
125 double median = (npair & 1) ? chi2_array[npair / 2]
126 : (chi2_array[npair / 2 - 1] + chi2_array[npair / 2]) * 0.5;
129 cut = sq(nSigmas) * median;
130 nremoved = chi2_cleanup(*
this, cut, *_transform);
137 int deno = (2. * size() - _transform->getNpar());
138 return (deno > 0) ?
sqrt(_dist2 / deno) : -1;
142 for (
auto &smi : *
this) smi.setDistance(transform);
146 if (!which)
return 0;
148 int initial_count = size();
157 return (initial_count - size());
162 setTransform(std::make_shared<AstrometryTransformLinearShift>());
164 setTransform(std::make_shared<AstrometryTransformLinear>());
175 if (!_transform)
return nullptr;
177 auto old_transform = _transform->clone();
178 double old_chi2 = _chi2;
181 setTransformOrder(_order);
183 auto inverted_transform = _transform->clone();
184 setTransform(old_transform.get());
188 return inverted_transform;
194 for (si =
begin(); si !=
end() && count < nKeep; ++count, ++si)
200 for (
auto &starMatch : *
this) {
208 for (
auto const &starMatch : *
this) {
209 if (starMatch.computeDistance(identity) < mindist) n++;
221 for (
auto const &starMatch : *
this) {
231 stream <<
" ================================================================" <<
std::endl 232 <<
" Transformation between lists of order " << getTransformOrder() <<
std::endl 234 <<
" Chi2 = " << getChi2() <<
" Residual = " << computeResidual() <<
std::endl 235 <<
" Number in the list = " << size() <<
std::endl 236 <<
" ================================================================" <<
std::endl;
241 for (
auto const &starMatch : starMatchList)
242 dist2 += transform.
apply(starMatch.point1).computeDist2(starMatch.point2);
247 unsigned s = starMatchList.
size();
250 for (
unsigned k = 0; k < s; ++k) chi2 += chi2s[k];
A hanger for star associations.
void setTransformOrder(int order)
set transform according to the given order.
double computeChi2(const AstrometryTransform &transform) const
returns the chi2 (using errors in the FatPoint's)
void setDistance(const AstrometryTransform &transform)
to be used before sorting on distances.
int recoveredNumber(double mindist) const
count the number of elements for which distance is < mindist
A Point with uncertainties.
std::unique_ptr< AstrometryTransform > inverseTransform()
returns the inverse transform (swap, fit(refineTransform) , and swap).
void refineTransform(double nSigmas)
removes pairs beyond nSigmas in distance (where the sigma scale is set by the fit) and iterates until...
A base class for image defects.
friend bool sameStar2(const StarMatch &one, const StarMatch &two)
unsigned removeAmbiguities(const AstrometryTransform &transform, int which=3)
cleans up the std::list of pairs for pairs that share one of their stars, keeping the closest one...
friend bool sameStar1(const StarMatch &one, const StarMatch &two)
void setDistance(const AstrometryTransform &transform)
Sets the distance (residual) field of all std::list elements. Mandatory before sorting on distances...
double computeResidual() const
returns the average 1d Residual (last call to refineTransform)
friend bool compareStar2(const StarMatch &one, const StarMatch &two)
void dumpTransform(std::ostream &stream=std::cout) const
print the matching transformation quality (transform, chi2, residual)
void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform, const AstrometryTransform *posteriorTransform=nullptr) const
enables to get a transformed StarMatchList.
double computeDist2(const StarMatchList &S, const AstrometryTransform &transform)
sum of distance squared
friend std::ostream & operator<<(std::ostream &stream, const StarMatch &Match)
friend bool compareStar1(const StarMatch &one, const StarMatch &two)
void swap()
swaps elements 1 and 2 of each starmatch in std::list.
void cutTail(int nKeep)
deletes the tail of the match std::list