lsst.meas.astrom  13.0-14-g9415442+43
polynomialTransform.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 #include "pybind11/stl.h"
24 
25 #include <memory>
26 
27 #include "numpy/arrayobject.h"
28 #include "ndarray/pybind11.h"
29 
30 #include "lsst/afw/geom/AffineTransform.h"
33 
34 namespace py = pybind11;
35 using namespace pybind11::literals;
36 
37 namespace lsst {
38 namespace meas {
39 namespace astrom {
40 
41 namespace {
42 
43 static void declarePolynomialTransform(py::module &mod) {
44  py::class_<PolynomialTransform, std::shared_ptr<PolynomialTransform>> cls(mod, "PolynomialTransform");
45 
46  cls.def(py::init<ndarray::Array<double const, 2, 2> const &,
47  ndarray::Array<double const, 2, 2> const &>(),
48  "xCoeffs"_a, "yCoeffs"_a);
49  cls.def(py::init<PolynomialTransform const &>(), "other"_a);
50 
51  cls.def_static("convert",
52  (PolynomialTransform(*)(ScaledPolynomialTransform const &)) & PolynomialTransform::convert,
53  "other"_a);
54  cls.def_static("convert",
55  (PolynomialTransform(*)(SipForwardTransform const &)) & PolynomialTransform::convert,
56  "other"_a);
57  cls.def_static("convert",
58  (PolynomialTransform(*)(SipReverseTransform const &)) & PolynomialTransform::convert,
59  "other"_a);
60 
61  cls.def("__call__", &PolynomialTransform::operator(), "in"_a);
62 
63  cls.def("getOrder", &PolynomialTransform::getOrder);
64  cls.def("getXCoeffs", &PolynomialTransform::getXCoeffs);
65  cls.def("getYCoeffs", &PolynomialTransform::getYCoeffs);
66  cls.def("linearize", &PolynomialTransform::linearize);
67 }
68 
69 static void declareScaledPolynomialTransform(py::module &mod) {
70  py::class_<ScaledPolynomialTransform, std::shared_ptr<ScaledPolynomialTransform>> cls(
71  mod, "ScaledPolynomialTransform");
72 
73  cls.def(py::init<PolynomialTransform const &, afw::geom::AffineTransform const &,
74  afw::geom::AffineTransform const &>(),
75  "poly"_a, "inputScaling"_a, "outputScalingInverse"_a);
76  cls.def(py::init<ScaledPolynomialTransform const &>(), "other"_a);
77 
78  cls.def_static("convert", (ScaledPolynomialTransform(*)(PolynomialTransform const &)) &
79  ScaledPolynomialTransform::convert,
80  "other"_a);
81  cls.def_static("convert", (ScaledPolynomialTransform(*)(SipForwardTransform const &)) &
82  ScaledPolynomialTransform::convert,
83  "other"_a);
84  cls.def_static("convert", (ScaledPolynomialTransform(*)(SipReverseTransform const &)) &
85  ScaledPolynomialTransform::convert,
86  "other"_a);
87 
88  cls.def("__call__", &ScaledPolynomialTransform::operator(), "in"_a);
89 
90  cls.def("getPoly", &ScaledPolynomialTransform::getPoly, py::return_value_policy::reference_internal);
91  cls.def("getInputScaling", &ScaledPolynomialTransform::getInputScaling,
92  py::return_value_policy::reference_internal);
93  cls.def("getOutputScalingInverse", &ScaledPolynomialTransform::getOutputScalingInverse,
94  py::return_value_policy::reference_internal);
95  cls.def("linearize", &ScaledPolynomialTransform::linearize);
96 }
97 
98 } // namespace lsst::meas::astrom::<anonymous>
99 
101  py::module mod("polynomialTransform");
102 
103  if (_import_array() < 0) {
104  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
105  return nullptr;
106  };
107 
108  declarePolynomialTransform(mod);
109  declareScaledPolynomialTransform(mod);
110 
111  mod.def("compose",
112  (PolynomialTransform(*)(afw::geom::AffineTransform const &, PolynomialTransform const &)) &
113  compose,
114  "t1"_a, "t2"_a);
115  mod.def("compose",
116  (PolynomialTransform(*)(PolynomialTransform const &, afw::geom::AffineTransform const &)) &
117  compose,
118  "t1"_a, "t2"_a);
119 
120  return mod.ptr();
121 }
122 }
123 }
124 } // namespace lsst::meas::astrom
PolynomialTransform compose(afw::geom::AffineTransform const &t1, PolynomialTransform const &t2)
Return a PolynomialTransform that is equivalent to the composition t1(t2())
PYBIND11_PLUGIN(polynomialTransform)
A 2-d coordinate transform represented by a pair of standard polynomials (one for each coordinate)...