lsst.afw  13.0-73-gb2a4e38
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
chebyshevBoundedField.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 
23 #include <pybind11/pybind11.h>
24 #include <pybind11/operators.h>
25 #include <pybind11/stl.h>
26 
27 #include "numpy/arrayobject.h"
28 #include "ndarray/pybind11.h"
29 #include "ndarray/converter.h"
30 
31 #include "lsst/pex/config/python.h" // defines LSST_DECLARE_CONTROL_FIELD
33 
37 
38 namespace py = pybind11;
39 
40 using namespace lsst::afw::math;
41 
42 using ClsField = py::class_<ChebyshevBoundedField, std::shared_ptr<ChebyshevBoundedField>, BoundedField,
44 
45 template <typename PixelT>
47  cls.def_static("fit", (std::shared_ptr<ChebyshevBoundedField>(*)(lsst::afw::image::Image<PixelT> const &,
50 }
51 
52 PYBIND11_PLUGIN(_chebyshevBoundedField) {
53  py::module mod("_chebyshevBoundedField", "Python wrapper for afw _chebyshevBoundedField library");
54 
55  if (_import_array() < 0) {
56  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
57  return nullptr;
58  };
59 
60  /* Module level */
61  lsst::afw::table::io::python::declarePersistableFacade<ChebyshevBoundedField>(mod,
62  "ChebyshevBoundedField");
63  py::class_<ChebyshevBoundedFieldControl> clsChebyshevBoundedFieldControl(mod,
64  "ChebyshevBoundedFieldControl");
65  ClsField clsChebyshevBoundedField(mod, "ChebyshevBoundedField");
66 
67  /* Member types and enums */
68  using Control = ChebyshevBoundedFieldControl;
69 
70  /* Constructors */
71  clsChebyshevBoundedFieldControl.def(py::init<>());
72  clsChebyshevBoundedField.def(
73  py::init<lsst::afw::geom::Box2I const &, ndarray::Array<double const, 2, 2> const &>());
74 
75  /* Operators */
76  clsChebyshevBoundedField.def("__rmul__",
77  [](ChebyshevBoundedField &bf, double const scale) { return bf * scale; },
78  py::is_operator());
79  clsChebyshevBoundedField.def("__mul__",
80  [](ChebyshevBoundedField &bf, double const scale) { return bf * scale; },
81  py::is_operator());
82  clsChebyshevBoundedField.def("__eq__", &BoundedField::operator==, py::is_operator());
83  clsChebyshevBoundedField.def("__ne__", &BoundedField::operator!=, py::is_operator());
84 
85  /* Members */
86  LSST_DECLARE_CONTROL_FIELD(clsChebyshevBoundedFieldControl, ChebyshevBoundedFieldControl, orderX);
87  LSST_DECLARE_CONTROL_FIELD(clsChebyshevBoundedFieldControl, ChebyshevBoundedFieldControl, orderY);
88  LSST_DECLARE_CONTROL_FIELD(clsChebyshevBoundedFieldControl, ChebyshevBoundedFieldControl, triangular);
89 
90  clsChebyshevBoundedFieldControl.def("computeSize", &ChebyshevBoundedFieldControl::computeSize);
91 
92  clsChebyshevBoundedField.def("getCoefficients", &ChebyshevBoundedField::getCoefficients);
93  clsChebyshevBoundedField.def_static(
94  "fit", (std::shared_ptr<ChebyshevBoundedField>(*)(
95  lsst::afw::geom::Box2I const &, ndarray::Array<double const, 1> const &,
96  ndarray::Array<double const, 1> const &, ndarray::Array<double const, 1> const &,
97  Control const &)) &
99  clsChebyshevBoundedField.def_static(
100  "fit", (std::shared_ptr<ChebyshevBoundedField>(*)(
101  lsst::afw::geom::Box2I const &, ndarray::Array<double const, 1> const &,
102  ndarray::Array<double const, 1> const &, ndarray::Array<double const, 1> const &,
103  ndarray::Array<double const, 1> const &, Control const &)) &
104  ChebyshevBoundedField::fit);
105 
106  clsChebyshevBoundedField.def("truncate", &ChebyshevBoundedField::truncate);
107 
108  // Pybind11 resolves overloads by picking the first one that might work
109  declareTemplates<double>(clsChebyshevBoundedField);
110  declareTemplates<float>(clsChebyshevBoundedField);
111 
112  return mod.ptr();
113 }
A control object used when fitting ChebyshevBoundedField to data (see ChebyshevBoundedField::fit) ...
int computeSize() const
Return the number of nonzero coefficients in the Chebyshev function defined by this object...
An integer coordinate rectangle.
Definition: Box.h:55
ndarray::Array< double const, 2, 2 > getCoefficients() const
Return the coefficient matrix.
A BoundedField based on 2-d Chebyshev polynomials of the first kind.
py::class_< ChebyshevBoundedField, std::shared_ptr< ChebyshevBoundedField >, BoundedField, lsst::afw::table::io::PersistableFacade< ChebyshevBoundedField >> ClsField
An abstract base class for 2-d functions defined on an integer bounding boxes.
Definition: BoundedField.h:55
static std::shared_ptr< ChebyshevBoundedField > fit(afw::geom::Box2I const &bbox, ndarray::Array< double const, 1 > const &x, ndarray::Array< double const, 1 > const &y, ndarray::Array< double const, 1 > const &z, Control const &ctrl)
Fit a Chebyshev approximation to non-gridded data with equal weights.
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:486
std::shared_ptr< ChebyshevBoundedField > truncate(Control const &ctrl) const
Return a new ChebyshevBoudedField with maximum orders set by the given control object.
table::Key< int > orderX
PYBIND11_PLUGIN(_approximate)
Definition: approximate.cc:56
void declareTemplates(ClsField &cls)