LSSTApplications  18.1.0
LSSTDataManagementBasePackage
match.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
25 
26 #include "lsst/pex/config/python.h" // for LSST_DECLARE_CONTROL_FIELD
27 #include "lsst/afw/table/Simple.h"
28 #include "lsst/afw/table/Source.h"
29 #include "lsst/afw/table/Match.h"
30 
31 namespace py = pybind11;
32 using namespace pybind11::literals;
33 
34 namespace lsst {
35 namespace afw {
36 namespace table {
37 namespace {
38 
40 template <typename Catalog1, typename Catalog2>
41 void declareMatch2(py::module &mod, std::string const &prefix) {
42  typedef typename Catalog1::Record Record1;
43  typedef typename Catalog2::Record Record2;
45 
46  using Class = Match<Record1, Record2>;
47  py::class_<Class, std::shared_ptr<Class>> clsMatch(mod, (prefix + "Match").c_str());
48  clsMatch.def(py::init<>());
49  clsMatch.def(py::init<std::shared_ptr<Record1> const &, std::shared_ptr<Record2> const &, double>(),
50  "first"_a, "second"_a, "distance"_a);
51 
52  // struct fields
53  clsMatch.def_readwrite("first", &Match<Record1, Record2>::first);
54  clsMatch.def_readwrite("second", &Match<Record1, Record2>::second);
55  clsMatch.def_readwrite("distance", &Match<Record1, Record2>::distance);
56 
57  // Free Functions
58  mod.def("unpackMatches", &unpackMatches<Catalog1, Catalog2>, "matches"_a, "cat1"_a, "cat2"_a);
59 
60  mod.def("matchRaDec", (MatchList(*)(Catalog1 const &, Catalog2 const &, lsst::geom::Angle,
61  MatchControl const &))matchRaDec<Catalog1, Catalog2>,
62  "cat1"_a, "cat2"_a, "radius"_a, "mc"_a = MatchControl());
63  // The following is deprecated; consider changing the code instead of wrapping it:
64  // mod.def("matchRaDec",
65  // (MatchList (*)(Catalog1 const &, Catalog2 const &, lsst::geom::Angle, bool))
66  // matchRaDec<Catalog1, Catalog2>, "cat1"_a, "cat2"_a, "radius"_a, "closest"_a);
67 };
68 
70 template <typename Catalog>
71 void declareMatch1(py::module &mod) {
73  mod.def("matchRaDec",
74  (MatchList(*)(Catalog const &, lsst::geom::Angle, MatchControl const &))matchRaDec<Catalog>,
75  "cat"_a, "radius"_a, "mc"_a = MatchControl());
76  // The following is deprecated; consider changing the code instead of wrapping it:
77  // mod.def("matchRaDec",
78  // (MatchList (*)(Catalog const &, lsst::geom::Angle, bool))
79  // &matchRaDec<Catalog1>, "cat"_a, "radius"_a, "symmetric"_a);
80 }
81 
82 } // <anonymous>
83 
84 PYBIND11_MODULE(match, mod) {
85  py::class_<MatchControl> clsMatchControl(mod, "MatchControl");
86  clsMatchControl.def(py::init<>());
87  LSST_DECLARE_CONTROL_FIELD(clsMatchControl, MatchControl, findOnlyClosest);
88  LSST_DECLARE_CONTROL_FIELD(clsMatchControl, MatchControl, symmetricMatch);
89  LSST_DECLARE_CONTROL_FIELD(clsMatchControl, MatchControl, includeMismatches);
90 
91  declareMatch2<SimpleCatalog, SimpleCatalog>(mod, "Simple");
92  declareMatch2<SimpleCatalog, SourceCatalog>(mod, "Reference");
93  declareMatch2<SourceCatalog, SourceCatalog>(mod, "Source");
94  declareMatch1<SimpleCatalog>(mod);
95  declareMatch1<SourceCatalog>(mod);
96 
97  mod.def("matchXy", (SourceMatchVector(*)(SourceCatalog const &, SourceCatalog const &, double,
98  MatchControl const &))matchXy,
99  "cat1"_a, "cat2"_a, "radius"_a, "mc"_a = MatchControl());
100  mod.def("matchXy", (SourceMatchVector(*)(SourceCatalog const &, double, MatchControl const &))matchXy,
101  "cat"_a, "radius"_a, "mc"_a = MatchControl());
102  // The following are deprecated; consider changing the code instead of wrapping them:
103  // mod.def("matchXy",
104  // (SourceMatchVector (*)(SourceCatalog const &, SourceCatalog const &, double, bool))
105  // matchXy, "cat1"_a, "cat2"_a, "radius"_a, "closest"_a);
106  // mod.def("matchXy",
107  // (SourceMatchVector (*)(SourceCatalog const &, double, bool))
108  // &matchXy, "cat"_a, "radius"_a, "symmetric"_a);
109 }
110 }
111 }
112 } // namespace lsst::afw::table::<anonymous>
def init()
Definition: tests.py:75
std::string prefix
Definition: SchemaMapper.cc:79
A class representing an angle.
Definition: Angle.h:127
STL class.
Pass parameters to algorithms that match list of sources.
Definition: Match.h:45
PYBIND11_MODULE(match, mod)
Definition: match.cc:84
A base class for image defects.
#define LSST_DECLARE_CONTROL_FIELD(WRAPPER, CLASS, NAME)
Macro used to wrap fields declared by LSST_CONTROL_FIELD using Pybind11.
Definition: python.h:43
STL class.
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...
Definition: Match.cc:305
std::vector< SourceMatch > SourceMatchVector
Definition: fwd.h:109