LSST Applications  21.0.0+c4f5df5339,21.0.0+e70536a077,21.0.0-1-ga51b5d4+7c60f8a6ea,21.0.0-10-gcf60f90+74aa0801fd,21.0.0-12-g63909ac9+643a1044a5,21.0.0-15-gedb9d5423+1041c3824f,21.0.0-2-g103fe59+a356b2badb,21.0.0-2-g1367e85+6d3f3f41db,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+6d3f3f41db,21.0.0-2-g7f82c8f+8d7c04eab9,21.0.0-2-g8f08a60+9c9a9cfcc8,21.0.0-2-ga326454+8d7c04eab9,21.0.0-2-gde069b7+bedfc5e1fb,21.0.0-2-gecfae73+6cb6558258,21.0.0-2-gfc62afb+6d3f3f41db,21.0.0-3-g21c7a62+f6e98b25aa,21.0.0-3-g357aad2+bd62456bea,21.0.0-3-g4be5c26+6d3f3f41db,21.0.0-3-g65f322c+03a4076c01,21.0.0-3-g7d9da8d+c4f5df5339,21.0.0-3-gaa929c8+c6b98066dc,21.0.0-3-gc44e71e+a26d5c1aea,21.0.0-3-ge02ed75+04b527a9d5,21.0.0-35-g64f566ff+b27e5ef93e,21.0.0-4-g591bb35+04b527a9d5,21.0.0-4-g88306b8+8773047b2e,21.0.0-4-gc004bbf+80a0b7acb7,21.0.0-4-gccdca77+a5c54364a0,21.0.0-4-ge8fba5a+ccfc328107,21.0.0-5-gdf36809+87b8d260e6,21.0.0-6-g00874e7+7eeda2b6ba,21.0.0-6-g2d4f3f3+e70536a077,21.0.0-6-g4e60332+04b527a9d5,21.0.0-6-g5ef7dad+f53629abd8,21.0.0-7-gc8ca178+b63e69433b,21.0.0-8-gfbe0b4b+c6b98066dc,w.2021.06
LSST Data Management Base Package
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
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:58
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
PYBIND11_MODULE(warpExposure, mod)
int warpExposure(DestExposureT &destExposure, SrcExposureT const &srcExposure, WarpingControl const &control, typename DestExposureT::MaskedImageT::SinglePixel padValue=lsst::afw::math::edgePixel< typename DestExposureT::MaskedImageT >(typename lsst::afw::image::detail::image_traits< typename DestExposureT::MaskedImageT >::image_category()))
Warp (remap) one exposure to another.
A base class for image defects.