LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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)