LSST Applications  21.0.0+c4f5df5339,21.0.0+e70536a077,21.0.0-1-ga51b5d4+7c60f8a6ea,21.0.0-10-gcf60f90+74aa0801fd,21.0.0-12-g63909ac9+643a1044a5,21.0.0-15-gedb9d5423+1041c3824f,21.0.0-2-g103fe59+a356b2badb,21.0.0-2-g1367e85+6d3f3f41db,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+6d3f3f41db,21.0.0-2-g7f82c8f+8d7c04eab9,21.0.0-2-g8f08a60+9c9a9cfcc8,21.0.0-2-ga326454+8d7c04eab9,21.0.0-2-gde069b7+bedfc5e1fb,21.0.0-2-gecfae73+6cb6558258,21.0.0-2-gfc62afb+6d3f3f41db,21.0.0-3-g21c7a62+f6e98b25aa,21.0.0-3-g357aad2+bd62456bea,21.0.0-3-g4be5c26+6d3f3f41db,21.0.0-3-g65f322c+03a4076c01,21.0.0-3-g7d9da8d+c4f5df5339,21.0.0-3-gaa929c8+c6b98066dc,21.0.0-3-gc44e71e+a26d5c1aea,21.0.0-3-ge02ed75+04b527a9d5,21.0.0-35-g64f566ff+b27e5ef93e,21.0.0-4-g591bb35+04b527a9d5,21.0.0-4-g88306b8+8773047b2e,21.0.0-4-gc004bbf+80a0b7acb7,21.0.0-4-gccdca77+a5c54364a0,21.0.0-4-ge8fba5a+ccfc328107,21.0.0-5-gdf36809+87b8d260e6,21.0.0-6-g00874e7+7eeda2b6ba,21.0.0-6-g2d4f3f3+e70536a077,21.0.0-6-g4e60332+04b527a9d5,21.0.0-6-g5ef7dad+f53629abd8,21.0.0-7-gc8ca178+b63e69433b,21.0.0-8-gfbe0b4b+c6b98066dc,w.2021.06
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 <pybind11/stl.h>
26 
27 #include "lsst/geom/Box.h"
28 #include "lsst/geom/Point.h"
29 
31 #include "lsst/afw/math/Function.h"
32 
33 namespace py = pybind11;
34 using namespace pybind11::literals;
35 
37 
38 namespace lsst {
39 namespace afw {
40 namespace math {
41 
42 template <typename ReturnT>
44  /* PolynomialFunction1 */
45  py::class_<PolynomialFunction1<ReturnT>, std::shared_ptr<PolynomialFunction1<ReturnT>>,
47  clsPolynomialFunction1(mod, ("PolynomialFunction1" + suffix).c_str());
48 
49  clsPolynomialFunction1.def(py::init<std::vector<double> const &>(), "params"_a);
50  clsPolynomialFunction1.def(py::init<unsigned int>(), "order"_a);
51 
52  clsPolynomialFunction1.def("__call__", &PolynomialFunction1<ReturnT>::operator(), "x"_a);
53  clsPolynomialFunction1.def("clone", &PolynomialFunction1<ReturnT>::clone);
54  clsPolynomialFunction1.def("isLinearCombination", &PolynomialFunction1<ReturnT>::isLinearCombination);
55  clsPolynomialFunction1.def("getOrder", &PolynomialFunction1<ReturnT>::getOrder);
56  clsPolynomialFunction1.def("toString", &PolynomialFunction1<ReturnT>::toString, "prefix"_a = "");
57 
58  /* PolynomialFunction2 */
59  py::class_<PolynomialFunction2<ReturnT>, std::shared_ptr<PolynomialFunction2<ReturnT>>,
61  clsPolynomialFunction2(mod, ("PolynomialFunction2" + suffix).c_str());
62 
63  clsPolynomialFunction2.def(py::init<std::vector<double> const &>(), "params"_a);
64  clsPolynomialFunction2.def(py::init<unsigned int>(), "order"_a);
65 
66  clsPolynomialFunction2.def("__call__", &PolynomialFunction2<ReturnT>::operator(), "x"_a, "y"_a);
67  clsPolynomialFunction2.def("clone", &PolynomialFunction2<ReturnT>::clone);
68  clsPolynomialFunction2.def("getOrder", &PolynomialFunction2<ReturnT>::getOrder);
69  clsPolynomialFunction2.def("getDFuncDParameters", &PolynomialFunction2<ReturnT>::getDFuncDParameters);
70  clsPolynomialFunction2.def("toString", &PolynomialFunction2<ReturnT>::toString, "prefix"_a = "");
71  clsPolynomialFunction2.def("isPersistable", &PolynomialFunction2<ReturnT>::isPersistable);
72 };
73 
74 template <typename ReturnT>
76  /* Chebyshev1Function1 */
77  py::class_<Chebyshev1Function1<ReturnT>, std::shared_ptr<Chebyshev1Function1<ReturnT>>,
79  clsChebyshev1Function1(mod, ("Chebyshev1Function1" + suffix).c_str());
80 
81  clsChebyshev1Function1.def(py::init<std::vector<double>, double, double>(), "params"_a, "minX"_a = -1,
82  "maxX"_a = 1);
83  clsChebyshev1Function1.def(py::init<unsigned int, double, double>(), "order"_a, "minX"_a = -1,
84  "maxX"_a = 1);
85 
86  clsChebyshev1Function1.def("__call__", &Chebyshev1Function1<ReturnT>::operator(), "x"_a);
87  clsChebyshev1Function1.def("clone", &Chebyshev1Function1<ReturnT>::clone);
88  clsChebyshev1Function1.def("getMinX", &Chebyshev1Function1<ReturnT>::getMinX);
89  clsChebyshev1Function1.def("getMaxX", &Chebyshev1Function1<ReturnT>::getMaxX);
90  clsChebyshev1Function1.def("getOrder", &Chebyshev1Function1<ReturnT>::getOrder);
91  clsChebyshev1Function1.def("isLinearCombination", &Chebyshev1Function1<ReturnT>::isLinearCombination);
92  clsChebyshev1Function1.def("toString", &Chebyshev1Function1<ReturnT>::toString, "prefix"_a = "");
93 
94  /* Chebyshev1Function2 */
95  py::class_<Chebyshev1Function2<ReturnT>, std::shared_ptr<Chebyshev1Function2<ReturnT>>,
97  clsChebyshev1Function2(mod, ("Chebyshev1Function2" + suffix).c_str());
98 
99  clsChebyshev1Function2.def(py::init<std::vector<double>, lsst::geom::Box2D const &>(), "params"_a,
100  "xyRange"_a = lsst::geom::Box2D(lsst::geom::Point2D(-1.0, -1.0), lsst::geom::Point2D(1.0, 1.0)));
101  clsChebyshev1Function2.def(py::init<unsigned int, lsst::geom::Box2D const &>(), "order"_a,
102  "xyRange"_a = lsst::geom::Box2D(lsst::geom::Point2D(-1.0, -1.0), lsst::geom::Point2D(1.0, 1.0)));
103 
104  clsChebyshev1Function2.def("__call__", &Chebyshev1Function2<ReturnT>::operator(), "x"_a, "y"_a);
105  clsChebyshev1Function2.def("clone", &Chebyshev1Function2<ReturnT>::clone);
106  clsChebyshev1Function2.def("getXYRange", &Chebyshev1Function2<ReturnT>::getXYRange);
107  clsChebyshev1Function2.def("truncate", &Chebyshev1Function2<ReturnT>::truncate, "order"_a);
108  clsChebyshev1Function2.def("toString", &Chebyshev1Function2<ReturnT>::toString, "prefix"_a = "");
109  clsChebyshev1Function2.def("isPersistable", &Chebyshev1Function2<ReturnT>::isPersistable);
110 };
111 
112 template <typename ReturnT>
114  /* GaussianFunction1 */
115  py::class_<GaussianFunction1<ReturnT>, std::shared_ptr<GaussianFunction1<ReturnT>>, Function1<ReturnT>>
116  clsGaussianFunction1(mod, ("GaussianFunction1" + suffix).c_str());
117 
118  clsGaussianFunction1.def(py::init<double>(), "sigma"_a);
119 
120  clsGaussianFunction1.def("__call__", &GaussianFunction1<ReturnT>::operator(), "x"_a);
121  clsGaussianFunction1.def("clone", &GaussianFunction1<ReturnT>::clone);
122  clsGaussianFunction1.def("toString", &GaussianFunction1<ReturnT>::toString, "prefix"_a = "");
123 
124  /* GaussianFunction2 */
125  py::class_<GaussianFunction2<ReturnT>, std::shared_ptr<GaussianFunction2<ReturnT>>, Function2<ReturnT>>
126  clsGaussianFunction2(mod, ("GaussianFunction2" + suffix).c_str());
127 
128  clsGaussianFunction2.def(py::init<double, double, double>(), "sigma1"_a, "sigma2"_a, "angle"_a = 0.0);
129 
130  clsGaussianFunction2.def("__call__", &GaussianFunction2<ReturnT>::operator(), "x"_a, "y"_a);
131  clsGaussianFunction2.def("clone", &GaussianFunction2<ReturnT>::clone);
132  clsGaussianFunction2.def("toString", &GaussianFunction2<ReturnT>::toString, "prefix"_a = "");
133  clsGaussianFunction2.def("isPersistable", &GaussianFunction2<ReturnT>::isPersistable);
134 
135  /* DoubleGaussianFunction2 */
136  py::class_<DoubleGaussianFunction2<ReturnT>, std::shared_ptr<DoubleGaussianFunction2<ReturnT>>,
138  clsDoubleGaussianFunction2(mod, ("DoubleGaussianFunction2" + suffix).c_str());
139 
140  clsDoubleGaussianFunction2.def(py::init<double, double, double>(), "sigma1"_a, "sigma2"_a = 0,
141  "ampl"_a = 0);
142 
143  clsDoubleGaussianFunction2.def("__call__", &DoubleGaussianFunction2<ReturnT>::operator(), "x"_a, "y"_a);
144  clsDoubleGaussianFunction2.def("clone", &DoubleGaussianFunction2<ReturnT>::clone);
145  clsDoubleGaussianFunction2.def("toString", &DoubleGaussianFunction2<ReturnT>::toString, "prefix"_a = "");
146  clsDoubleGaussianFunction2.def("isPersistable", &DoubleGaussianFunction2<ReturnT>::isPersistable);
147 };
148 
149 template <typename ReturnT>
151  /* IntegerDeltaFunction1 */
152  py::class_<IntegerDeltaFunction1<ReturnT>, std::shared_ptr<IntegerDeltaFunction1<ReturnT>>,
154  clsIntegerDeltaFunction1(mod, ("IntegerDeltaFunction1" + suffix).c_str());
155 
156  clsIntegerDeltaFunction1.def(py::init<double>(), "xo"_a);
157 
158  clsIntegerDeltaFunction1.def("__call__", &IntegerDeltaFunction1<ReturnT>::operator(), "x"_a);
159  clsIntegerDeltaFunction1.def("clone", &IntegerDeltaFunction1<ReturnT>::clone);
160  clsIntegerDeltaFunction1.def("toString", &IntegerDeltaFunction1<ReturnT>::toString, "prefix"_a = "");
161 
162  /* IntegerDeltaFunction2 */
163  py::class_<IntegerDeltaFunction2<ReturnT>, std::shared_ptr<IntegerDeltaFunction2<ReturnT>>,
165  clsIntegerDeltaFunction2(mod, ("IntegerDeltaFunction2" + suffix).c_str());
166 
167  clsIntegerDeltaFunction2.def(py::init<double, double>(), "xo"_a, "yo"_a);
168 
169  clsIntegerDeltaFunction2.def("__call__", &IntegerDeltaFunction2<ReturnT>::operator(), "x"_a, "y"_a);
170  clsIntegerDeltaFunction2.def("clone", &IntegerDeltaFunction2<ReturnT>::clone);
171  clsIntegerDeltaFunction2.def("toString", &IntegerDeltaFunction2<ReturnT>::toString, "prefix"_a = "");
172 };
173 
174 template <typename ReturnT>
175 void declareLanczosFunctions(py::module &mod, const std::string &suffix) {
176  /* LanczosFunction1 */
177  py::class_<LanczosFunction1<ReturnT>, std::shared_ptr<LanczosFunction1<ReturnT>>, Function1<ReturnT>>
178  clsLanczosFunction1(mod, ("LanczosFunction1" + suffix).c_str());
179 
180  clsLanczosFunction1.def(py::init<unsigned int, double>(), "n"_a, "xOffset"_a = 0.0);
181 
182  clsLanczosFunction1.def("__call__", &LanczosFunction1<ReturnT>::operator(), "x"_a);
183  clsLanczosFunction1.def("clone", &LanczosFunction1<ReturnT>::clone);
184  clsLanczosFunction1.def("getOrder", &LanczosFunction1<ReturnT>::getOrder);
185  clsLanczosFunction1.def("toString", &LanczosFunction1<ReturnT>::toString, "prefix"_a = "");
186 
187  /* LanczosFunction2 */
188  py::class_<LanczosFunction2<ReturnT>, std::shared_ptr<LanczosFunction2<ReturnT>>, Function2<ReturnT>>
189  clsLanczosFunction2(mod, ("LanczosFunction2" + suffix).c_str());
190 
191  clsLanczosFunction2.def(py::init<unsigned int, double, double>(), "n"_a, "xOffset"_a = 0.0,
192  "yOffset"_a = 0.0);
193 
194  clsLanczosFunction2.def("__call__", &LanczosFunction2<ReturnT>::operator(), "x"_a, "y"_a);
195  clsLanczosFunction2.def("clone", &LanczosFunction2<ReturnT>::clone);
196  clsLanczosFunction2.def("getOrder", &LanczosFunction2<ReturnT>::getOrder);
197  clsLanczosFunction2.def("toString", &LanczosFunction2<ReturnT>::toString, "prefix"_a = "");
198 };
199 
200 PYBIND11_MODULE(functionLibrary, mod) {
201  py::module::import("lsst.geom");
202  py::module::import("lsst.afw.math.function");
203 
204  declarePolynomialFunctions<float>(mod, "F");
205  declareChebyshevFunctions<float>(mod, "F");
206  declareGaussianFunctions<float>(mod, "F");
207  declareIntegerDeltaFunctions<float>(mod, "F");
208  declareLanczosFunctions<float>(mod, "F");
209 
210  declarePolynomialFunctions<double>(mod, "D");
211  declareChebyshevFunctions<double>(mod, "D");
212  declareGaussianFunctions<double>(mod, "D");
213  declareIntegerDeltaFunctions<double>(mod, "D");
214  declareLanczosFunctions<double>(mod, "D");
215 }
216 
217 } // namespace math
218 } // namespace afw
219 } // namespace lsst
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 floating-point coordinate rectangle geometry.
Definition: Box.h:413
PYBIND11_MODULE(functionLibrary, mod)
void declareLanczosFunctions(py::module &mod, const std::string &suffix)
void declareIntegerDeltaFunctions(py::module &mod, const std::string &suffix)
void declareChebyshevFunctions(py::module &mod, const std::string &suffix)
void declareGaussianFunctions(py::module &mod, const std::string &suffix)
void declarePolynomialFunctions(py::module &mod, const std::string &suffix)
def init()
Definition: tests.py:59
A base class for image defects.
PYBIND11_DECLARE_HOLDER_TYPE(MyType, std::shared_ptr< MyType >)