lsst.afw  13.0-98-g5a654715e+2
 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("warpImage",
101  (int (*)(DestImageT &, SrcImageT const &,
102  geom::Transform<geom::Point2Endpoint, geom::Point2Endpoint> const &,
103  WarpingControl const &, typename DestImageT::SinglePixel)) &
104  warpImage<DestImageT, SrcImageT>,
105  "destImage"_a, "srcImage"_a, "destToSrc"_a, "control"_a, "padValue"_a = EdgePixel);
106 
107  mod.def("warpCenteredImage", &warpCenteredImage<DestImageT, SrcImageT>, "destImage"_a, "srcImage"_a,
108  "linearTransform"_a, "centerPoint"_a, "control"_a, "padValue"_a = EdgePixel);
109 }
110 
121 template <typename DestPixelT, typename SrcPixelT>
122 void declareWarpingFunctions(py::module &mod) {
125  using DestImageT = image::Image<DestPixelT>;
126  using SrcImageT = image::Image<SrcPixelT>;
129 
130  mod.def("warpExposure", &warpExposure<DestExposureT, SrcExposureT>, "destExposure"_a, "srcExposure"_a,
131  "control"_a, "padValue"_a = edgePixel<DestMaskedImageT>(
132  typename image::detail::image_traits<DestMaskedImageT>::image_category()));
133 
134  declareImageWarpingFunctions<DestImageT, SrcImageT>(mod);
135  declareImageWarpingFunctions<DestMaskedImageT, SrcMaskedImageT>(mod);
136 }
137 }
138 
139 PYBIND11_PLUGIN(_warpExposure) {
140  py::module mod("_warpExposure", "Python wrapper for afw _warpExposure library");
141 
142  /* Module level */
143  auto clsLanczosWarpingKernel = declareWarpingKernel<LanczosWarpingKernel>(mod, "LanczosWarpingKernel");
144  declareSimpleWarpingKernel<BilinearWarpingKernel>(mod, "BilinearWarpingKernel");
145  declareSimpleWarpingKernel<NearestWarpingKernel>(mod, "NearestWarpingKernel");
146 
147  py::class_<WarpingControl, std::shared_ptr<WarpingControl>> clsWarpingControl(mod, "WarpingControl");
148 
149  declareWarpingFunctions<double, double>(mod);
150  declareWarpingFunctions<double, float>(mod);
151  declareWarpingFunctions<double, int>(mod);
152  declareWarpingFunctions<double, std::uint16_t>(mod);
153  declareWarpingFunctions<float, float>(mod);
154  declareWarpingFunctions<float, int>(mod);
155  declareWarpingFunctions<float, std::uint16_t>(mod);
156  declareWarpingFunctions<int, int>(mod);
157  declareWarpingFunctions<std::uint16_t, std::uint16_t>(mod);
158 
159  /* Member types and enums */
160 
161  /* Constructors */
162  clsLanczosWarpingKernel.def(py::init<int>(), "order"_a);
163 
164  clsWarpingControl.def(py::init<std::string, std::string, int, int, image::MaskPixel>(),
165  "warpingKernelName"_a, "maskWarpingKernelName"_a = "", "cacheSize"_a = 0,
166  "interpLength"_a = 0, "growFullMask"_a = 0);
167 
168  /* Operators */
169  clsLanczosWarpingKernel.def("getOrder", &LanczosWarpingKernel::getOrder);
170 
171  clsWarpingControl.def("getCacheSize", &WarpingControl::getCacheSize);
172  clsWarpingControl.def("setCacheSize", &WarpingControl::setCacheSize, "cacheSize"_a);
173  clsWarpingControl.def("getInterpLength", &WarpingControl::getInterpLength);
174  clsWarpingControl.def("setInterpLength", &WarpingControl::setInterpLength, "interpLength"_a);
175  clsWarpingControl.def("setWarpingKernelName", &WarpingControl::setWarpingKernelName,
176  "warpingKernelName"_a);
177  clsWarpingControl.def("getWarpingKernel", &WarpingControl::getWarpingKernel);
178  clsWarpingControl.def("setWarpingKernel", &WarpingControl::setWarpingKernel, "warpingKernel"_a);
179  clsWarpingControl.def("setMaskWarpingKernelName", &WarpingControl::setMaskWarpingKernelName,
180  "maskWarpingKernelName"_a);
181  clsWarpingControl.def("getMaskWarpingKernel", &WarpingControl::getMaskWarpingKernel);
182  clsWarpingControl.def("hasMaskWarpingKernel", &WarpingControl::hasMaskWarpingKernel);
183  clsWarpingControl.def("setMaskWarpingKernelName", &WarpingControl::setMaskWarpingKernelName,
184  "maskWarpingKernelName"_a);
185  clsWarpingControl.def("setMaskWarpingKernel", &WarpingControl::setMaskWarpingKernel,
186  "maskWarpingKernel"_a);
187  clsWarpingControl.def("getGrowFullMask", &WarpingControl::getGrowFullMask);
188  clsWarpingControl.def("setGrowFullMask", &WarpingControl::setGrowFullMask, "growFullMask"_a);
189 
190  /* Members */
191 
192  return mod.ptr();
193 }
194 }
195 }
196 } // 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:68