lsst.afw  13.0-39-g3deb52d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
warpExposure.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 <cstdint>
24 #include <memory>
25 #include <string>
26 
27 #include <pybind11/pybind11.h>
28 //#include <pybind11/stl.h>
29 
31 #include "lsst/afw/image/Image.h"
33 #include "lsst/afw/image/Wcs.h"
34 #include "lsst/afw/math/Kernel.h"
36 
37 namespace py = pybind11;
38 using namespace py::literals;
39 
40 namespace lsst {
41 namespace afw {
42 namespace math {
43 
44 namespace {
53 template <typename KernelT>
54 py::class_<KernelT, std::shared_ptr<KernelT>, SeparableKernel> declareWarpingKernel(py::module &mod,
55  std::string const &name) {
56  py::class_<KernelT, std::shared_ptr<KernelT>, SeparableKernel> cls(mod, name.c_str());
57 
58  cls.def("clone", &KernelT::clone);
59  return cls;
60 }
61 
70 template <typename KernelT>
71 py::class_<KernelT, std::shared_ptr<KernelT>, SeparableKernel> declareSimpleWarpingKernel(
72  py::module &mod, std::string const &name, bool addConstructor = true) {
73  auto cls = declareWarpingKernel<KernelT>(mod, name);
74  cls.def(py::init<>());
75  return cls;
76 }
77 
86 template <typename DestImageT, typename SrcImageT>
87 void declareImageWarpingFunctions(py::module &mod) {
88  auto const EdgePixel =
89  edgePixel<DestImageT>(typename image::detail::image_traits<DestImageT>::image_category());
90  mod.def("warpImage", (int (*)(DestImageT &, image::Wcs const &, SrcImageT const &, image::Wcs const &,
91  WarpingControl const &, typename DestImageT::SinglePixel)) &
92  warpImage<DestImageT, SrcImageT>,
93  "destImage"_a, "destWcs"_a, "srcImage"_a, "srcWcs"_a, "control"_a, "padValue"_a = EdgePixel);
94 
95  mod.def("warpImage", (int (*)(DestImageT &, SrcImageT const &, geom::XYTransform const &,
96  WarpingControl const &, typename DestImageT::SinglePixel)) &
97  warpImage<DestImageT, SrcImageT>,
98  "destImage"_a, "srcImage"_a, "xyTransform"_a, "control"_a, "padValue"_a = EdgePixel);
99 
100  mod.def("warpCenteredImage", &warpCenteredImage<DestImageT, SrcImageT>, "destImage"_a, "srcImage"_a,
101  "linearTransform"_a, "centerPoint"_a, "control"_a, "padValue"_a = EdgePixel);
102 }
103 
114 template <typename DestPixelT, typename SrcPixelT>
115 void declareWarpingFunctions(py::module &mod) {
118  using DestImageT = image::Image<DestPixelT>;
119  using SrcImageT = image::Image<SrcPixelT>;
122 
123  mod.def("warpExposure", &warpExposure<DestExposureT, SrcExposureT>, "destExposure"_a, "srcExposure"_a,
124  "control"_a, "padValue"_a = edgePixel<DestMaskedImageT>(
125  typename image::detail::image_traits<DestMaskedImageT>::image_category()));
126 
127  declareImageWarpingFunctions<DestImageT, SrcImageT>(mod);
128  declareImageWarpingFunctions<DestMaskedImageT, SrcMaskedImageT>(mod);
129 }
130 }
131 
132 PYBIND11_PLUGIN(_warpExposure) {
133  py::module mod("_warpExposure", "Python wrapper for afw _warpExposure library");
134 
135  /* Module level */
136  auto clsLanczosWarpingKernel = declareWarpingKernel<LanczosWarpingKernel>(mod, "LanczosWarpingKernel");
137  declareSimpleWarpingKernel<BilinearWarpingKernel>(mod, "BilinearWarpingKernel");
138  declareSimpleWarpingKernel<NearestWarpingKernel>(mod, "NearestWarpingKernel");
139 
140  py::class_<WarpingControl, std::shared_ptr<WarpingControl>> clsWarpingControl(mod, "WarpingControl");
141 
142  declareWarpingFunctions<double, double>(mod);
143  declareWarpingFunctions<double, float>(mod);
144  declareWarpingFunctions<double, int>(mod);
145  declareWarpingFunctions<double, std::uint16_t>(mod);
146  declareWarpingFunctions<float, float>(mod);
147  declareWarpingFunctions<float, int>(mod);
148  declareWarpingFunctions<float, std::uint16_t>(mod);
149  declareWarpingFunctions<int, int>(mod);
150  declareWarpingFunctions<std::uint16_t, std::uint16_t>(mod);
151 
152  /* Member types and enums */
153 
154  /* Constructors */
155  clsLanczosWarpingKernel.def(py::init<int>(), "order"_a);
156 
157  clsWarpingControl.def(py::init<std::string, std::string, int, int, image::MaskPixel>(),
158  "warpingKernelName"_a, "maskWarpingKernelName"_a = "", "cacheSize"_a = 0,
159  "interpLength"_a = 0, "growFullMask"_a = 0);
160 
161  /* Operators */
162  clsLanczosWarpingKernel.def("getOrder", &LanczosWarpingKernel::getOrder);
163 
164  clsWarpingControl.def("getCacheSize", &WarpingControl::getCacheSize);
165  clsWarpingControl.def("setCacheSize", &WarpingControl::setCacheSize, "cacheSize"_a);
166  clsWarpingControl.def("getInterpLength", &WarpingControl::getInterpLength);
167  clsWarpingControl.def("setInterpLength", &WarpingControl::setInterpLength, "interpLength"_a);
168  clsWarpingControl.def("setWarpingKernelName", &WarpingControl::setWarpingKernelName,
169  "warpingKernelName"_a);
170  clsWarpingControl.def("getWarpingKernel", &WarpingControl::getWarpingKernel);
171  clsWarpingControl.def("setWarpingKernel", &WarpingControl::setWarpingKernel, "warpingKernel"_a);
172  clsWarpingControl.def("setMaskWarpingKernelName", &WarpingControl::setMaskWarpingKernelName,
173  "maskWarpingKernelName"_a);
174  clsWarpingControl.def("getMaskWarpingKernel", &WarpingControl::getMaskWarpingKernel);
175  clsWarpingControl.def("hasMaskWarpingKernel", &WarpingControl::hasMaskWarpingKernel);
176  clsWarpingControl.def("setMaskWarpingKernelName", &WarpingControl::setMaskWarpingKernelName,
177  "maskWarpingKernelName"_a);
178  clsWarpingControl.def("setMaskWarpingKernel", &WarpingControl::setMaskWarpingKernel,
179  "maskWarpingKernel"_a);
180  clsWarpingControl.def("getGrowFullMask", &WarpingControl::getGrowFullMask);
181  clsWarpingControl.def("setGrowFullMask", &WarpingControl::setGrowFullMask, "growFullMask"_a);
182 
183  /* Members */
184 
185  return mod.ptr();
186 }
187 }
188 }
189 } // namespace lsst::afw::math
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:76
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:104
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:81
table::Key< std::string > name
Definition: ApCorrMap.cc:71
double const _a
Definition: RandomImage.cc:77
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:486