LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
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
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
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)
A base class for image defects.
STL namespace.
T swap(T... args)
table::Key< int > order