LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Kernel.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2016 AURA/LSST.
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 #ifndef LSST_AFW_MATH_KERNEL_H
26 #define LSST_AFW_MATH_KERNEL_H
27 /*
28  * Declare the Kernel class and subclasses.
29  */
30 #include <memory>
31 #include <type_traits>
32 #include <utility>
33 #include <vector>
34 
35 #include "boost/format.hpp"
36 
37 #include "lsst/geom.h"
38 #include "lsst/afw/image/Image.h"
39 #include "lsst/afw/math/Function.h"
40 #include "lsst/afw/math/traits.h"
41 
43 
44 namespace lsst {
45 namespace afw {
46 
47 namespace math {
48 
111 public:
112  using Pixel = double;
116 
117  // Traits values for this class of Kernel
119 
125  explicit Kernel();
126 
140  explicit Kernel(int width, int height, unsigned int nKernelParams,
141  SpatialFunction const &spatialFunction = NullSpatialFunction());
142 
154  explicit Kernel(int width, int height, const std::vector<SpatialFunctionPtr> spatialFunctionList);
155 
156  // prevent copying and assignment (to avoid problems from type slicing)
157  Kernel(const Kernel &) = delete;
158  Kernel(Kernel &&) = delete;
159  Kernel &operator=(const Kernel &) = delete;
160  Kernel &operator=(Kernel &&) = delete;
161 
162  ~Kernel() override = default;
163 
175  virtual std::shared_ptr<Kernel> clone() const = 0;
176 
187  virtual std::shared_ptr<Kernel> resized(int width, int height) const = 0;
188 
206  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
207  double y = 0.0) const;
208 
212  lsst::geom::Extent2I const getDimensions() const { return lsst::geom::Extent2I(_width, _height); }
213 
215  _width = dims.getX();
216  _height = dims.getY();
217  }
218  inline void setWidth(int width) { _width = width; }
219  inline void setHeight(int height) { _height = height; }
220 
224  inline int getWidth() const { return _width; }
225 
229  inline int getHeight() const { return _height; }
230 
234  inline lsst::geom::Point2I getCtr() const { return lsst::geom::Point2I(_ctrX, _ctrY); }
235 
239  inline lsst::geom::Box2I getBBox() const {
240  return lsst::geom::Box2I(lsst::geom::Point2I(-_ctrX, -_ctrY), lsst::geom::Extent2I(_width, _height));
241  }
242 
246  inline unsigned int getNKernelParameters() const { return _nKernelParams; }
247 
251  inline int getNSpatialParameters() const {
252  return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
253  }
254 
265  SpatialFunctionPtr getSpatialFunction(unsigned int index) const;
266 
274 
277  virtual double getKernelParameter(unsigned int i) const { return getKernelParameters()[i]; }
278 
287 
296 
308 
312  inline void setCtr(lsst::geom::Point2I ctr) {
313  _ctrX = ctr.getX();
314  _ctrY = ctr.getY();
315  _setKernelXY();
316  }
317 
322  std::vector<std::vector<double>> spatialParams;
324  for (; spFuncIter != _spatialFunctionList.end(); ++spFuncIter) {
325  spatialParams.push_back((*spFuncIter)->getParameters());
326  }
327  return spatialParams;
328  }
329 
333  inline bool isSpatiallyVarying() const { return _spatialFunctionList.size() != 0; }
334 
341  inline void setKernelParameters(std::vector<double> const &params) {
342  if (this->isSpatiallyVarying()) {
343  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Kernel is spatially varying");
344  }
345  const unsigned int nParams = this->getNKernelParameters();
346  if (nParams != params.size()) {
348  (boost::format("Number of parameters is wrong, saw %d expected %d") % nParams %
349  params.size())
350  .str());
351  }
352  for (unsigned int ii = 0; ii < nParams; ++ii) {
353  this->setKernelParameter(ii, params[ii]);
354  }
355  }
356 
363  inline void setKernelParameters(std::pair<double, double> const &params) {
364  this->setKernelParameter(0, params.first);
365  this->setKernelParameter(1, params.second);
366  }
367 
377 
384  void computeKernelParametersFromSpatialModel(std::vector<double> &kernelParams, double x, double y) const;
385 
389  virtual std::string toString(std::string const &prefix = "") const;
390 
397  virtual void computeCache(int const
398  ) {}
399 
403  virtual int getCacheSize() const { return 0; };
404 
405 #if 0 // fails to compile with icc; is it actually used?
406  virtual void toFile(std::string fileName) const;
407 #endif
408 
409  struct PersistenceHelper;
410 
411 protected:
412  std::string getPythonModule() const override;
413 
424  virtual void setKernelParameter(unsigned int ind, double value) const;
425 
434  void setKernelParametersFromSpatialModel(double x, double y) const;
435 
447  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const = 0;
448 
450 
451 private:
452  int _width;
453  int _height;
454  int _ctrX;
455  int _ctrY;
456  unsigned int _nKernelParams;
457 
458  // Set the Kernel's ideas about the x- and y- coordinates
459  virtual void _setKernelXY() {}
460 };
461 
463 
471 class FixedKernel : public afw::table::io::PersistableFacade<FixedKernel>, public Kernel {
472 public:
476  explicit FixedKernel();
477 
482  );
483 
487  explicit FixedKernel(lsst::afw::math::Kernel const &kernel,
488  lsst::geom::Point2D const &pos
489  );
490 
491  FixedKernel(const FixedKernel &) = delete;
492  FixedKernel(FixedKernel &&) = delete;
493  FixedKernel &operator=(const FixedKernel &) = delete;
495 
496  ~FixedKernel() override = default;
497 
498  std::shared_ptr<Kernel> clone() const override;
499 
500  std::shared_ptr<Kernel> resized(int width, int height) const override;
501 
502  std::string toString(std::string const &prefix = "") const override;
503 
504  virtual Pixel getSum() const { return _sum; }
505 
506  bool isPersistable() const noexcept override { return true; }
507 
508  class Factory;
509 
510 protected:
511  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
512 
513  std::string getPersistenceName() const override;
514 
515  void write(OutputArchiveHandle &handle) const override;
516 
517 private:
519  Pixel _sum;
520 };
521 
535 class AnalyticKernel : public afw::table::io::PersistableFacade<AnalyticKernel>, public Kernel {
536 public:
539 
543  explicit AnalyticKernel();
544 
557  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
558  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
559 
573  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
574  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
575 
576  AnalyticKernel(const AnalyticKernel &) = delete;
580 
581  ~AnalyticKernel() override = default;
582 
583  std::shared_ptr<Kernel> clone() const override;
584 
585  std::shared_ptr<Kernel> resized(int width, int height) const override;
586 
607  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
608  double y = 0.0) const;
609 
610  std::vector<double> getKernelParameters() const override;
611 
615  virtual KernelFunctionPtr getKernelFunction() const;
616 
617  std::string toString(std::string const &prefix = "") const override;
618 
619  bool isPersistable() const noexcept override { return true; }
620 
621  class Factory;
622 
623 protected:
624  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
625 
626  std::string getPersistenceName() const override;
627 
628  void write(OutputArchiveHandle &handle) const override;
629 
630 protected:
631  void setKernelParameter(unsigned int ind, double value) const override;
632 
634 };
635 
643 class DeltaFunctionKernel : public afw::table::io::PersistableFacade<DeltaFunctionKernel>, public Kernel {
644 public:
645  // Traits values for this class of Kernel
647 
657  explicit DeltaFunctionKernel(int width, int height, lsst::geom::Point2I const &point);
658 
663 
664  ~DeltaFunctionKernel() override = default;
665 
666  std::shared_ptr<Kernel> clone() const override;
667 
668  std::shared_ptr<Kernel> resized(int width, int height) const override;
669 
670  lsst::geom::Point2I getPixel() const { return _pixel; }
671 
672  std::string toString(std::string const &prefix = "") const override;
673 
674  bool isPersistable() const noexcept override { return true; }
675 
676  class Factory;
677 
678 protected:
679  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
680 
681  std::string getPersistenceName() const override;
682 
683  void write(OutputArchiveHandle &handle) const override;
684 
685 private:
686  lsst::geom::Point2I _pixel;
687 };
688 
703 class LinearCombinationKernel : public afw::table::io::PersistableFacade<LinearCombinationKernel>,
704  public Kernel {
705 public:
709  explicit LinearCombinationKernel();
710 
717  explicit LinearCombinationKernel(KernelList const &kernelList,
718  std::vector<double> const &kernelParameters);
719 
727  explicit LinearCombinationKernel(KernelList const &kernelList,
728  Kernel::SpatialFunction const &spatialFunction);
729 
739  explicit LinearCombinationKernel(KernelList const &kernelList,
740  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
741 
746 
747  ~LinearCombinationKernel() override = default;
748 
749  std::shared_ptr<Kernel> clone() const override;
750 
751  std::shared_ptr<Kernel> resized(int width, int height) const override;
752 
753  std::vector<double> getKernelParameters() const override;
754 
758  virtual KernelList const &getKernelList() const;
759 
764 
768  int getNBasisKernels() const { return static_cast<int>(_kernelList.size()); };
769 
775  void checkKernelList(const KernelList &kernelList) const;
776 
780  bool isDeltaFunctionBasis() const { return _isDeltaFunctionBasis; };
781 
817 
818  std::string toString(std::string const &prefix = "") const override;
819 
820  bool isPersistable() const noexcept override { return true; }
821 
822  class Factory;
823 
824 protected:
825  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
826 
827  std::string getPersistenceName() const override;
828 
829  void write(OutputArchiveHandle &handle) const override;
830 
831  void setKernelParameter(unsigned int ind, double value) const override;
832 
833 private:
837  void _setKernelList(KernelList const &kernelList);
838 
839  KernelList _kernelList;
842  std::vector<double> _kernelSumList;
843  mutable std::vector<double> _kernelParams;
844  bool _isDeltaFunctionBasis;
845 };
846 
860 class SeparableKernel : public afw::table::io::PersistableFacade<SeparableKernel>, public Kernel {
861 public:
864 
868  explicit SeparableKernel();
869 
882  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
883  KernelFunction const &kernelRowFunction,
884  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
885 
899  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
900  KernelFunction const &kernelRowFunction,
901  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
902 
903  SeparableKernel(const SeparableKernel &) = delete;
907 
908  ~SeparableKernel() override = default;
909 
910  std::shared_ptr<Kernel> clone() const override;
911 
912  std::shared_ptr<Kernel> resized(int width, int height) const override;
913 
930  double computeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList, bool doNormalize,
931  double x = 0.0, double y = 0.0) const;
932 
933  double getKernelParameter(unsigned int i) const override {
934  unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
935  if (i < ncol) {
936  return _kernelColFunctionPtr->getParameter(i);
937  } else {
938  i -= ncol;
939  return _kernelRowFunctionPtr->getParameter(i);
940  }
941  }
942  std::vector<double> getKernelParameters() const override;
943 
948 
953 
954  std::string toString(std::string const &prefix = "") const override;
955 
956  /***
957  * Compute a cache of values for the x and y kernel functions
958  *
959  * A value of 0 disables the cache for maximum accuracy.
960  * 10,000 typically results in a warping error of a fraction of a count.
961  * 100,000 typically results in a warping error of less than 0.01 count.
962  *
963  * @param cacheSize cache size (number of double precision array elements in the x and y caches)
964  */
965  void computeCache(int const cacheSize) override;
966 
970  int getCacheSize() const override;
971 
972 protected:
973  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
974 
975  void setKernelParameter(unsigned int ind, double value) const override;
976 
977 private:
991  double basicComputeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList,
992  bool doNormalize) const;
993 
994  KernelFunctionPtr _kernelColFunctionPtr;
995  KernelFunctionPtr _kernelRowFunctionPtr;
996  mutable std::vector<Pixel> _localColList; // used by doComputeImage
997  mutable std::vector<Pixel> _localRowList;
998  mutable std::vector<double> _kernelX; // used by SeparableKernel::basicComputeVectors
999  mutable std::vector<double> _kernelY;
1000  //
1001  // Cached values of the row- and column- kernels
1002  //
1003  mutable std::vector<std::vector<double>> _kernelRowCache;
1004  mutable std::vector<std::vector<double>> _kernelColCache;
1005 
1006  virtual void _setKernelXY() override {
1007  lsst::geom::Extent2I const dim = getDimensions();
1008  lsst::geom::Point2I const ctr = getCtr();
1009 
1010  assert(dim[0] == static_cast<int>(_kernelX.size()));
1011  for (int i = 0; i != dim.getX(); ++i) {
1012  _kernelX[i] = i - ctr.getX();
1013  }
1014 
1015  assert(dim[1] == static_cast<int>(_kernelY.size()));
1016  for (int i = 0; i != dim.getY(); ++i) {
1017  _kernelY[i] = i - ctr.getY();
1018  }
1019  }
1020 };
1021 } // namespace math
1022 } // namespace afw
1023 } // namespace lsst
1024 
1025 #endif // !defined(LSST_AFW_MATH_KERNEL_H)
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
table::Key< int > kernelFunction
double x
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
std::string prefix
Definition: SchemaMapper.cc:72
int y
Definition: SpanSet.cc:48
A kernel described by a function.
Definition: Kernel.h:535
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:619
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
AnalyticKernel(AnalyticKernel &&)=delete
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
AnalyticKernel & operator=(const AnalyticKernel &)=delete
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
AnalyticKernel(const AnalyticKernel &)=delete
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
KernelFunctionPtr _kernelFunctionPtr
Definition: Kernel.h:633
AnalyticKernel & operator=(AnalyticKernel &&)=delete
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
AnalyticKernel()
Construct an empty spatially invariant AnalyticKernel of size 0x0.
~AnalyticKernel() override=default
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:643
DeltaFunctionKernel(int width, int height, lsst::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
DeltaFunctionKernel & operator=(DeltaFunctionKernel &&)=delete
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
~DeltaFunctionKernel() override=default
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
lsst::geom::Point2I getPixel() const
Definition: Kernel.h:670
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
DeltaFunctionKernel(DeltaFunctionKernel &&)=delete
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:674
DeltaFunctionKernel(const DeltaFunctionKernel &)=delete
DeltaFunctionKernel & operator=(const DeltaFunctionKernel &)=delete
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
A kernel created from an Image.
Definition: Kernel.h:471
FixedKernel(FixedKernel &&)=delete
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: FixedKernel.cc:180
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: FixedKernel.cc:62
FixedKernel()
Construct an empty FixedKernel of size 0x0.
Definition: FixedKernel.cc:43
FixedKernel & operator=(FixedKernel &&)=delete
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
Definition: FixedKernel.cc:105
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
Definition: FixedKernel.cc:68
~FixedKernel() override=default
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:506
virtual Pixel getSum() const
Definition: Kernel.h:504
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
Definition: FixedKernel.cc:128
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: FixedKernel.cc:182
FixedKernel & operator=(const FixedKernel &)=delete
FixedKernel(const FixedKernel &)=delete
A Function taking one argument.
Definition: Function.h:202
A Function taking two arguments.
Definition: Function.h:259
virtual double getParameter(unsigned int ind) const
Get one function parameter without range checking.
Definition: Function.h:119
unsigned int getNParameters() const noexcept
Return the number of function parameters.
Definition: Function.h:112
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:110
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
Definition: Kernel.h:212
virtual void _setKernelXY()
Definition: Kernel.h:459
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:449
Kernel & operator=(const Kernel &)=delete
Kernel(const Kernel &)=delete
virtual void computeCache(int const)
Compute a cache of Kernel values, if desired.
Definition: Kernel.h:397
int getHeight() const
Return the Kernel's height.
Definition: Kernel.h:229
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
Definition: Kernel.h:234
void setKernelParameters(std::vector< double > const &params)
Set the kernel parameters of a spatially invariant kernel.
Definition: Kernel.h:341
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
Definition: Kernel.h:246
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
Definition: Kernel.h:277
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:113
virtual std::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
Kernel & operator=(Kernel &&)=delete
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
Definition: Kernel.h:251
void setWidth(int width)
Definition: Kernel.h:218
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
Definition: Kernel.cc:157
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
Definition: Kernel.cc:165
~Kernel() override=default
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:185
lsst::afw::math::NullFunction2< double > NullSpatialFunction
Definition: Kernel.h:115
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
Definition: Kernel.cc:135
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model)
Definition: Kernel.cc:144
void setCtr(lsst::geom::Point2I ctr)
Set index of kernel's center.
Definition: Kernel.h:312
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
Definition: Kernel.h:403
void setKernelParameters(std::pair< double, double > const &params)
Set the kernel parameters of a 2-component spatially invariant kernel.
Definition: Kernel.h:363
lsst::geom::Box2I shrinkBBox(lsst::geom::Box2I const &bbox) const
Given a bounding box for an image one wishes to convolve with this kernel, return the bounding box fo...
Definition: Kernel.cc:173
virtual std::shared_ptr< Kernel > resized(int width, int height) const =0
Return a pointer to a clone with specified kernel dimensions.
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying)
Definition: Kernel.h:321
int getWidth() const
Return the Kernel's width.
Definition: Kernel.h:224
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:333
lsst::geom::Box2I growBBox(lsst::geom::Box2I const &bbox) const
Given a bounding box for pixels one wishes to compute by convolving an image with this kernel,...
Definition: Kernel.cc:167
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Definition: Kernel.cc:213
void setHeight(int height)
Definition: Kernel.h:219
void setDimensions(lsst::geom::Extent2I dims)
Definition: Kernel.h:214
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: Kernel.cc:224
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
Definition: Kernel.cc:76
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
void setSpatialParameters(const std::vector< std::vector< double >> params)
Set the parameters of all spatial functions.
Definition: Kernel.cc:110
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:49
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
Definition: Kernel.cc:217
Kernel(Kernel &&)=delete
lsst::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:239
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:704
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:820
std::vector< double > getKernelSumList() const
Get the sum of the pixels of each fixed basis kernel.
std::shared_ptr< Kernel > refactor() const
Refactor the kernel as a linear combination of N bases where N is the number of parameters for the sp...
virtual KernelList const & getKernelList() const
Get the fixed basis kernels.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
LinearCombinationKernel & operator=(const LinearCombinationKernel &)=delete
LinearCombinationKernel()
Construct an empty LinearCombinationKernel of size 0x0.
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
LinearCombinationKernel & operator=(LinearCombinationKernel &&)=delete
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
int getNBasisKernels() const
Get the number of basis kernels.
Definition: Kernel.h:768
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
LinearCombinationKernel(LinearCombinationKernel &&)=delete
LinearCombinationKernel(const LinearCombinationKernel &)=delete
bool isDeltaFunctionBasis() const
Return true if all basis kernels are instances of DeltaFunctionKernel.
Definition: Kernel.h:780
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
a class used in function calls to indicate that no Function2 is being provided
Definition: Function.h:458
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:860
~SeparableKernel() override=default
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
SeparableKernel(SeparableKernel &&)=delete
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
std::shared_ptr< KernelFunction > KernelFunctionPtr
Definition: Kernel.h:863
double getKernelParameter(unsigned int i) const override
Return a particular Kernel Parameter (no bounds checking).
Definition: Kernel.h:933
int getCacheSize() const override
Get the current cache size (0 if none)
SeparableKernel & operator=(SeparableKernel &&)=delete
SeparableKernel & operator=(const SeparableKernel &)=delete
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
SeparableKernel(const SeparableKernel &)=delete
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
double computeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize, double x=0.0, double y=0.0) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row)
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
virtual void _setKernelXY() override
Definition: Kernel.h:1006
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
SeparableKernel()
Construct an empty spatially invariant SeparableKernel of size 0x0.
void computeCache(int const cacheSize) override
Compute a cache of Kernel values, if desired.
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
An integer coordinate rectangle.
Definition: Box.h:55
Reports invalid arguments.
Definition: Runtime.h:66
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Extent< int, 2 > Extent2I
Definition: Extent.h:397
Point< int, 2 > Point2I
Definition: Point.h:321
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
A base class for image defects.
T push_back(T... args)
T size(T... args)
Kernel has only one non-zero pixel.
Definition: traits.h:56
Tags carrying information about Kernels Kernel with no special properties.
Definition: traits.h:53
table::Key< int > cacheSize