LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
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 
30 #include "lsst/afw/geom/SkyWcs.h"
32 #include "lsst/afw/image/Image.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 &, geom::SkyWcs const &, SrcImageT const &, geom::SkyWcs 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",
96  (int (*)(DestImageT &, SrcImageT const &, geom::TransformPoint2ToPoint2 const &,
97  WarpingControl const &, typename DestImageT::SinglePixel)) &
98  warpImage<DestImageT, SrcImageT>,
99  "destImage"_a, "srcImage"_a, "srcToDest"_a, "control"_a, "padValue"_a = EdgePixel);
100 
101  mod.def("warpCenteredImage", &warpCenteredImage<DestImageT, SrcImageT>, "destImage"_a, "srcImage"_a,
102  "linearTransform"_a, "centerPoint"_a, "control"_a, "padValue"_a = EdgePixel);
103 }
104 
115 template <typename DestPixelT, typename SrcPixelT>
116 void declareWarpingFunctions(py::module &mod) {
119  using DestImageT = image::Image<DestPixelT>;
120  using SrcImageT = image::Image<SrcPixelT>;
123 
124  mod.def("warpExposure", &warpExposure<DestExposureT, SrcExposureT>, "destExposure"_a, "srcExposure"_a,
125  "control"_a, "padValue"_a = edgePixel<DestMaskedImageT>(
126  typename image::detail::image_traits<DestMaskedImageT>::image_category()));
127 
128  declareImageWarpingFunctions<DestImageT, SrcImageT>(mod);
129  declareImageWarpingFunctions<DestMaskedImageT, SrcMaskedImageT>(mod);
130 }
131 }
132 
134  /* Module level */
135  auto clsLanczosWarpingKernel = declareWarpingKernel<LanczosWarpingKernel>(mod, "LanczosWarpingKernel");
136  declareSimpleWarpingKernel<BilinearWarpingKernel>(mod, "BilinearWarpingKernel");
137  declareSimpleWarpingKernel<NearestWarpingKernel>(mod, "NearestWarpingKernel");
138 
139  py::class_<WarpingControl, std::shared_ptr<WarpingControl>> clsWarpingControl(mod, "WarpingControl");
140 
141  declareWarpingFunctions<double, double>(mod);
142  declareWarpingFunctions<double, float>(mod);
143  declareWarpingFunctions<double, int>(mod);
144  declareWarpingFunctions<double, std::uint16_t>(mod);
145  declareWarpingFunctions<float, float>(mod);
146  declareWarpingFunctions<float, int>(mod);
147  declareWarpingFunctions<float, std::uint16_t>(mod);
148  declareWarpingFunctions<int, int>(mod);
149  declareWarpingFunctions<std::uint16_t, std::uint16_t>(mod);
150 
151  /* Member types and enums */
152 
153  /* Constructors */
154  clsLanczosWarpingKernel.def(py::init<int>(), "order"_a);
155 
156  clsWarpingControl.def(py::init<std::string, std::string, int, int, image::MaskPixel>(),
157  "warpingKernelName"_a, "maskWarpingKernelName"_a = "", "cacheSize"_a = 0,
158  "interpLength"_a = 0, "growFullMask"_a = 0);
159 
160  /* Operators */
161  clsLanczosWarpingKernel.def("getOrder", &LanczosWarpingKernel::getOrder);
162 
163  clsWarpingControl.def("getCacheSize", &WarpingControl::getCacheSize);
164  clsWarpingControl.def("setCacheSize", &WarpingControl::setCacheSize, "cacheSize"_a);
165  clsWarpingControl.def("getInterpLength", &WarpingControl::getInterpLength);
166  clsWarpingControl.def("setInterpLength", &WarpingControl::setInterpLength, "interpLength"_a);
167  clsWarpingControl.def("setWarpingKernelName", &WarpingControl::setWarpingKernelName,
168  "warpingKernelName"_a);
169  clsWarpingControl.def("getWarpingKernel", &WarpingControl::getWarpingKernel);
170  clsWarpingControl.def("setWarpingKernel", &WarpingControl::setWarpingKernel, "warpingKernel"_a);
171  clsWarpingControl.def("setMaskWarpingKernelName", &WarpingControl::setMaskWarpingKernelName,
172  "maskWarpingKernelName"_a);
173  clsWarpingControl.def("getMaskWarpingKernel", &WarpingControl::getMaskWarpingKernel);
174  clsWarpingControl.def("hasMaskWarpingKernel", &WarpingControl::hasMaskWarpingKernel);
175  clsWarpingControl.def("setMaskWarpingKernelName", &WarpingControl::setMaskWarpingKernelName,
176  "maskWarpingKernelName"_a);
177  clsWarpingControl.def("setMaskWarpingKernel", &WarpingControl::setMaskWarpingKernel,
178  "maskWarpingKernel"_a);
179  clsWarpingControl.def("getGrowFullMask", &WarpingControl::getGrowFullMask);
180  clsWarpingControl.def("setGrowFullMask", &WarpingControl::setGrowFullMask, "growFullMask"_a);
181 
182  /* Members */
183 }
184 }
185 }
186 } // 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:72
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
STL class.
PYBIND11_MODULE(warpExposure, mod)
A base class for image defects.
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
T c_str(T... args)
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:58