LSSTApplications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
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/afw/math/Kernel.h"
28 #include "lsst/afw/table/io/python.h" // for addPersistableMethods
29 
30 namespace py = pybind11;
31 
32 using namespace py::literals;
33 
34 using namespace lsst::afw::math;
35 
36 PYBIND11_MODULE(kernel, mod) {
37  py::class_<Kernel, std::shared_ptr<Kernel>> clsKernel(mod, "Kernel");
38 
39  lsst::afw::table::io::python::addPersistableMethods<Kernel>(clsKernel);
40 
41  clsKernel.def("clone", &Kernel::clone);
42  clsKernel.def("resized", &Kernel::resized, "width"_a, "height"_a);
43  clsKernel.def("computeImage", &Kernel::computeImage, "image"_a, "doNormalize"_a, "x"_a = 0.0,
44  "y"_a = 0.0);
45  clsKernel.def("getDimensions", &Kernel::getDimensions);
46  clsKernel.def("setDimensions", &Kernel::setDimensions);
47  clsKernel.def("setWidth", &Kernel::setWidth);
48  clsKernel.def("setHeight", &Kernel::setHeight);
49  clsKernel.def("getWidth", &Kernel::getWidth);
50  clsKernel.def("getHeight", &Kernel::getHeight);
51  clsKernel.def("getCtr", &Kernel::getCtr);
52  clsKernel.def("getBBox", &Kernel::getBBox);
53  clsKernel.def("getNKernelParameters", &Kernel::getNKernelParameters);
54  clsKernel.def("getNSpatialParameters", &Kernel::getNSpatialParameters);
55  clsKernel.def("getSpatialFunction", &Kernel::getSpatialFunction);
56  clsKernel.def("getSpatialFunctionList", &Kernel::getSpatialFunctionList);
57  clsKernel.def("getKernelParameter", &Kernel::getKernelParameter);
58  clsKernel.def("getKernelParameters", &Kernel::getKernelParameters);
59  clsKernel.def("growBBox", &Kernel::growBBox);
60  clsKernel.def("shrinkBBox", &Kernel::shrinkBBox);
61  clsKernel.def("setCtr", &Kernel::setCtr);
62  clsKernel.def("getSpatialParameters", &Kernel::getSpatialParameters);
63  clsKernel.def("isSpatiallyVarying", &Kernel::isSpatiallyVarying);
64  clsKernel.def("setKernelParameters",
65  (void (Kernel::*)(std::vector<double> const &)) & Kernel::setKernelParameters);
66  clsKernel.def("setKernelParameters",
67  (void (Kernel::*)(std::pair<double, double> const &)) & Kernel::setKernelParameters);
68  clsKernel.def("setSpatialParameters", &Kernel::setSpatialParameters);
69  clsKernel.def("computeKernelParametersFromSpatialModel",
70  &Kernel::computeKernelParametersFromSpatialModel);
71  clsKernel.def("toString", &Kernel::toString, "prefix"_a = "");
72  clsKernel.def("computeCache", &Kernel::computeCache);
73  clsKernel.def("getCacheSize", &Kernel::getCacheSize);
74 
75  py::class_<FixedKernel, std::shared_ptr<FixedKernel>, Kernel> clsFixedKernel(mod, "FixedKernel");
76 
77  clsFixedKernel.def(py::init<>());
78  clsFixedKernel.def(py::init<lsst::afw::image::Image<Kernel::Pixel> const &>(), "image"_a);
79  clsFixedKernel.def(py::init<lsst::afw::math::Kernel const &, lsst::geom::Point2D const &>(), "kernel"_a,
80  "pos"_a);
81  clsFixedKernel.def("clone", &FixedKernel::clone);
82  clsFixedKernel.def("resized", &FixedKernel::resized, "width"_a, "height"_a);
83  clsFixedKernel.def("toString", &FixedKernel::toString, "prefix"_a = "");
84  clsFixedKernel.def("getSum", &FixedKernel::getSum);
85  clsFixedKernel.def("isPersistable", &FixedKernel::isPersistable);
86 
87  py::class_<AnalyticKernel, std::shared_ptr<AnalyticKernel>, Kernel> clsAnalyticKernel(mod,
88  "AnalyticKernel");
89  clsAnalyticKernel.def(py::init<>());
90  // Workaround for NullSpatialFunction and py::arg not playing well with Citizen (TODO: no longer needed?)
91  clsAnalyticKernel.def(py::init<int, int, AnalyticKernel::KernelFunction const &>(), "width"_a, "height"_a,
92  "kernelFunction"_a);
93  clsAnalyticKernel.def(
94  py::init<int, int, AnalyticKernel::KernelFunction const &, Kernel::SpatialFunction const &>(),
95  "width"_a, "height"_a, "kernelFunction"_a, "spatialFunction"_a);
96  clsAnalyticKernel.def(py::init<int, int, AnalyticKernel::KernelFunction const &,
98  "width"_a, "height"_a, "kernelFunction"_a, "spatialFunctionList"_a);
99  clsAnalyticKernel.def("clone", &AnalyticKernel::clone);
100  clsAnalyticKernel.def("resized", &AnalyticKernel::resized, "width"_a, "height"_a);
101  clsAnalyticKernel.def("computeImage", &AnalyticKernel::computeImage, "image"_a, "doNormalize"_a,
102  "x"_a = 0.0, "y"_a = 0.0);
103  clsAnalyticKernel.def("getKernelParameters", &AnalyticKernel::getKernelParameters);
104  clsAnalyticKernel.def("getKernelFunction", &AnalyticKernel::getKernelFunction);
105  clsAnalyticKernel.def("toString", &AnalyticKernel::toString, "prefix"_a = "");
106  clsAnalyticKernel.def("isPersistable", &AnalyticKernel::isPersistable);
107 
108  py::class_<DeltaFunctionKernel, std::shared_ptr<DeltaFunctionKernel>, Kernel> clsDeltaFunctionKernel(
109  mod, "DeltaFunctionKernel");
110 
111  clsDeltaFunctionKernel.def(py::init<int, int, lsst::geom::Point2I const &>(), "width"_a, "height"_a,
112  "point"_a);
113  clsDeltaFunctionKernel.def("clone", &DeltaFunctionKernel::clone);
114  clsDeltaFunctionKernel.def("resized", &DeltaFunctionKernel::resized, "width"_a, "height"_a);
115  clsDeltaFunctionKernel.def("getPixel", &DeltaFunctionKernel::getPixel);
116  clsDeltaFunctionKernel.def("toString", &DeltaFunctionKernel::toString, "prefix"_a = "");
117  clsDeltaFunctionKernel.def("isPersistable", &DeltaFunctionKernel::isPersistable);
118 
119  py::class_<LinearCombinationKernel, std::shared_ptr<LinearCombinationKernel>, Kernel>
120  clsLinearCombinationKernel(mod, "LinearCombinationKernel");
121 
122  clsLinearCombinationKernel.def(py::init<>());
123  clsLinearCombinationKernel.def(py::init<KernelList const &, std::vector<double> const &>(),
124  "kernelList"_a, "kernelParameters"_a);
125  clsLinearCombinationKernel.def(py::init<KernelList const &, Kernel::SpatialFunction const &>(),
126  "kernelList"_a, "spatialFunction"_a);
127  clsLinearCombinationKernel.def(
128  py::init<KernelList const &, std::vector<Kernel::SpatialFunctionPtr> const &>(), "kernelList"_a,
129  "spatialFunctionList"_a);
130  clsLinearCombinationKernel.def("clone", &LinearCombinationKernel::clone);
131  clsLinearCombinationKernel.def("resized", &LinearCombinationKernel::resized, "width"_a, "height"_a);
132  clsLinearCombinationKernel.def("getKernelParameters", &LinearCombinationKernel::getKernelParameters);
133  clsLinearCombinationKernel.def("getKernelList", &LinearCombinationKernel::getKernelList);
134  clsLinearCombinationKernel.def("getKernelSumList", &LinearCombinationKernel::getKernelSumList);
135  clsLinearCombinationKernel.def("getNBasisKernels", &LinearCombinationKernel::getNBasisKernels);
136  clsLinearCombinationKernel.def("checkKernelList", &LinearCombinationKernel::checkKernelList);
137  clsLinearCombinationKernel.def("isDeltaFunctionBasis", &LinearCombinationKernel::isDeltaFunctionBasis);
138  clsLinearCombinationKernel.def("refactor", &LinearCombinationKernel::refactor);
139  clsLinearCombinationKernel.def("toString", &LinearCombinationKernel::toString, "prefix"_a = "");
140  clsLinearCombinationKernel.def("isPersistable", &LinearCombinationKernel::isPersistable);
141 
142  py::class_<SeparableKernel, std::shared_ptr<SeparableKernel>, Kernel> clsSeparableKernel(
143  mod, "SeparableKernel");
144 
145  clsSeparableKernel.def(py::init<>());
146  // Workaround for NullSpatialFunction and py::arg not playing well with Citizen (TODO: no longer needed?)
147  clsSeparableKernel.def(py::init<int, int, SeparableKernel::KernelFunction const &,
149  "width"_a, "height"_a, "kernelColFunction"_a, "kernelRowFunction"_a);
150  clsSeparableKernel.def(
151  py::init<int, int, SeparableKernel::KernelFunction const &,
153  "width"_a, "height"_a, "kernelColFunction"_a, "kernelRowFunction"_a, "spatialFunction"_a);
154  clsSeparableKernel.def(py::init<int, int, SeparableKernel::KernelFunction const &,
157  "width"_a, "height"_a, "kernelColFunction"_a, "kernelRowFunction"_a,
158  "spatialFunctionList"_a);
159  clsSeparableKernel.def("clone", &SeparableKernel::clone);
160  clsSeparableKernel.def("resized", &SeparableKernel::resized, "width"_a, "height"_a);
161  clsSeparableKernel.def("computeVectors", &SeparableKernel::computeVectors);
162  clsSeparableKernel.def("getKernelParameter", &SeparableKernel::getKernelParameter);
163  clsSeparableKernel.def("getKernelParameters", &SeparableKernel::getKernelParameters);
164  clsSeparableKernel.def("getKernelColFunction", &SeparableKernel::getKernelColFunction);
165  clsSeparableKernel.def("getKernelRowFunction", &SeparableKernel::getKernelRowFunction);
166  clsSeparableKernel.def("toString", &SeparableKernel::toString, "prefix"_a = "");
167  clsSeparableKernel.def("computeCache", &SeparableKernel::computeCache);
168  clsSeparableKernel.def("getCacheSize", &SeparableKernel::getCacheSize);
169 }
std::pair< double, double >
std::vector< double >
lsst::meas::algorithms::setSpatialParameters
void setSpatialParameters(afw::math::Kernel *kernel, std::vector< double > const &coeffs)
Fit a Kernel's spatial variability from a set of stars.
Definition: SpatialModelPsf.cc:500
PYBIND11_MODULE
PYBIND11_MODULE(kernel, mod)
Definition: kernel.cc:36
python.h
lsst::afw::math::Function2< Pixel >
lsst::afw::math
Definition: statistics.dox:6
Kernel.h
pybind11
Definition: _GenericMap.cc:40
lsst::afw::math::Kernel
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:111
lsst::afw::image::Image
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:58
lsst::utils.tests.init
def init()
Definition: tests.py:59
lsst::afw::math::Function1
A Function taking one argument.
Definition: Function.h:202
lsst::afw::image.slicing.clone
clone
Definition: slicing.py:257