LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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 <iostream>
29 #include <iterator> // for std::ostream_iterator
30 #include <algorithm> // for swap
31 #include <string>
32 #include <list>
33 
34 #include "lsst/jointcal/Point.h"
35 #include "lsst/jointcal/BaseStar.h" // class definition used in inlined functions
36 #include "lsst/jointcal/AstrometryTransform.h" // inlined function calls AstrometryTransform::apply()
37 
38 namespace lsst {
39 namespace jointcal {
40 
52 
54 class StarMatch {
55  friend class StarMatchList;
56 
57 public:
58  /* if one sets that private, then fitting routines will be a nightmare. we could set all the Transform
59  * classes friend... */
63  double distance;
64  double chi2;
65 
67 
71  : point1(point1), point2(point2), s1(std::move(star1)), s2(std::move(star2)), distance(0.){};
72 
73  // the next one would require that StarMatch knows BaseStar which is not mandatory for StarMatch to work
74  // StarMatch(BaseStar *star1, BaseStar *star2) : point1(*star1), point2(*star2), s1(star1), s2(star2) {};
75 
78  return point2.Distance(transform.apply(point1));
79  };
80 
82  double computeChi2(const AstrometryTransform &transform) const;
83 
87  double getDistance() const { return distance; }
88 
89  void swap() {
91  std::swap(s1, s2);
92  }
93 
94  /* comparison that ensures that after a sort, duplicates are next one another */
95  explicit StarMatch(){};
96 
97  friend std::ostream &operator<<(std::ostream &stream, const StarMatch &Match);
98 
100 
101 private:
102  // bool operator < (const StarMatch & other) const { return (s1 > other.s1) ? s1 > other.s1 : s2 >
103  // other.s2;}
104 
105  /* for unique to remove duplicates */
106  bool operator==(const StarMatch &other) const { return (s1 == other.s1 && s2 == other.s2); };
107  bool operator!=(const StarMatch &other) const { return (s1 != other.s1 || s2 != other.s2); };
108 
109  friend bool compareStar1(const StarMatch &one, const StarMatch &two);
110  friend bool sameStar1(const StarMatch &one, const StarMatch &two);
111  friend bool compareStar2(const StarMatch &one, const StarMatch &two);
112  friend bool sameStar2(const StarMatch &one, const StarMatch &two);
113 };
114 
115 inline bool compareStar1(const StarMatch &one, const StarMatch &two) {
116  return ((one.s1 == two.s1) ? (one.distance < two.distance) : (&(*one.s1) > &(*two.s1)));
117 }
118 
119 inline bool sameStar1(const StarMatch &one, const StarMatch &two) { return (one.s1 == two.s1); }
120 
121 inline bool compareStar2(const StarMatch &one, const StarMatch &two) {
122  return ((one.s2 == two.s2) ? (one.distance < two.distance) : (&(*one.s2) > &(*two.s2)));
123 }
124 
125 inline bool sameStar2(const StarMatch &one, const StarMatch &two) { return (one.s2 == two.s2); }
126 
127 /* =================================== StarMatchList
128  * ============================================================ */
129 
130 std::ostream &operator<<(std::ostream &stream, const StarMatch &match);
131 
132 //#ifdef TO_BE_FIXED
133 typedef ::std::list<StarMatch>::iterator StarMatchIterator;
134 typedef ::std::list<StarMatch>::const_iterator StarMatchCIterator;
135 //#endif
136 
138 
147 std::ostream &operator<<(std::ostream &stream, const StarMatchList &starMatchList);
148 
149 class StarMatchList : public std::list<StarMatch> {
150 public:
151  void refineTransform(double nSigmas);
152 
155  void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform,
156  const AstrometryTransform *posteriorTransform = nullptr) const;
157 
158  /* constructor */
159  StarMatchList() : _order(0), _chi2(0){};
160 
162 
165 
167  double getDist2() const { return _dist2; }
168 
170  double getChi2() const { return _chi2; }
171 
173  int getTransformOrder() const { return _order; }
174 
176  void swap();
177 
179  double computeResidual() const;
180 
184  unsigned removeAmbiguities(const AstrometryTransform &transform, int which = 3);
185 
187  void setTransform(const AstrometryTransform *transform) { _transform = transform->clone(); }
189  void setTransform(const AstrometryTransform &transform) { _transform = transform.clone(); }
191 
193  void setTransformOrder(int order);
194 
198 
201 
203  void cutTail(int nKeep);
204 
206  int recoveredNumber(double mindist) const;
207 
209  void printTransform(std::ostream &stream = std::cout) const;
210 
211  ~StarMatchList(){/* should delete the transform.... or use counted refs*/};
212 
213 private:
214  StarMatchList(const StarMatchList &); // copies nor properly handled
215  void operator=(const StarMatchList &);
216 
217  int _order;
218  double _chi2;
219  double _dist2;
221 };
222 
224 double computeDist2(const StarMatchList &S, const AstrometryTransform &transform);
225 
227 double computeChi2(const StarMatchList &L, const AstrometryTransform &transform);
228 } // namespace jointcal
229 } // namespace lsst
230 
231 #endif // LSST_JOINTCAL_STAR_MATCH_H
lsst::jointcal::StarMatch::point2
FatPoint point2
2 points
Definition: StarMatch.h:60
lsst::jointcal::StarMatch::StarMatch
StarMatch(const FatPoint &point1, const FatPoint &point2, std::shared_ptr< const BaseStar > star1, std::shared_ptr< const BaseStar > star2)
constructor.
Definition: StarMatch.h:69
lsst::jointcal::StarMatch::setDistance
void setDistance(const AstrometryTransform &transform)
to be used before sorting on distances.
Definition: StarMatch.h:85
std::shared_ptr
STL class.
lsst::jointcal::StarMatchList::removeAmbiguities
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:145
lsst::jointcal::StarMatch::sameStar1
friend bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:119
lsst::jointcal::StarMatchList::setTransform
void setTransform(std::shared_ptr< AstrometryTransform > transform)
Definition: StarMatch.h:190
std::list
STL class.
std::move
T move(T... args)
lsst::jointcal::StarMatchList::getTransform
std::shared_ptr< const AstrometryTransform > getTransform() const
carries out a fit with outlier rejection
Definition: StarMatch.h:164
AstrometryTransform.h
lsst::jointcal::StarMatch::swap
void swap()
Definition: StarMatch.h:89
lsst::jointcal::computeChi2
double computeChi2(const StarMatchList &L, const AstrometryTransform &transform)
the actual chi2
Definition: StarMatch.cc:246
lsst::jointcal::StarMatchList::StarMatchList
StarMatchList()
Definition: StarMatch.h:159
lsst::jointcal::StarMatch::chi2
double chi2
Definition: StarMatch.h:64
lsst::jointcal::StarMatch::compareStar2
friend bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:121
lsst::jointcal::StarMatchList::recoveredNumber
int recoveredNumber(double mindist) const
count the number of elements for which distance is < mindist
Definition: StarMatch.cc:205
lsst::jointcal::StarMatchList::printTransform
void printTransform(std::ostream &stream=std::cout) const
print the matching transformation quality (transform, chi2, residual)
Definition: StarMatch.cc:230
lsst::jointcal::StarMatch::computeChi2
double computeChi2(const AstrometryTransform &transform) const
returns the chi2 (using errors in the FatPoint's)
Definition: StarMatch.cc:44
lsst::jointcal::StarMatchIterator
::std::list< StarMatch >::iterator StarMatchIterator
Definition: StarMatch.h:133
lsst::jointcal::StarMatchList::computeResidual
double computeResidual() const
returns the average 1d Residual (last call to refineTransform)
Definition: StarMatch.cc:136
lsst::jointcal::StarMatch::s1
std::shared_ptr< const BaseStar > s1
Definition: StarMatch.h:62
lsst::jointcal::StarMatchList::setTransform
void setTransform(const AstrometryTransform &transform)
Definition: StarMatch.h:189
lsst::jointcal::StarMatchList::cutTail
void cutTail(int nKeep)
deletes the tail of the match std::list
Definition: StarMatch.cc:191
Point.h
lsst::jointcal::StarMatch::getDistance
double getDistance() const
returns the value computed by the above one.
Definition: StarMatch.h:87
lsst::jointcal::StarMatchList::swap
void swap()
swaps elements 1 and 2 of each starmatch in std::list.
Definition: StarMatch.cc:199
lsst::jointcal::compareStar2
bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:121
lsst::jointcal::StarMatchList::setDistance
void setDistance(const AstrometryTransform &transform)
Sets the distance (residual) field of all std::list elements. Mandatory before sorting on distances.
Definition: StarMatch.cc:141
lsst::jointcal::StarMatchList::applyTransform
void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform, const AstrometryTransform *posteriorTransform=nullptr) const
enables to get a transformed StarMatchList.
Definition: StarMatch.cc:214
lsst::jointcal::StarMatchList::setTransform
void setTransform(const AstrometryTransform *transform)
sets a transform between the 2 std::lists and deletes the previous or default one....
Definition: StarMatch.h:187
std::ostream
STL class.
lsst::jointcal::StarMatch::computeDistance
double computeDistance(const AstrometryTransform &transform) const
returns the distance from transform(point1) to point2.
Definition: StarMatch.h:77
lsst::jointcal::operator<<
std::ostream & operator<<(std::ostream &stream, AstrometryMapping const &mapping)
Definition: AstrometryMapping.h:78
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::jointcal::StarMatch::s2
std::shared_ptr< const BaseStar > s2
Definition: StarMatch.h:62
lsst::jointcal::StarMatchList::setTransformOrder
void setTransformOrder(int order)
set transform according to the given order.
Definition: StarMatch.cc:160
lsst::jointcal::StarMatchList::getDist2
double getDist2() const
access to the sum of squared residuals of the last call to refineTransform.
Definition: StarMatch.h:167
lsst::jointcal
Definition: Associations.h:49
lsst::jointcal::Point::Distance
double Distance(const Point &other) const
Definition: Point.h:50
lsst::jointcal::FatPoint
A Point with uncertainties.
Definition: FatPoint.h:34
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
std::swap
T swap(T... args)
lsst::jointcal::StarMatch::operator<<
friend std::ostream & operator<<(std::ostream &stream, const StarMatch &Match)
Definition: StarMatch.cc:56
lsst::jointcal::compareStar1
bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:115
lsst::jointcal::StarMatchList
Definition: StarMatch.h:149
lsst::jointcal::StarMatchList::getTransformOrder
int getTransformOrder() const
returns the order of the used transform
Definition: StarMatch.h:173
BaseStar.h
lsst::jointcal::StarMatch::StarMatch
StarMatch()
Definition: StarMatch.h:95
lsst::jointcal::StarMatchList::~StarMatchList
~StarMatchList()
Definition: StarMatch.h:211
lsst::jointcal::sameStar2
bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:125
lsst::jointcal::StarMatch::compareStar1
friend bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:115
std
STL namespace.
lsst::jointcal::StarMatch::sameStar2
friend bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:125
transform
table::Key< int > transform
Definition: TransformMap.cc:299
lsst::jointcal::StarMatch::distance
double distance
Definition: StarMatch.h:63
lsst::jointcal::StarMatch::point1
FatPoint point1
Definition: StarMatch.h:60
lsst::jointcal::StarMatchCIterator
::std::list< StarMatch >::const_iterator StarMatchCIterator
Definition: StarMatch.h:134
lsst::jointcal::AstrometryTransform
a virtual (interface) class for geometric transformations.
Definition: AstrometryTransform.h:65
lsst::jointcal::StarMatchList::refineTransform
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:94
lsst::jointcal::StarMatchList::getChi2
double getChi2() const
access to the chi2 of the last call to refineTransform.
Definition: StarMatch.h:170
std::unique_ptr
STL class.
lsst::jointcal::StarMatchList::inverseTransform
std::unique_ptr< AstrometryTransform > inverseTransform()
returns the inverse transform (swap, fit(refineTransform) , and swap).
Definition: StarMatch.cc:174
lsst::jointcal::computeDist2
double computeDist2(const StarMatchList &S, const AstrometryTransform &transform)
sum of distance squared
Definition: StarMatch.cc:239
lsst::jointcal::sameStar1
bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:119
lsst::jointcal::StarMatch
A hanger for star associations.
Definition: StarMatch.h:54
lsst::jointcal::StarMatch::~StarMatch
~StarMatch()
Definition: StarMatch.h:99