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,
79 unsigned erased = starMatchList.removeAmbiguities(
transform);
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);
124 std::sort(chi2_array.get(), chi2_array.get() + npair);
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;
183 auto inverted_transform = _transform->clone();
188 return inverted_transform;
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
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 Point with uncertainties.
A hanger for star associations.
double computeChi2(const AstrometryTransform &transform) const
returns the chi2 (using errors in the FatPoint's)
std::unique_ptr< AstrometryTransform > inverseTransform()
returns the inverse transform (swap, fit(refineTransform) , and swap).
void setDistance(const AstrometryTransform &transform)
Sets the distance (residual) field of all std::list elements. Mandatory before sorting on distances.
void printTransform(std::ostream &stream=std::cout) const
print the matching transformation quality (transform, chi2, residual)
void swap()
swaps elements 1 and 2 of each starmatch in std::list.
double getChi2() const
access to the chi2 of the last call to refineTransform.
int getTransformOrder() const
returns the order of the used transform
void setTransform(const AstrometryTransform *transform)
sets a transform between the 2 std::lists and deletes the previous or default one....
int recoveredNumber(double mindist) const
count the number of elements for which distance is < mindist
void setTransformOrder(int order)
set transform according to the given order.
double computeResidual() const
returns the average 1d Residual (last call to refineTransform)
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.
void cutTail(int nKeep)
deletes the tail of the match std::list
void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform, const AstrometryTransform *posteriorTransform=nullptr) const
enables to get a transformed StarMatchList.
void refineTransform(double nSigmas)
removes pairs beyond nSigmas in distance (where the sigma scale is set by the fit) and iterates until...
StarMatch erase(StarMatch ... args)
bool compareStar1(const StarMatch &one, const StarMatch &two)
bool sameStar2(const StarMatch &one, const StarMatch &two)
bool sameStar1(const StarMatch &one, const StarMatch &two)
bool compareStar2(const StarMatch &one, const StarMatch &two)
double computeDist2(const StarMatchList &S, const AstrometryTransform &transform)
sum of distance squared
std::ostream & operator<<(std::ostream &stream, AstrometryMapping const &mapping)
double computeChi2(const StarMatchList &L, const AstrometryTransform &transform)
the actual chi2
A base class for image defects.
StarMatch unique(StarMatch ... args)