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
StarMatch.h
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#ifndef LSST_JOINTCAL_STAR_MATCH_H
26#define LSST_JOINTCAL_STAR_MATCH_H
27
28#include <algorithm> // for swap
29#include <iostream>
30#include <iterator> // for std::ostream_iterator
31#include <list>
32#include <string>
33#include <utility>
34
35#include "lsst/jointcal/Point.h"
36#include "lsst/jointcal/BaseStar.h" // class definition used in inlined functions
37#include "lsst/jointcal/AstrometryTransform.h" // inlined function calls AstrometryTransform::apply()
38
39namespace lsst {
40namespace jointcal {
41
53
55class StarMatch {
56 friend class StarMatchList;
57
58public:
59 /* if one sets that private, then fitting routines will be a nightmare. we could set all the Transform
60 * classes friend... */
64 double distance{};
65 double chi2{};
66
68
72 : point1(std::move(point1)), point2(std::move(point2)), s1(std::move(star1)), s2(std::move(star2)), distance(0.){};
73
74 // the next one would require that StarMatch knows BaseStar which is not mandatory for StarMatch to work
75 // StarMatch(BaseStar *star1, BaseStar *star2) : point1(*star1), point2(*star2), s1(star1), s2(star2) {};
76
78 double computeDistance(const AstrometryTransform &transform) const {
79 return point2.Distance(transform.apply(point1));
80 };
81
83 double computeChi2(const AstrometryTransform &transform) const;
84
88 double getDistance() const { return distance; }
89
90 void swap() {
92 std::swap(s1, s2);
93 }
94
95 /* comparison that ensures that after a sort, duplicates are next one another */
96 explicit StarMatch() = default;;
97
98 friend std::ostream &operator<<(std::ostream &stream, const StarMatch &Match);
99
100 ~StarMatch() = default;
101
102private:
103 // bool operator < (const StarMatch & other) const { return (s1 > other.s1) ? s1 > other.s1 : s2 >
104 // other.s2;}
105
106 /* for unique to remove duplicates */
107 bool operator==(const StarMatch &other) const { return (s1 == other.s1 && s2 == other.s2); };
108 bool operator!=(const StarMatch &other) const { return (s1 != other.s1 || s2 != other.s2); };
109
110 friend bool compareStar1(const StarMatch &one, const StarMatch &two);
111 friend bool sameStar1(const StarMatch &one, const StarMatch &two);
112 friend bool compareStar2(const StarMatch &one, const StarMatch &two);
113 friend bool sameStar2(const StarMatch &one, const StarMatch &two);
114};
115
116inline bool compareStar1(const StarMatch &one, const StarMatch &two) {
117 return ((one.s1 == two.s1) ? (one.distance < two.distance) : (&(*one.s1) > &(*two.s1)));
118}
119
120inline bool sameStar1(const StarMatch &one, const StarMatch &two) { return (one.s1 == two.s1); }
121
122inline bool compareStar2(const StarMatch &one, const StarMatch &two) {
123 return ((one.s2 == two.s2) ? (one.distance < two.distance) : (&(*one.s2) > &(*two.s2)));
124}
125
126inline bool sameStar2(const StarMatch &one, const StarMatch &two) { return (one.s2 == two.s2); }
127
128/* =================================== StarMatchList
129 * ============================================================ */
130
131std::ostream &operator<<(std::ostream &stream, const StarMatch &match);
132
133//#ifdef TO_BE_FIXED
136//#endif
137
139
148std::ostream &operator<<(std::ostream &stream, const StarMatchList &starMatchList);
149
150class StarMatchList : public std::list<StarMatch> {
151public:
152 void refineTransform(double nSigmas);
153
156 void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform,
157 const AstrometryTransform *posteriorTransform = nullptr) const;
158
159 /* constructor */
160 StarMatchList() : _order(0), _chi2(0){};
161
163
166
168 double getDist2() const { return _dist2; }
169
171 double getChi2() const { return _chi2; }
172
174 int getTransformOrder() const { return _order; }
175
177 void swap();
178
180 double computeResidual() const;
181
185 unsigned removeAmbiguities(const AstrometryTransform &transform, int which = 3);
186
188 void setTransform(const AstrometryTransform *transform) { _transform = transform->clone(); }
190 void setTransform(const AstrometryTransform &transform) { _transform = transform.clone(); }
192
194 void setTransformOrder(int order);
195
199
201 void setDistance(const AstrometryTransform &transform);
202
204 void cutTail(int nKeep);
205
207 int recoveredNumber(double mindist) const;
208
210 void printTransform(std::ostream &stream = std::cout) const;
211
212 ~StarMatchList() = default;
213 StarMatchList(const StarMatchList &) = delete; // copies not properly handled
214 void operator=(const StarMatchList &) = delete;
215
216private:
217 int _order;
218 double _chi2;
219 double _dist2{};
221};
222
224double computeDist2(const StarMatchList &S, const AstrometryTransform &transform);
225
227double computeChi2(const StarMatchList &L, const AstrometryTransform &transform);
228} // namespace jointcal
229} // namespace lsst
230
231#endif // LSST_JOINTCAL_STAR_MATCH_H
table::Key< int > transform
a virtual (interface) class for geometric transformations.
A Point with uncertainties.
Definition: FatPoint.h:34
double Distance(const Point &other) const
Definition: Point.h:51
A hanger for star associations.
Definition: StarMatch.h:55
double computeChi2(const AstrometryTransform &transform) const
returns the chi2 (using errors in the FatPoint's)
Definition: StarMatch.cc:43
std::shared_ptr< const BaseStar > s1
Definition: StarMatch.h:63
std::shared_ptr< const BaseStar > s2
Definition: StarMatch.h:63
StarMatch(FatPoint point1, FatPoint point2, std::shared_ptr< const BaseStar > star1, std::shared_ptr< const BaseStar > star2)
constructor.
Definition: StarMatch.h:70
friend std::ostream & operator<<(std::ostream &stream, const StarMatch &Match)
Definition: StarMatch.cc:55
void setDistance(const AstrometryTransform &transform)
to be used before sorting on distances.
Definition: StarMatch.h:86
friend bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:126
double computeDistance(const AstrometryTransform &transform) const
returns the distance from transform(point1) to point2.
Definition: StarMatch.h:78
double getDistance() const
returns the value computed by the above one.
Definition: StarMatch.h:88
friend bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:122
FatPoint point2
2 points
Definition: StarMatch.h:61
friend bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:120
friend bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:116
void operator=(const StarMatchList &)=delete
std::unique_ptr< AstrometryTransform > inverseTransform()
returns the inverse transform (swap, fit(refineTransform) , and swap).
Definition: StarMatch.cc:172
void setDistance(const AstrometryTransform &transform)
Sets the distance (residual) field of all std::list elements. Mandatory before sorting on distances.
Definition: StarMatch.cc:139
void setTransform(const AstrometryTransform &transform)
Definition: StarMatch.h:190
void printTransform(std::ostream &stream=std::cout) const
print the matching transformation quality (transform, chi2, residual)
Definition: StarMatch.cc:228
void swap()
swaps elements 1 and 2 of each starmatch in std::list.
Definition: StarMatch.cc:197
double getChi2() const
access to the chi2 of the last call to refineTransform.
Definition: StarMatch.h:171
void setTransform(std::shared_ptr< AstrometryTransform > transform)
Definition: StarMatch.h:191
int getTransformOrder() const
returns the order of the used transform
Definition: StarMatch.h:174
std::shared_ptr< const AstrometryTransform > getTransform() const
carries out a fit with outlier rejection
Definition: StarMatch.h:165
StarMatchList(const StarMatchList &)=delete
void setTransform(const AstrometryTransform *transform)
sets a transform between the 2 std::lists and deletes the previous or default one....
Definition: StarMatch.h:188
int recoveredNumber(double mindist) const
count the number of elements for which distance is < mindist
Definition: StarMatch.cc:203
void setTransformOrder(int order)
set transform according to the given order.
Definition: StarMatch.cc:158
double computeResidual() const
returns the average 1d Residual (last call to refineTransform)
Definition: StarMatch.cc:134
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.
Definition: StarMatch.cc:143
double getDist2() const
access to the sum of squared residuals of the last call to refineTransform.
Definition: StarMatch.h:168
void cutTail(int nKeep)
deletes the tail of the match std::list
Definition: StarMatch.cc:189
void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform, const AstrometryTransform *posteriorTransform=nullptr) const
enables to get a transformed StarMatchList.
Definition: StarMatch.cc:212
void refineTransform(double nSigmas)
removes pairs beyond nSigmas in distance (where the sigma scale is set by the fit) and iterates until...
Definition: StarMatch.cc:92
T move(T... args)
bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:116
bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:126
::std::list< StarMatch >::iterator StarMatchIterator
Definition: StarMatch.h:134
bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:120
bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:122
::std::list< StarMatch >::const_iterator StarMatchCIterator
Definition: StarMatch.h:135
double computeDist2(const StarMatchList &S, const AstrometryTransform &transform)
sum of distance squared
Definition: StarMatch.cc:237
double computeChi2(const StarMatchList &L, const AstrometryTransform &transform)
the actual chi2
Definition: StarMatch.cc:244
std::ostream & operator<<(std::ostream &stream, AstrometryMapping const &mapping)
STL namespace.
T swap(T... args)
table::Key< int > order