LSSTApplications  20.0.0
LSSTDataManagementBasePackage
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
lsst::afw::math::GaussianFunction1
1-dimensional Gaussian
Definition: FunctionLibrary.h:147
Box.h
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::math::Chebyshev1Function2
2-dimensional weighted sum of Chebyshev polynomials of the first kind.
Definition: FunctionLibrary.h:719
std::vector< double >
FunctionLibrary.h
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::math::IntegerDeltaFunction1
1-dimensional integer delta function.
Definition: FunctionLibrary.h:52
lsst::afw::math::BasePolynomialFunction2
Base class for 2-dimensional polynomials of the form:
Definition: Function.h:326
lsst::afw::math::LanczosFunction2
2-dimensional separable Lanczos function
Definition: FunctionLibrary.h:992
lsst::afw::math::GaussianFunction2
2-dimensional Gaussian
Definition: FunctionLibrary.h:201
lsst::afw::math::PYBIND11_MODULE
PYBIND11_MODULE(functionLibrary, mod)
Definition: functionLibrary.cc:200
lsst::afw::math::Chebyshev1Function1
1-dimensional weighted sum of Chebyshev polynomials of the first kind.
Definition: FunctionLibrary.h:582
lsst::afw::math::declareLanczosFunctions
void declareLanczosFunctions(py::module &mod, const std::string &suffix)
Definition: functionLibrary.cc:175
lsst::afw::math::IntegerDeltaFunction2
2-dimensional integer delta function.
Definition: FunctionLibrary.h:99
lsst::afw::math::LanczosFunction1
1-dimensional Lanczos function
Definition: FunctionLibrary.h:927
lsst::afw::math::declareIntegerDeltaFunctions
void declareIntegerDeltaFunctions(py::module &mod, const std::string &suffix)
Definition: functionLibrary.cc:150
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::math::PolynomialFunction1
1-dimensional polynomial function.
Definition: FunctionLibrary.h:371
lsst::afw::math::Function2
A Function taking two arguments.
Definition: Function.h:259
lsst::afw::math::DoubleGaussianFunction2
double Guassian (sum of two Gaussians)
Definition: FunctionLibrary.h:305
lsst::afw::math::declareGaussianFunctions
void declareGaussianFunctions(py::module &mod, const std::string &suffix)
Definition: functionLibrary.cc:113
PYBIND11_DECLARE_HOLDER_TYPE
PYBIND11_DECLARE_HOLDER_TYPE(MyType, std::shared_ptr< MyType >)
lsst::afw::math::declarePolynomialFunctions
void declarePolynomialFunctions(py::module &mod, const std::string &suffix)
Definition: functionLibrary.cc:43
lsst::geom::Point< double, 2 >
pybind11
Definition: _GenericMap.cc:40
Point.h
lsst::afw::math::declareChebyshevFunctions
void declareChebyshevFunctions(py::module &mod, const std::string &suffix)
Definition: functionLibrary.cc:75
lsst::afw::math::PolynomialFunction2
2-dimensional polynomial function with cross terms
Definition: FunctionLibrary.h:449
lsst::geom::Box2D
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
lsst::utils.tests.init
def init()
Definition: tests.py:58
lsst::afw::math::Function1
A Function taking one argument.
Definition: Function.h:202
Function.h
lsst::meas::modelfit.psf.psfContinued.module
module
Definition: psfContinued.py:42