lsst.shapelet  13.0-5-gde6b2c8+14
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
shapeletFunction.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  *
4  * This product includes software developed by the
5  * LSST Project (http://www.lsst.org/).
6  * See the COPYRIGHT file
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 "pybind11/pybind11.h"
23 
24 #include "numpy/arrayobject.h"
25 #include "ndarray/pybind11.h"
26 
28 
29 namespace py = pybind11;
30 using namespace pybind11::literals;
31 
32 namespace lsst {
33 namespace shapelet {
34 
35 PYBIND11_PLUGIN(shapeletFunction) {
36  py::module::import("lsst.afw.geom");
37  py::module::import("lsst.afw.image");
38 
39  py::module mod("shapeletFunction");
40 
41  if (_import_array() < 0) {
42  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
43  return nullptr;
44  }
45 
46  py::class_<ShapeletFunction, std::shared_ptr<ShapeletFunction>> clsShapeletFunction(mod,
47  "ShapeletFunction");
48 
49  clsShapeletFunction.def_readonly_static("FLUX_FACTOR", &ShapeletFunction::FLUX_FACTOR);
50 
51  clsShapeletFunction.def(py::init<int, BasisTypeEnum>(), "order"_a, "basisType"_a);
52  clsShapeletFunction.def(py::init<int, BasisTypeEnum, ndarray::Array<double, 1, 1> const &>(), "order"_a,
53  "basisType"_a, "coefficients"_a);
54  clsShapeletFunction.def(py::init<int, BasisTypeEnum, double, afw::geom::Point2D const &>(), "order"_a,
55  "basisType"_a, "radius"_a, "center"_a = afw::geom::Point2D());
56  clsShapeletFunction.def(py::init<int, BasisTypeEnum, double, afw::geom::Point2D const &,
57  ndarray::Array<double, 1, 1> const &>(),
58  "order"_a, "basisType"_a, "radius"_a, "center"_a, "coefficients"_a);
59  clsShapeletFunction.def(py::init<int, BasisTypeEnum, afw::geom::ellipses::Ellipse const &>(), "order"_a,
60  "basisType"_a, "ellipse"_a);
61  clsShapeletFunction.def(py::init<int, BasisTypeEnum, afw::geom::ellipses::Ellipse const &,
62  ndarray::Array<double const, 1, 1> const &>(),
63  "order"_a, "basisType"_a, "ellipse"_a, "coefficients"_a);
64  clsShapeletFunction.def(py::init<ShapeletFunction>());
65 
66  clsShapeletFunction.def("getOrder", &ShapeletFunction::getOrder);
67  clsShapeletFunction.def("getEllipse", (afw::geom::ellipses::Ellipse & (ShapeletFunction::*)()) &
68  ShapeletFunction::getEllipse,
69  py::return_value_policy::reference_internal);
70  clsShapeletFunction.def("setEllipse", &ShapeletFunction::setEllipse);
71  clsShapeletFunction.def("getBasisType", &ShapeletFunction::getBasisType);
72  clsShapeletFunction.def("changeBasisType", &ShapeletFunction::changeBasisType);
73  clsShapeletFunction.def("normalize", &ShapeletFunction::normalize, "value"_a = 1.0);
74  clsShapeletFunction.def("getCoefficients", (ndarray::Array<double, 1, 1> const (ShapeletFunction::*)()) &
75  ShapeletFunction::getCoefficients);
76  clsShapeletFunction.def("convolve", &ShapeletFunction::convolve);
77  clsShapeletFunction.def("evaluate", &ShapeletFunction::evaluate);
78  clsShapeletFunction.def("shiftInPlace", &ShapeletFunction::shiftInPlace);
79  clsShapeletFunction.def("transformInPlace", &ShapeletFunction::transformInPlace);
80 
81  py::class_<ShapeletFunctionEvaluator, std::shared_ptr<ShapeletFunctionEvaluator>>
82  clsShapeletFunctionEvaluator(mod, "ShapeletFunctionEvaluator");
83 
84  clsShapeletFunctionEvaluator.def(py::init<ShapeletFunction const &>(), "function"_a);
85 
86  clsShapeletFunctionEvaluator.def("__call__",
87  (double (ShapeletFunctionEvaluator::*)(double, double) const) &
88  ShapeletFunctionEvaluator::operator());
89  clsShapeletFunctionEvaluator.def(
90  "__call__", (double (ShapeletFunctionEvaluator::*)(afw::geom::Point2D const &) const) &
91  ShapeletFunctionEvaluator::operator());
92  clsShapeletFunctionEvaluator.def(
93  "__call__", (double (ShapeletFunctionEvaluator::*)(afw::geom::Extent2D const &) const) &
94  ShapeletFunctionEvaluator::operator());
95  clsShapeletFunctionEvaluator.def("__call__", (ndarray::Array<double, 1, 1> (ShapeletFunctionEvaluator::*)(
96  ndarray::Array<double const, 1> const &,
97  ndarray::Array<double const, 1> const &) const) &
98  ShapeletFunctionEvaluator::operator());
99 
100  clsShapeletFunctionEvaluator.def(
101  "addToImage", (void (ShapeletFunctionEvaluator::*)(ndarray::Array<double, 2, 1> const &,
102  afw::geom::Point2I const &) const) &
103  ShapeletFunctionEvaluator::addToImage,
104  "array"_a, "xy0"_a = afw::geom::Point2D());
105  clsShapeletFunctionEvaluator.def(
106  "addToImage", (void (ShapeletFunctionEvaluator::*)(afw::image::Image<double> &) const) &
107  ShapeletFunctionEvaluator::addToImage,
108  "image"_a);
109  clsShapeletFunctionEvaluator.def("integrate", &ShapeletFunctionEvaluator::integrate);
110  clsShapeletFunctionEvaluator.def("computeMoments", &ShapeletFunctionEvaluator::computeMoments);
111  clsShapeletFunctionEvaluator.def("update", &ShapeletFunctionEvaluator::update);
112 
113  return mod.ptr();
114 }
115 
116 } // shapelet
117 } // lsst
Evaluates a ShapeletFunction.
PYBIND11_PLUGIN(basisEvaluator)
BasisTypeEnum
An enum that sets whether to use real-valued polar shapelets or Cartesian shapelets.
Definition: constants.h:52
A 2-d function defined by an expansion onto a Gauss-Laguerre or Gauss-Hermite basis.