lsst.afw  13.0-92-g8ecf155+1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
kernel.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 "lsst/daf/base/Persistable.h"
29 
30 #include "lsst/afw/math/Kernel.h"
32 
33 namespace py = pybind11;
34 
35 using namespace py::literals;
36 
37 using namespace lsst::afw::math;
38 
39 PYBIND11_PLUGIN(_kernel) {
40  py::module mod("_kernel", "Python wrapper for afw _kernel library");
41 
42  lsst::afw::table::io::python::declarePersistableFacade<Kernel>(mod, "Kernel");
43 
44  py::class_<Kernel, std::shared_ptr<Kernel>, lsst::daf::base::Persistable,
46  clsKernel(mod, "Kernel");
47 
48  clsKernel.def("clone", &Kernel::clone);
49  clsKernel.def("resized", &Kernel::resized, "width"_a, "height"_a);
50  clsKernel.def("computeImage", &Kernel::computeImage, "image"_a, "doNormalize"_a, "x"_a = 0.0,
51  "y"_a = 0.0);
52  clsKernel.def("getDimensions", &Kernel::getDimensions);
53  clsKernel.def("setDimensions", &Kernel::setDimensions);
54  clsKernel.def("setWidth", &Kernel::setWidth);
55  clsKernel.def("setHeight", &Kernel::setHeight);
56  clsKernel.def("getWidth", &Kernel::getWidth);
57  clsKernel.def("getHeight", &Kernel::getHeight);
58  clsKernel.def("getCtr", &Kernel::getCtr);
59  clsKernel.def("getCtrX", &Kernel::getCtrX);
60  clsKernel.def("getCtrY", &Kernel::getCtrY);
61  clsKernel.def("getBBox", &Kernel::getBBox);
62  clsKernel.def("getNKernelParameters", &Kernel::getNKernelParameters);
63  clsKernel.def("getNSpatialParameters", &Kernel::getNSpatialParameters);
64  clsKernel.def("getSpatialFunction", &Kernel::getSpatialFunction);
65  clsKernel.def("getSpatialFunctionList", &Kernel::getSpatialFunctionList);
66  clsKernel.def("getKernelParameter", &Kernel::getKernelParameter);
67  clsKernel.def("getKernelParameters", &Kernel::getKernelParameters);
68  clsKernel.def("growBBox", &Kernel::growBBox);
69  clsKernel.def("shrinkBBox", &Kernel::shrinkBBox);
70  clsKernel.def("setCtr", &Kernel::setCtr);
71  clsKernel.def("setCtrX", &Kernel::setCtrX);
72  clsKernel.def("setCtrY", &Kernel::setCtrY);
73  clsKernel.def("getSpatialParameters", &Kernel::getSpatialParameters);
74  clsKernel.def("isSpatiallyVarying", &Kernel::isSpatiallyVarying);
75  clsKernel.def("setKernelParameters",
76  (void (Kernel::*)(std::vector<double> const &)) & Kernel::setKernelParameters);
77  clsKernel.def("setKernelParameters",
78  (void (Kernel::*)(std::pair<double, double> const &)) & Kernel::setKernelParameters);
79  clsKernel.def("setSpatialParameters", &Kernel::setSpatialParameters);
80  clsKernel.def("computeKernelParametersFromSpatialModel",
81  &Kernel::computeKernelParametersFromSpatialModel);
82  clsKernel.def("toString", &Kernel::toString, "prefix"_a = "");
83  clsKernel.def("computeCache", &Kernel::computeCache);
84  clsKernel.def("getCacheSize", &Kernel::getCacheSize);
85 
86  py::class_<FixedKernel, std::shared_ptr<FixedKernel>, Kernel> clsFixedKernel(mod, "FixedKernel");
87 
88  clsFixedKernel.def(py::init<>());
89  clsFixedKernel.def(py::init<lsst::afw::image::Image<Kernel::Pixel> const &>(), "image"_a);
90  clsFixedKernel.def(py::init<lsst::afw::math::Kernel const &, lsst::afw::geom::Point2D const &>(),
91  "kernel"_a, "pos"_a);
92  clsFixedKernel.def("clone", &FixedKernel::clone);
93  clsFixedKernel.def("resized", &FixedKernel::resized, "width"_a, "height"_a);
94  clsFixedKernel.def("toString", &FixedKernel::toString, "prefix"_a = "");
95  clsFixedKernel.def("getSum", &FixedKernel::getSum);
96  clsFixedKernel.def("isPersistable", &FixedKernel::isPersistable);
97 
98  py::class_<AnalyticKernel, std::shared_ptr<AnalyticKernel>, Kernel> clsAnalyticKernel(mod,
99  "AnalyticKernel");
100  clsAnalyticKernel.def(py::init<>());
101  // Workaround for NullSpatialFunction and py::arg not playing well with Citizen
102  clsAnalyticKernel.def(py::init<int, int, AnalyticKernel::KernelFunction const &>(), "width"_a, "height"_a,
103  "kernelFunction"_a);
104  clsAnalyticKernel.def(
105  py::init<int, int, AnalyticKernel::KernelFunction const &, Kernel::SpatialFunction const &>(),
106  "width"_a, "height"_a, "kernelFunction"_a, "spatialFunction"_a);
107  clsAnalyticKernel.def(py::init<int, int, AnalyticKernel::KernelFunction const &,
108  std::vector<Kernel::SpatialFunctionPtr> const &>(),
109  "width"_a, "height"_a, "kernelFunction"_a, "spatialFunctionList"_a);
110  clsAnalyticKernel.def("clone", &AnalyticKernel::clone);
111  clsAnalyticKernel.def("resized", &AnalyticKernel::resized, "width"_a, "height"_a);
112  clsAnalyticKernel.def("computeImage", &AnalyticKernel::computeImage, "image"_a, "doNormalize"_a,
113  "x"_a = 0.0, "y"_a = 0.0);
114  clsAnalyticKernel.def("getKernelParameters", &AnalyticKernel::getKernelParameters);
115  clsAnalyticKernel.def("getKernelFunction", &AnalyticKernel::getKernelFunction);
116  clsAnalyticKernel.def("toString", &AnalyticKernel::toString, "prefix"_a = "");
117  clsAnalyticKernel.def("isPersistable", &AnalyticKernel::isPersistable);
118 
119  py::class_<DeltaFunctionKernel, std::shared_ptr<DeltaFunctionKernel>, Kernel> clsDeltaFunctionKernel(
120  mod, "DeltaFunctionKernel");
121 
122  clsDeltaFunctionKernel.def(py::init<int, int, lsst::afw::geom::Point2I const &>(), "width"_a, "height"_a,
123  "point"_a);
124  clsDeltaFunctionKernel.def("clone", &DeltaFunctionKernel::clone);
125  clsDeltaFunctionKernel.def("resized", &DeltaFunctionKernel::resized, "width"_a, "height"_a);
126  clsDeltaFunctionKernel.def("getPixel", &DeltaFunctionKernel::getPixel);
127  clsDeltaFunctionKernel.def("toString", &DeltaFunctionKernel::toString, "prefix"_a = "");
128  clsDeltaFunctionKernel.def("isPersistable", &DeltaFunctionKernel::isPersistable);
129 
130  py::class_<LinearCombinationKernel, std::shared_ptr<LinearCombinationKernel>, Kernel>
131  clsLinearCombinationKernel(mod, "LinearCombinationKernel");
132 
133  clsLinearCombinationKernel.def(py::init<>());
134  clsLinearCombinationKernel.def(py::init<KernelList const &, std::vector<double> const &>(),
135  "kernelList"_a, "kernelParameters"_a);
136  clsLinearCombinationKernel.def(py::init<KernelList const &, Kernel::SpatialFunction const &>(),
137  "kernelList"_a, "spatialFunction"_a);
138  clsLinearCombinationKernel.def(
139  py::init<KernelList const &, std::vector<Kernel::SpatialFunctionPtr> const &>(), "kernelList"_a,
140  "spatialFunctionList"_a);
141  clsLinearCombinationKernel.def("clone", &LinearCombinationKernel::clone);
142  clsLinearCombinationKernel.def("resized", &LinearCombinationKernel::resized, "width"_a, "height"_a);
143  clsLinearCombinationKernel.def("getKernelParameters", &LinearCombinationKernel::getKernelParameters);
144  clsLinearCombinationKernel.def("getKernelList", &LinearCombinationKernel::getKernelList);
145  clsLinearCombinationKernel.def("getKernelSumList", &LinearCombinationKernel::getKernelSumList);
146  clsLinearCombinationKernel.def("getNBasisKernels", &LinearCombinationKernel::getNBasisKernels);
147  clsLinearCombinationKernel.def("checkKernelList", &LinearCombinationKernel::checkKernelList);
148  clsLinearCombinationKernel.def("isDeltaFunctionBasis", &LinearCombinationKernel::isDeltaFunctionBasis);
149  clsLinearCombinationKernel.def("refactor", &LinearCombinationKernel::refactor);
150  clsLinearCombinationKernel.def("toString", &LinearCombinationKernel::toString, "prefix"_a = "");
151  clsLinearCombinationKernel.def("isPersistable", &LinearCombinationKernel::isPersistable);
152 
153  py::class_<SeparableKernel, std::shared_ptr<SeparableKernel>, Kernel> clsSeparableKernel(
154  mod, "SeparableKernel");
155 
156  clsSeparableKernel.def(py::init<>());
157  // Workaround for NullSpatialFunction and py::arg not playing well with Citizen
158  clsSeparableKernel.def(py::init<int, int, SeparableKernel::KernelFunction const &,
160  "width"_a, "height"_a, "kernelColFunction"_a, "kernelRowFunction"_a);
161  clsSeparableKernel.def(
162  py::init<int, int, SeparableKernel::KernelFunction const &,
164  "width"_a, "height"_a, "kernelColFunction"_a, "kernelRowFunction"_a, "spatialFunction"_a);
165  clsSeparableKernel.def(py::init<int, int, SeparableKernel::KernelFunction const &,
167  std::vector<Kernel::SpatialFunctionPtr> const &>(),
168  "width"_a, "height"_a, "kernelColFunction"_a, "kernelRowFunction"_a,
169  "spatialFunctionList"_a);
170  clsSeparableKernel.def("clone", &SeparableKernel::clone);
171  clsSeparableKernel.def("resized", &SeparableKernel::resized, "width"_a, "height"_a);
172  clsSeparableKernel.def("computeVectors", &SeparableKernel::computeVectors);
173  clsSeparableKernel.def("getKernelParameter", &SeparableKernel::getKernelParameter);
174  clsSeparableKernel.def("getKernelParameters", &SeparableKernel::getKernelParameters);
175  clsSeparableKernel.def("getKernelColFunction", &SeparableKernel::getKernelColFunction);
176  clsSeparableKernel.def("getKernelRowFunction", &SeparableKernel::getKernelRowFunction);
177  clsSeparableKernel.def("toString", &SeparableKernel::toString, "prefix"_a = "");
178  clsSeparableKernel.def("computeCache", &SeparableKernel::computeCache);
179  clsSeparableKernel.def("getCacheSize", &SeparableKernel::getCacheSize);
180 
181  return mod.ptr();
182 }
A Function taking two arguments.
Definition: Function.h:266
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:73
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
A Function taking one argument.
Definition: Function.h:207
double const _a
Definition: RandomImage.cc:77
std::vector< std::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:512
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:123
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:486