LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
warpExposure.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*- // fixed format comment for emacs
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 /*
26  * Support for warping an image to a new WCS.
27  */
28 
29 #ifndef LSST_AFW_MATH_WARPEXPOSURE_H
30 #define LSST_AFW_MATH_WARPEXPOSURE_H
31 
32 #include <memory>
33 #include <string>
34 
35 #include "lsst/base.h"
36 #include "lsst/pex/exceptions.h"
37 #include "lsst/geom.h"
38 #include "lsst/afw/geom.h"
42 #include "lsst/afw/math/Function.h"
44 #include "lsst/afw/math/Kernel.h"
46 
47 namespace lsst {
48 namespace afw {
49 namespace geom {
50 class SkyWcs;
51 }
52 namespace math {
53 
67 public:
69  )
72 
77 
78  ~LanczosWarpingKernel() override = default;
79 
80  std::shared_ptr<Kernel> clone() const override;
81 
85  int getOrder() const;
86 
87  bool isPersistable() const noexcept override { return true; }
88 
89 protected:
90  void setKernelParameter(unsigned int ind, double value) const override;
91 
92  std::string getPersistenceName() const override { return "LanczosWarpingKernel"; }
93 
94  std::string getPythonModule() const override { return "lsst.afw.math"; }
95 
96  void write(OutputArchiveHandle &handle) const override;
97 };
98 
109 public:
112 
117 
118  ~BilinearWarpingKernel() override = default;
119 
120  std::shared_ptr<Kernel> clone() const override;
121 
122  bool isPersistable() const noexcept override { return true; }
123 
131  class BilinearFunction1 : public Function1<Kernel::Pixel> {
132  public:
134 
138  explicit BilinearFunction1(double fracPos)
139  : Function1<Kernel::Pixel>(1) {
140  this->_params[0] = fracPos;
141  }
142  ~BilinearFunction1() override {}
143 
144  Function1Ptr clone() const override { return Function1Ptr(new BilinearFunction1(this->_params[0])); }
145 
153  Kernel::Pixel operator()(double x) const override;
154 
158  std::string toString(std::string const & = "") const override;
159  };
160 
161 protected:
162  void setKernelParameter(unsigned int ind, double value) const override;
163 
164  std::string getPersistenceName() const override { return "BillinearWarpingKernel"; }
165 
166  std::string getPythonModule() const override { return "lsst.afw.math"; }
167 
168  void write(OutputArchiveHandle &handle) const override;
169 };
170 
181 public:
183 
188 
189  ~NearestWarpingKernel() override = default;
190 
191  std::shared_ptr<Kernel> clone() const override;
192 
193  bool isPersistable() const noexcept override { return true; }
194 
202  class NearestFunction1 : public Function1<Kernel::Pixel> {
203  public:
205 
209  explicit NearestFunction1(double fracPos)
210  : Function1<Kernel::Pixel>(1) {
211  this->_params[0] = fracPos;
212  }
213  ~NearestFunction1() override {}
214 
215  Function1Ptr clone() const override { return Function1Ptr(new NearestFunction1(this->_params[0])); }
216 
224  Kernel::Pixel operator()(double x) const override;
225 
229  std::string toString(std::string const & = "") const override;
230  };
231 
232 protected:
233  void setKernelParameter(unsigned int ind, double value) const override;
234 
235  std::string getPersistenceName() const override { return "NearestWarpingKernel"; }
236 
237  std::string getPythonModule() const override { return "lsst.afw.math"; }
238 
239  void write(OutputArchiveHandle &handle) const override;
240 };
241 
267 
275 class WarpingControl final : public table::io::PersistableFacade<WarpingControl>,
276  public table::io::Persistable {
277 public:
284  explicit WarpingControl(
287  std::string const &maskWarpingKernelName = "",
292  int cacheSize = 0,
294  int interpLength = 0,
297  )
298  : _warpingKernelPtr(makeWarpingKernel(warpingKernelName)),
299  _maskWarpingKernelPtr(),
300  _cacheSize(cacheSize),
301  _interpLength(interpLength),
302  _growFullMask(growFullMask) {
303  setMaskWarpingKernelName(maskWarpingKernelName);
304  }
305 
306  virtual ~WarpingControl(){};
307 
311  int getCacheSize() const { return _cacheSize; };
312 
322  ) {
323  _cacheSize = cacheSize;
324  };
325 
329  int getInterpLength() const { return _interpLength; };
330 
340  ) {
341  _interpLength = interpLength;
342  };
343 
348 
353  );
354 
360  void setWarpingKernel(SeparableKernel const &warpingKernel
361  );
362 
367 
371  bool hasMaskWarpingKernel() const { return static_cast<bool>(_maskWarpingKernelPtr); }
372 
376  void setMaskWarpingKernelName(std::string const &maskWarpingKernelName
378  );
379 
385  void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel
386  );
387 
391  lsst::afw::image::MaskPixel getGrowFullMask() const { return _growFullMask; };
392 
398  ) {
399  _growFullMask = growFullMask;
400  }
401 
402  bool isPersistable() const noexcept override;
403 
404 protected:
405  std::string getPersistenceName() const override;
406  std::string getPythonModule() const override;
407  void write(OutputArchiveHandle &handle) const override;
408 
409 private:
416  void _testWarpingKernels(SeparableKernel const &warpingKernel,
417  SeparableKernel const &maskWarpingKernel
418  ) const;
419 
420  std::shared_ptr<SeparableKernel> _warpingKernelPtr;
421  std::shared_ptr<SeparableKernel> _maskWarpingKernelPtr;
422  int _cacheSize;
423  int _interpLength;
424  lsst::afw::image::MaskPixel _growFullMask;
425 };
426 
432 template <typename DestExposureT, typename SrcExposureT>
433 int warpExposure(
434  DestExposureT &destExposure,
437  SrcExposureT const &srcExposure,
438  WarpingControl const &control,
439  typename DestExposureT::MaskedImageT::SinglePixel padValue =
440  lsst::afw::math::edgePixel<typename DestExposureT::MaskedImageT>(
441  typename lsst::afw::image::detail::image_traits<
442  typename DestExposureT::MaskedImageT>::image_category())
444 );
445 
492 template <typename DestImageT, typename SrcImageT>
493 int warpImage(DestImageT &destImage,
494  geom::SkyWcs const &destWcs,
495  SrcImageT const &srcImage,
496  geom::SkyWcs const &srcWcs,
497  WarpingControl const &control,
498  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
499  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
501 );
502 
517 template <typename DestImageT, typename SrcImageT>
518 int warpImage(DestImageT &destImage, SrcImageT const &srcImage,
519  geom::TransformPoint2ToPoint2 const &srcToDest, WarpingControl const &control,
520  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
521  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category()));
522 
528 template <typename DestImageT, typename SrcImageT>
530  DestImageT &destImage,
531  SrcImageT const &srcImage,
532  lsst::geom::LinearTransform const &linearTransform,
533  lsst::geom::Point2D const &centerPosition,
534  WarpingControl const &control,
535  typename DestImageT::SinglePixel padValue = lsst::afw::math::edgePixel<DestImageT>(
536  typename lsst::afw::image::detail::image_traits<DestImageT>::image_category())
538 );
539 
540 } // namespace math
541 } // namespace afw
542 } // namespace lsst
543 
544 #endif // !defined(LSST_AFW_MATH_WARPEXPOSURE_H)
table::Key< std::string > name
Definition: Amplifier.cc:116
double x
Basic LSST definitions.
1-dimensional bilinear interpolation function.
Definition: warpExposure.h:131
std::string toString(std::string const &="") const override
Return string representation.
Function1Ptr clone() const override
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:144
BilinearFunction1(double fracPos)
Construct a Bilinear interpolation function.
Definition: warpExposure.h:138
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:133
Kernel::Pixel operator()(double x) const override
Solve bilinear equation.
Bilinear warping: fast; good for undersampled data.
Definition: warpExposure.h:108
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: warpExposure.h:166
BilinearWarpingKernel & operator=(BilinearWarpingKernel &&)=delete
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: warpExposure.h:164
BilinearWarpingKernel & operator=(const BilinearWarpingKernel &)=delete
BilinearWarpingKernel(BilinearWarpingKernel &&)=delete
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: warpExposure.h:122
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
BilinearWarpingKernel(const BilinearWarpingKernel &)=delete
A Function taking one argument.
Definition: Function.h:202
std::vector< double > _params
Definition: Function.h:185
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:110
1-dimensional Lanczos function
Lanczos warping: accurate but slow and can introduce ringing artifacts.
Definition: warpExposure.h:66
int getOrder() const
get the order of the kernel
LanczosWarpingKernel(const LanczosWarpingKernel &)=delete
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: warpExposure.h:87
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
~LanczosWarpingKernel() override=default
LanczosWarpingKernel & operator=(const LanczosWarpingKernel &)=delete
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: warpExposure.h:92
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: warpExposure.cc:97
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: warpExposure.h:94
LanczosWarpingKernel & operator=(LanczosWarpingKernel &&)=delete
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
LanczosWarpingKernel(LanczosWarpingKernel &&)=delete
1-dimensional nearest neighbor interpolation function.
Definition: warpExposure.h:202
NearestFunction1(double fracPos)
Construct a Nearest interpolation function.
Definition: warpExposure.h:209
Kernel::Pixel operator()(double x) const override
Solve nearest neighbor equation.
Function1Ptr clone() const override
Return a pointer to a deep copy of this function.
Definition: warpExposure.h:215
std::shared_ptr< Function1< Kernel::Pixel > > Function1Ptr
Definition: warpExposure.h:204
std::string toString(std::string const &="") const override
Return string representation.
Nearest neighbor warping: fast; good for undersampled data.
Definition: warpExposure.h:180
NearestWarpingKernel(NearestWarpingKernel &&)=delete
NearestWarpingKernel & operator=(NearestWarpingKernel &&)=delete
NearestWarpingKernel(const NearestWarpingKernel &)=delete
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
NearestWarpingKernel & operator=(const NearestWarpingKernel &)=delete
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: warpExposure.h:237
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
~NearestWarpingKernel() override=default
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: warpExposure.h:193
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: warpExposure.h:235
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:860
Parameters to control convolution.
Definition: warpExposure.h:276
bool hasMaskWarpingKernel() const
return true if there is a mask kernel
Definition: warpExposure.h:371
lsst::afw::image::MaskPixel getGrowFullMask() const
get mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:391
void setWarpingKernel(SeparableKernel const &warpingKernel)
set the warping kernel
int getInterpLength() const
get the interpolation length (pixels)
Definition: warpExposure.h:329
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
void setWarpingKernelName(std::string const &warpingKernelName)
set the warping kernel by name
void setMaskWarpingKernelName(std::string const &maskWarpingKernelName)
set or clear the mask warping kernel by name
void setCacheSize(int cacheSize)
set the cache size for the interpolation kernel(s)
Definition: warpExposure.h:321
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
int getCacheSize() const
get the cache size for the interpolation kernel(s)
Definition: warpExposure.h:311
void setMaskWarpingKernel(SeparableKernel const &maskWarpingKernel)
set the mask warping kernel
std::shared_ptr< SeparableKernel > getWarpingKernel() const
get the warping kernel
void setGrowFullMask(lsst::afw::image::MaskPixel growFullMask)
set mask bits to grow to full width of image/variance kernel
Definition: warpExposure.h:396
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
void setInterpLength(int interpLength)
set the interpolation length
Definition: warpExposure.h:339
std::shared_ptr< SeparableKernel > getMaskWarpingKernel() const
get the mask warping kernel
WarpingControl(std::string const &warpingKernelName, std::string const &maskWarpingKernelName="", int cacheSize=0, int interpLength=0, lsst::afw::image::MaskPixel growFullMask=0)
Construct a WarpingControl object.
Definition: warpExposure.h:284
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
class[[deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be " "removed after v22.")]] FilterProperty final
Describe the properties of a Filter (e.g.
Definition: Filter.h:53
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
int warpCenteredImage(DestImageT &destImage, SrcImageT const &srcImage, lsst::geom::LinearTransform const &linearTransform, lsst::geom::Point2D const &centerPosition, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
Warp an image with a LinearTranform about a specified point.
int warpImage(DestImageT &destImage, geom::SkyWcs const &destWcs, SrcImageT const &srcImage, geom::SkyWcs const &srcWcs, WarpingControl const &control, typename DestImageT::SinglePixel padValue=lsst::afw::math::edgePixel< DestImageT >(typename lsst::afw::image::detail::image_traits< DestImageT >::image_category()))
Warp an Image or MaskedImage to a new Wcs.
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.
ImageT::SinglePixel edgePixel(lsst::afw::image::detail::Image_tag)
Return an off-the-edge pixel appropriate for a given Image type.
Point< double, 2 > Point2D
Definition: Point.h:324
A base class for image defects.
STL namespace.
afw::table::Key< std::string > warpingKernelName
Definition: CoaddPsf.cc:350
table::Key< int > interpLength
table::Key< image::MaskPixel > growFullMask
table::Key< int > order
table::Key< int > cacheSize