LSSTApplications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
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
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())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
Definition: Match.cc:158
lsst::afw::table._match.second
second
Definition: _match.py:76
lsst::meas::astrom::sip::MatchSrcToCatalogue::findMatches
void findMatches()
Definition: MatchSrcToCatalogue.cc:74
wcs
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
std::vector< ReferenceMatch >
std::vector::size
T size(T... args)
lsst::afw::table._match.first
first
Definition: _match.py:74
SkyWcs.h
lsst::afw::geom::SkyWcs
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
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
Angle.h
MatchSrcToCatalogue.h
lsst::afw::table._source.SourceCatalog
Definition: _source.py:32
lsst.pex::exceptions::LogicError
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
std::vector::erase
T erase(T... args)
lsst::afw::table::CatalogIterator
Iterator class for CatalogT.
Definition: Catalog.h:39
lsst::afw::table._match.distance
distance
Definition: _match.py:78
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::meas::astrom::sip::MatchSrcToCatalogue::setCatSrcSet
void setCatSrcSet(afw::table::SimpleCatalog const &catSet)
Definition: MatchSrcToCatalogue.cc:72
lsst.pex::exceptions::InvalidParameterError
Reports invalid arguments.
Definition: Runtime.h:66
std::vector::begin
T begin(T... args)
lsst::geom::Angle
A class representing an angle.
Definition: Angle.h:127
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
CONST_PTR
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
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
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition: SortedCatalog.h:42
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