39template <
typename RecordT>
51template <
typename Record1,
typename Record2>
52bool operator<(RecordPos<Record1>
const &s1, RecordPos<Record2>
const &s2) {
53 return (s1.dec < s2.dec);
58 return s1->getY() < s2->getY();
72template <
typename Cat>
73size_t makeRecordPositions(Cat
const &cat, RecordPos<typename Cat::Record> *positions) {
75 Key<lsst::geom::Angle> raKey = Cat::Table::getCoordKey().getRa();
76 Key<lsst::geom::Angle> decKey = Cat::Table::getCoordKey().getDec();
77 for (
typename Cat::const_iterator i(cat.begin()), e(cat.end()); i != e; ++i) {
84 positions[n].dec =
dec.asRadians();
85 positions[n].x =
std::cos(ra) * cosDec;
86 positions[n].y =
std::sin(ra) * cosDec;
93 LOGLS_WARN(
"lsst.afw.table.matchRaDec",
"At least one source had ra or dec equal to NaN");
98template size_t makeRecordPositions(SimpleCatalog
const &, RecordPos<SimpleRecord> *);
99template size_t makeRecordPositions(SourceCatalog
const &, RecordPos<SourceRecord> *);
101template <
typename Cat1,
typename Cat2>
102bool doSelfMatchIfSame(
std::vector<Match<typename Cat1::Record, typename Cat2::Record> > &result,
108template <
typename Cat>
109bool doSelfMatchIfSame(
std::vector<Match<typename Cat::Record, typename Cat::Record> > &result,
111 if (&cat1 == &cat2) {
127 return 2. * (1. -
std::cos(theta.asRadians()));
146template <
typename Cat1,
typename Cat2>
157template <
typename Cat1,
typename Cat2>
170 if (
cat1.size() == 0 ||
cat2.size() == 0) {
188 for (
size_t i = 0, start = 0;
i <
len1; ++
i) {
207 if (
mc.findOnlyClosest) {
220 if (
mc.findOnlyClosest && found) {
228#define LSST_MATCH_RADEC(RTYPE, C1, C2) \
229 template RTYPE matchRaDec(C1 const &, C2 const &, lsst::geom::Angle, bool); \
230 template RTYPE matchRaDec(C1 const &, C2 const &, lsst::geom::Angle, MatchControl const &)
236#undef LSST_MATCH_RADEC
238template <
typename Cat>
248template <
typename Cat>
258 if (
cat.size() == 0) {
270 for (
size_t i = 0;
i <
len; ++
i) {
280 if (
mc.symmetricMatch) {
289#define LSST_MATCH_RADEC(RTYPE, C) \
290 template RTYPE matchRaDec(C const &, lsst::geom::Angle, bool); \
291 template RTYPE matchRaDec(C const &, lsst::geom::Angle, MatchControl const &)
296#undef LSST_MATCH_RADEC
311 double const r2 = radius * radius;
342 for (
size_t i = 0, start = 0;
i <
len1; ++
i) {
343 double y =
pos1[
i]->getY();
344 double minY =
y - radius;
351 double x =
pos1[
i]->getX();
352 double maxY =
y + radius;
363 if (
mc.findOnlyClosest) {
376 if (
mc.findOnlyClosest && found) {
392 double const r2 = radius * radius;
410 for (
size_t i = 0;
i <
len; ++
i) {
411 double x =
pos[
i]->getX();
412 double y =
pos[
i]->getY();
413 double maxY =
y + radius;
416 double dx =
x -
pos[
j]->getX();
422 if (
mc.symmetricMatch) {
431template <
typename Record1,
typename Record2>
438 result.getTable()->preallocate(
matches.size());
439 result.reserve(
matches.size());
443 record->set(
outKey1,
i->first->getId());
444 record->set(
outKey2,
i->second->getId());
445 record->set(
keyD,
i->distance);
454template <
typename Cat1,
typename Cat2>
464 "Catalogs passed to unpackMatches must be sorted.");
468 typename std::vector<MatchT>::iterator
j = result.
begin();
476 "Persisted match record with ID " <<
i->get(
inKey1) <<
" not found in catalog 1.");
482 "Persisted match record with ID " <<
i->get(
inKey2) <<
" not found in catalog 2.");
484 j->distance =
i->get(
keyD);
#define LSST_EXCEPT(type,...)
#define LOGLS_WARN(logger, message)
std::shared_ptr< RecordT > src
#define LSST_MATCH_RADEC(RTYPE, C1, C2)
Tag types used to declare specialized field types.
Pass parameters to algorithms that match list of sources.
Defines the fields and offsets for a table.
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
typename Base::const_iterator const_iterator
constexpr double asRadians() const noexcept
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > unpackMatches(BaseCatalog const &matches, Cat1 const &cat1, Cat2 const &cat2)
Reconstruct a MatchVector from a BaseCatalog representation of the matches and a pair of catalogs.
BaseCatalog packMatches(std::vector< Match< Record1, Record2 > > const &matches)
Return a table representation of a MatchVector that can be used to persist it.
Match< SourceRecord, SourceRecord > SourceMatch
SourceMatchVector matchXy(SourceCatalog const &cat1, SourceCatalog const &cat2, double 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...
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...
AngleUnit constexpr degrees
AngleUnit constexpr radians