lsst.meas.base  13.0-33-gb1a1d47+3
python.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * See COPYRIGHT file at the top of the source tree.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_MEAS_BASE_PYTHON_H
25 #define LSST_MEAS_BASE_PYTHON_H
26 
27 #include "pybind11/pybind11.h"
28 
29 #include <string>
30 
31 #include "lsst/afw/image/Calib.h"
32 #include "lsst/afw/image/Wcs.h"
33 #include "lsst/afw/table/fwd.h"
34 #include "lsst/afw/table/Schema.h"
35 #include "lsst/afw/table/SchemaMapper.h"
36 
37 namespace lsst {
38 namespace meas {
39 namespace base {
40 namespace python {
41 
42 namespace py = pybind11;
43 using namespace pybind11::literals;
44 
53 template <class Algorithm, class PyAlg>
54 typename std::enable_if<!std::is_abstract<Algorithm>::value, void>::type declareAlgorithmConstructor(PyAlg & cls) {
55  cls.def(py::init<typename Algorithm::Control const &,
56  std::string const &,
57  afw::table::Schema &>(),
58  "ctrl"_a, "name"_a, "schema"_a);
59 }
71 template <class Algorithm, class PyAlg>
72 typename std::enable_if<std::is_abstract<Algorithm>::value, void>::type declareAlgorithmConstructor(PyAlg & cls) {
73 }
74 
86 template <class Algorithm, class PyAlg>
87 void declareAlgorithm(PyAlg & clsAlgorithm) {
88  /* Member types and enums */
89 
90  /* Constructors */
91  declareAlgorithmConstructor<Algorithm>(clsAlgorithm);
92 
93  /* Operators */
94 
95  /* Members */
96  clsAlgorithm.def("fail", &Algorithm::fail, "measRecord"_a, "error"_a=NULL);
97  clsAlgorithm.def("measure", &Algorithm::measure, "record"_a, "exposure"_a);
98 }
99 
115 template <class Algorithm, class Control, class PyAlg, class PyCtrl>
116 void declareAlgorithm(PyAlg & clsAlgorithm, PyCtrl & clsControl) {
117  declareAlgorithm<Algorithm>(clsAlgorithm);
118 
119  /* Member types and enums */
120 
121  /* Constructors */
122  clsControl.def(py::init<>());
123 
124  /* Operators */
125 
126  /* Members */
127 }
128 
147 template <class Algorithm, class Control, class Transform, class PyAlg, class PyCtrl, class PyXform>
148 void declareAlgorithm(PyAlg & clsAlgorithm, PyCtrl & clsControl, PyXform & clsTransform) {
149  declareAlgorithm<Algorithm, Control>(clsAlgorithm, clsControl);
150 
151  /* Member types and enums */
152 
153  /* Constructors */
154  clsTransform.def(py::init<typename Transform::Control const &,
155  std::string const &,
156  afw::table::SchemaMapper &>(),
157  "ctrl"_a, "name"_a, "mapper"_a);
158 
159  /* Operators */
160  clsTransform.def("__call__", [](Transform const & self,
161  afw::table::SourceCatalog const & inputCatalog,
162  afw::table::BaseCatalog & outputCatalog,
163  afw::image::Wcs const & wcs,
164  afw::image::Calib const &calib) {
165  return self(inputCatalog, outputCatalog, wcs, calib);
166  }, "inputCatalog"_a, "outputCatalog"_a, "wcs"_a, "calib"_a);
167 
168  /* Members */
169 }
170 
171 }}}} // lsst::meas::base::
172 
173 #endif
174 
Definition: mainpage.dox:3
void declareAlgorithm(PyAlg &clsAlgorithm)
Wrap the implicit API used by meas_base&#39;s algorithms.
Definition: python.h:87
std::enable_if<!std::is_abstract< Algorithm >::value, void >::type declareAlgorithmConstructor(PyAlg &cls)
Wrap the standard algorithm constructor.
Definition: python.h:54