lsst.meas.astrom  20.0.0-1-gc96f8cb+16
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()->hasCentroidSlot()) {
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
lsst::afw::table::matchRaDec
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, lsst::geom::Angle radius, MatchControl const &mc=MatchControl())
lsst::meas::astrom::sip::MatchSrcToCatalogue::findMatches
void findMatches()
Definition: MatchSrcToCatalogue.cc:74
CONST_PTR
#define CONST_PTR(...)
wcs
table::Key< table::Array< std::uint8_t > > wcs
std::vector< ReferenceMatch >
std::vector::size
T size(T... args)
lsst::afw::table::SortedCatalogT::const_iterator
Base::const_iterator const_iterator
lsst::afw::geom::SkyWcs
SkyWcs.h
lsst::meas::astrom::sip::MatchSrcToCatalogue::MatchSrcToCatalogue
MatchSrcToCatalogue(afw::table::SimpleCatalog const &catSet, afw::table::SourceCatalog const &imgSet, boost::shared_ptr< afw::geom::SkyWcs const > wcs, geom::Angle dist)
Create a list of common objects from a catalogue and an image.
Definition: MatchSrcToCatalogue.cc:49
lsst::meas::astrom::sip::MatchSrcToCatalogue::getMatches
afw::table::ReferenceMatchVector getMatches()
Definition: MatchSrcToCatalogue.cc:139
MatchSrcToCatalogue.h
lsst::pex::exceptions::LogicError
std::vector::erase
T erase(T... args)
Angle.h
lsst
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
lsst::meas::astrom::sip::MatchSrcToCatalogue::setCatSrcSet
void setCatSrcSet(afw::table::SimpleCatalog const &catSet)
Definition: MatchSrcToCatalogue.cc:72
lsst::pex::exceptions::InvalidParameterError
std::vector::begin
T begin(T... args)
lsst::geom::Angle
lsst::meas::astrom::sip::MatchSrcToCatalogue::setDist
void setDist(geom::Angle dist)
Set a new value for the maximum allowed distance between two matching objects (in ra/dec space)
Definition: MatchSrcToCatalogue.cc:59
std::size_t
lsst::meas::astrom::sip::MatchSrcToCatalogue::setImgSrcSet
void setImgSrcSet(afw::table::SourceCatalog const &srcSet)
sourceSet is a vector of pointers to Sources.
Definition: MatchSrcToCatalogue.cc:70
lsst::afw::table::SortedCatalogT
lsst::meas::astrom::sip::MatchSrcToCatalogue::setWcs
void setWcs(boost::shared_ptr< afw::geom::SkyWcs const > wcs)
Set a different Wcs solution.
Definition: MatchSrcToCatalogue.cc:67