LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
_functionLibrary.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 #include <memory>
23 
24 #include <pybind11/pybind11.h>
25 #include <lsst/utils/python.h>
26 
27 #include <pybind11/stl.h>
28 
29 #include "lsst/geom/Box.h"
30 #include "lsst/geom/Point.h"
31 
33 #include "lsst/afw/math/Function.h"
34 
35 namespace py = pybind11;
36 using namespace pybind11::literals;
37 
39 
40 namespace lsst {
41 namespace afw {
42 namespace math {
43 
44 template <typename ReturnT>
46  /* PolynomialFunction1 */
47 
48  wrappers.wrapType(
50  Function1<ReturnT>>(wrappers.module, ("PolynomialFunction1" + suffix).c_str()),
51  [](auto &mod, auto &cls) {
52  cls.def(py::init<std::vector<double> const &>(), "params"_a);
53  cls.def(py::init<unsigned int>(), "order"_a);
54 
55  cls.def("__call__", &PolynomialFunction1<ReturnT>::operator(), "x"_a);
56  cls.def("clone", &PolynomialFunction1<ReturnT>::clone);
57  cls.def("isLinearCombination", &PolynomialFunction1<ReturnT>::isLinearCombination);
58  cls.def("getOrder", &PolynomialFunction1<ReturnT>::getOrder);
59  cls.def("toString", &PolynomialFunction1<ReturnT>::toString, "prefix"_a = "");
60  });
61  /* PolynomialFunction2 */
64  ("PolynomialFunction2" + suffix).c_str()),
65  [](auto &mod, auto &cls) {
66  cls.def(py::init<std::vector<double> const &>(), "params"_a);
67  cls.def(py::init<unsigned int>(), "order"_a);
68 
69  cls.def("__call__", &PolynomialFunction2<ReturnT>::operator(), "x"_a, "y"_a);
70  cls.def("clone", &PolynomialFunction2<ReturnT>::clone);
71  cls.def("getOrder", &PolynomialFunction2<ReturnT>::getOrder);
72  cls.def("getDFuncDParameters", &PolynomialFunction2<ReturnT>::getDFuncDParameters);
73  cls.def("toString", &PolynomialFunction2<ReturnT>::toString, "prefix"_a = "");
74  cls.def("isPersistable", &PolynomialFunction2<ReturnT>::isPersistable);
75  });
76 };
77 
78 template <typename ReturnT>
80  /* Chebyshev1Function1 */
81 
82  wrappers.wrapType(
84  Function1<ReturnT>>(wrappers.module, ("Chebyshev1Function1" + suffix).c_str()),
85  [](auto &mod, auto &cls) {
86  cls.def(py::init<std::vector<double>, double, double>(), "params"_a, "minX"_a = -1,
87  "maxX"_a = 1);
88  cls.def(py::init<unsigned int, double, double>(), "order"_a, "minX"_a = -1, "maxX"_a = 1);
89 
90  cls.def("__call__", &Chebyshev1Function1<ReturnT>::operator(), "x"_a);
91  cls.def("clone", &Chebyshev1Function1<ReturnT>::clone);
92  cls.def("getMinX", &Chebyshev1Function1<ReturnT>::getMinX);
93  cls.def("getMaxX", &Chebyshev1Function1<ReturnT>::getMaxX);
94  cls.def("getOrder", &Chebyshev1Function1<ReturnT>::getOrder);
95  cls.def("isLinearCombination", &Chebyshev1Function1<ReturnT>::isLinearCombination);
96  cls.def("toString", &Chebyshev1Function1<ReturnT>::toString, "prefix"_a = "");
97 
98  /* Chebyshev1Function2 */
99  });
102  ("Chebyshev1Function2" + suffix).c_str()),
103  [](auto &mod, auto &cls) {
104  cls.def(py::init<std::vector<double>, lsst::geom::Box2D const &>(), "params"_a,
105  "xyRange"_a = lsst::geom::Box2D(lsst::geom::Point2D(-1.0, -1.0),
106  lsst::geom::Point2D(1.0, 1.0)));
107  cls.def(py::init<unsigned int, lsst::geom::Box2D const &>(), "order"_a,
108  "xyRange"_a = lsst::geom::Box2D(lsst::geom::Point2D(-1.0, -1.0),
109  lsst::geom::Point2D(1.0, 1.0)));
110 
111  cls.def("__call__", &Chebyshev1Function2<ReturnT>::operator(), "x"_a, "y"_a);
112  cls.def("clone", &Chebyshev1Function2<ReturnT>::clone);
113  cls.def("getXYRange", &Chebyshev1Function2<ReturnT>::getXYRange);
114  cls.def("truncate", &Chebyshev1Function2<ReturnT>::truncate, "order"_a);
115  cls.def("toString", &Chebyshev1Function2<ReturnT>::toString, "prefix"_a = "");
116  cls.def("isPersistable", &Chebyshev1Function2<ReturnT>::isPersistable);
117  });
118 };
119 
120 template <typename ReturnT>
122  /* GaussianFunction1 */
124  Function1<ReturnT>>(wrappers.module, ("GaussianFunction1" + suffix).c_str()),
125  [](auto &mod, auto &cls) {
126  cls.def(py::init<double>(), "sigma"_a);
127 
128  cls.def("__call__", &GaussianFunction1<ReturnT>::operator(), "x"_a);
129  cls.def("clone", &GaussianFunction1<ReturnT>::clone);
130  cls.def("toString", &GaussianFunction1<ReturnT>::toString, "prefix"_a = "");
131  });
132 
134  Function2<ReturnT>>(wrappers.module, ("GaussianFunction2" + suffix).c_str()),
135  [](auto &mod, auto &cls) {
136  /* GaussianFunction2 */
137 
138  cls.def(py::init<double, double, double>(), "sigma1"_a, "sigma2"_a,
139  "angle"_a = 0.0);
140 
141  cls.def("__call__", &GaussianFunction2<ReturnT>::operator(), "x"_a, "y"_a);
142  cls.def("clone", &GaussianFunction2<ReturnT>::clone);
143  cls.def("toString", &GaussianFunction2<ReturnT>::toString, "prefix"_a = "");
144  cls.def("isPersistable", &GaussianFunction2<ReturnT>::isPersistable);
145  });
146  /* DoubleGaussianFunction2 */
147 
148  wrappers.wrapType(
150  Function2<ReturnT>>(wrappers.module, ("DoubleGaussianFunction2" + suffix).c_str()),
151  [](auto &mod, auto &cls) {
152  cls.def(py::init<double, double, double>(), "sigma1"_a, "sigma2"_a = 0, "ampl"_a = 0);
153 
154  cls.def("__call__", &DoubleGaussianFunction2<ReturnT>::operator(), "x"_a, "y"_a);
155  cls.def("clone", &DoubleGaussianFunction2<ReturnT>::clone);
156  cls.def("toString", &DoubleGaussianFunction2<ReturnT>::toString, "prefix"_a = "");
157  cls.def("isPersistable", &DoubleGaussianFunction2<ReturnT>::isPersistable);
158  });
159 };
160 
161 template <typename ReturnT>
163  const std::string &suffix) {
164  /* IntegerDeltaFunction1 */
165 
166  wrappers.wrapType(
168  Function1<ReturnT>>(wrappers.module, ("IntegerDeltaFunction1" + suffix).c_str()),
169  [](auto &mod, auto &cls) {
170  cls.def(py::init<double>(), "xo"_a);
171 
172  cls.def("__call__", &IntegerDeltaFunction1<ReturnT>::operator(), "x"_a);
173  cls.def("clone", &IntegerDeltaFunction1<ReturnT>::clone);
174  cls.def("toString", &IntegerDeltaFunction1<ReturnT>::toString, "prefix"_a = "");
175  });
176  /* IntegerDeltaFunction2 */
177 
178  wrappers.wrapType(
180  Function2<ReturnT>>(wrappers.module, ("IntegerDeltaFunction2" + suffix).c_str()),
181  [](auto &mod, auto &cls) {
182  cls.def(py::init<double, double>(), "xo"_a, "yo"_a);
183 
184  cls.def("__call__", &IntegerDeltaFunction2<ReturnT>::operator(), "x"_a, "y"_a);
185  cls.def("clone", &IntegerDeltaFunction2<ReturnT>::clone);
186  cls.def("toString", &IntegerDeltaFunction2<ReturnT>::toString, "prefix"_a = "");
187  });
188 };
189 
190 template <typename ReturnT>
192  /* LanczosFunction1 */
193 
195  Function1<ReturnT>>(wrappers.module, ("LanczosFunction1" + suffix).c_str()),
196  [](auto &mod, auto &cls) {
197  cls.def(py::init<unsigned int, double>(), "n"_a, "xOffset"_a = 0.0);
198 
199  cls.def("__call__", &LanczosFunction1<ReturnT>::operator(), "x"_a);
200  cls.def("clone", &LanczosFunction1<ReturnT>::clone);
201  cls.def("getOrder", &LanczosFunction1<ReturnT>::getOrder);
202  cls.def("toString", &LanczosFunction1<ReturnT>::toString, "prefix"_a = "");
203  });
204  /* LanczosFunction2 */
205 
207  Function2<ReturnT>>(wrappers.module, ("LanczosFunction2" + suffix).c_str()),
208  [](auto &mod, auto &cls) {
209  /* LanczosFunction2 */
210  cls.def(py::init<unsigned int, double, double>(), "n"_a, "xOffset"_a = 0.0,
211  "yOffset"_a = 0.0);
212 
213  cls.def("__call__", &LanczosFunction2<ReturnT>::operator(), "x"_a, "y"_a);
214  cls.def("clone", &LanczosFunction2<ReturnT>::clone);
215  cls.def("getOrder", &LanczosFunction2<ReturnT>::getOrder);
216  cls.def("toString", &LanczosFunction2<ReturnT>::toString, "prefix"_a = "");
217  });
218 };
219 
221  wrappers.addInheritanceDependency("lsst.geom");
222  declarePolynomialFunctions<float>(wrappers, "F");
223  declareChebyshevFunctions<float>(wrappers, "F");
224  declareGaussianFunctions<float>(wrappers, "F");
225  declareIntegerDeltaFunctions<float>(wrappers, "F");
226  declareLanczosFunctions<float>(wrappers, "F");
227 
228  declarePolynomialFunctions<double>(wrappers, "D");
229  declareChebyshevFunctions<double>(wrappers, "D");
230  declareGaussianFunctions<double>(wrappers, "D");
231  declareIntegerDeltaFunctions<double>(wrappers, "D");
232  declareLanczosFunctions<double>(wrappers, "D");
233 }
234 
235 } // namespace math
236 } // namespace afw
237 } // namespace lsst
PYBIND11_DECLARE_HOLDER_TYPE(MyType, std::shared_ptr< MyType >)
Base class for 2-dimensional polynomials of the form:
Definition: Function.h:326
1-dimensional weighted sum of Chebyshev polynomials of the first kind.
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
double Guassian (sum of two Gaussians)
A Function taking one argument.
Definition: Function.h:202
A Function taking two arguments.
Definition: Function.h:259
1-dimensional integer delta function.
2-dimensional integer delta function.
1-dimensional Lanczos function
2-dimensional separable Lanczos function
1-dimensional polynomial function.
2-dimensional polynomial function with cross terms
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition: python.h:242
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition: python.h:448
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
Definition: python.h:391
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
Definition: python.h:343
void declareChebyshevFunctions(lsst::utils::python::WrapperCollection &wrappers, const std::string &suffix)
void declarePolynomialFunctions(lsst::utils::python::WrapperCollection &wrappers, const std::string &suffix)
void declareIntegerDeltaFunctions(lsst::utils::python::WrapperCollection &wrappers, const std::string &suffix)
void declareGaussianFunctions(lsst::utils::python::WrapperCollection &wrappers, const std::string &suffix)
void wrapFunctionLibrary(lsst::utils::python::WrapperCollection &wrappers)
void declareLanczosFunctions(lsst::utils::python::WrapperCollection &wrappers, const std::string &suffix)
A base class for image defects.