lsst.afw  14.0
 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>,
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  py::class_<ChebyshevBoundedFieldControl> clsChebyshevBoundedFieldControl(mod,
62  "ChebyshevBoundedFieldControl");
63  ClsField clsChebyshevBoundedField(mod, "ChebyshevBoundedField");
64 
65  /* Member types and enums */
66  using Control = ChebyshevBoundedFieldControl;
67 
68  /* Constructors */
69  clsChebyshevBoundedFieldControl.def(py::init<>());
70  clsChebyshevBoundedField.def(
71  py::init<lsst::afw::geom::Box2I const &, ndarray::Array<double const, 2, 2> const &>());
72 
73  /* Operators are defined only in the BoundedField base class;
74  we let Python inheritance provide them here. */
75 
76  /* Members */
77  LSST_DECLARE_CONTROL_FIELD(clsChebyshevBoundedFieldControl, ChebyshevBoundedFieldControl, orderX);
78  LSST_DECLARE_CONTROL_FIELD(clsChebyshevBoundedFieldControl, ChebyshevBoundedFieldControl, orderY);
79  LSST_DECLARE_CONTROL_FIELD(clsChebyshevBoundedFieldControl, ChebyshevBoundedFieldControl, triangular);
80 
81  clsChebyshevBoundedFieldControl.def("computeSize", &ChebyshevBoundedFieldControl::computeSize);
82 
83  clsChebyshevBoundedField.def("getCoefficients", &ChebyshevBoundedField::getCoefficients);
84  clsChebyshevBoundedField.def_static(
85  "fit", (std::shared_ptr<ChebyshevBoundedField>(*)(
86  lsst::afw::geom::Box2I const &, ndarray::Array<double const, 1> const &,
87  ndarray::Array<double const, 1> const &, ndarray::Array<double const, 1> const &,
88  Control const &)) &
90  clsChebyshevBoundedField.def_static(
91  "fit", (std::shared_ptr<ChebyshevBoundedField>(*)(
92  lsst::afw::geom::Box2I const &, ndarray::Array<double const, 1> const &,
93  ndarray::Array<double const, 1> const &, ndarray::Array<double const, 1> const &,
94  ndarray::Array<double const, 1> const &, Control const &)) &
95  ChebyshevBoundedField::fit);
96 
97  clsChebyshevBoundedField.def("truncate", &ChebyshevBoundedField::truncate);
98 
99  // Pybind11 resolves overloads by picking the first one that might work
100  declareTemplates<double>(clsChebyshevBoundedField);
101  declareTemplates<float>(clsChebyshevBoundedField);
102 
103  return mod.ptr();
104 }
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.
An abstract base class for 2-d functions defined on an integer bounding boxes.
Definition: BoundedField.h:55
py::class_< ChebyshevBoundedField, std::shared_ptr< ChebyshevBoundedField >, BoundedField > ClsField
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)