LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
MatchSrcToCatalogue.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
26 #include "lsst/geom/Angle.h"
27 #include "lsst/afw/geom/SkyWcs.h"
28 
29 namespace lsst {
30 namespace meas {
31 namespace astrom {
32 namespace sip {
33 
50  afw::table::SourceCatalog const& imgSet,
52  setImgSrcSet(imgSet);
53  setCatSrcSet(catSet);
54  setDist(dist);
55  setWcs(wcs);
56 }
57 
60  if (dist <= 0) {
61  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Distance must be > 0");
62  }
63  _dist = dist;
64 }
65 
68 
70 void MatchSrcToCatalogue::setImgSrcSet(afw::table::SourceCatalog const& srcSet) { _imgSet = srcSet; }
71 
72 void MatchSrcToCatalogue::setCatSrcSet(afw::table::SimpleCatalog const& srcSet) { _catSet = srcSet; }
73 
75  if (!_imgSet.getTable()->getCentroidSlot().isValid()) {
77  "SourceTable passed to MatchSrcToCatalogue does not have its centroid slot set.");
78  }
79 
80  for (afw::table::SourceCatalog::const_iterator i = _imgSet.begin(); i != _imgSet.end(); ++i) {
81  i->updateCoord(*_wcs);
82  }
83 
84  _match = afw::table::matchRaDec(_catSet, _imgSet, _dist);
85 
86  _removeOneToMany();
87  _removeManyToOne();
88 }
89 
93 void MatchSrcToCatalogue::_removeOneToMany() {
94  std::size_t size = _match.size();
95  for (std::size_t i = 0; i < size; ++i) {
96  for (std::size_t j = i + 1; j < size; ++j) {
97  // If the same Source appears twice keep the one with the smaller separation from its match
98  if (_match[i].first == _match[j].first) {
99  // Keep the one with the shorter match distance, and disgard the other
100  if (_match[i].distance < _match[j].distance) {
101  _match.erase(_match.begin() + j);
102  size--;
103  j--;
104  } else {
105  _match.erase(_match.begin() + i);
106  size--;
107  i--;
108  break;
109  }
110  }
111  }
112  }
113 }
114 
117 void MatchSrcToCatalogue::_removeManyToOne() {
118  std::size_t size = _match.size();
119  for (std::size_t i = 0; i < size; ++i) {
120  for (std::size_t j = i + 1; j < size; ++j) {
121  // If the same Source appears twice
122  if (_match[i].second == _match[j].second) {
123  // Keep the one with the shorter match distance, and disgard the other
124  if (_match[i].distance < _match[j].distance) {
125  _match.erase(_match.begin() + j);
126  size--;
127  j--;
128  } else {
129  _match.erase(_match.begin() + i);
130  size--;
131  i--;
132  break;
133  }
134  }
135  }
136  }
137 }
138 
140  findMatches();
141  return _match;
142 }
143 
144 } // namespace sip
145 } // namespace astrom
146 } // namespace meas
147 } // namespace lsst
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:66
T begin(T... args)
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition: SortedCatalog.h:42
typename Base::const_iterator const_iterator
Definition: SortedCatalog.h:50
A class representing an angle.
Definition: Angle.h:127
void setWcs(std::shared_ptr< afw::geom::SkyWcs const > wcs)
Set a different Wcs solution.
afw::table::ReferenceMatchVector getMatches()
void setDist(geom::Angle dist)
Set a new value for the maximum allowed distance between two matching objects (in ra/dec space)
MatchSrcToCatalogue(afw::table::SimpleCatalog const &catSet, afw::table::SourceCatalog const &imgSet, std::shared_ptr< afw::geom::SkyWcs const > wcs, geom::Angle dist)
Create a list of common objects from a catalogue and an image.
void setCatSrcSet(afw::table::SimpleCatalog const &catSet)
void setImgSrcSet(afw::table::SourceCatalog const &srcSet)
sourceSet is a vector of pointers to Sources.
Reports invalid arguments.
Definition: Runtime.h:66
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
T erase(T... args)
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, lsst::geom::Angle radius, MatchControl const &mc=MatchControl())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
Definition: Match.cc:158
A base class for image defects.
T size(T... args)