LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
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/mpl/or.hpp"
36 
37 #include "lsst/geom.h"
38 #include "lsst/afw/image/Image.h"
39 #include "lsst/afw/image/Utils.h"
40 #include "lsst/afw/math/Function.h"
41 #include "lsst/afw/math/traits.h"
42 
44 
45 namespace lsst {
46 namespace afw {
47 
48 namespace math {
49 
112 public:
113  typedef double Pixel;
117 
118  // Traits values for this class of Kernel
120 
126  explicit Kernel();
127 
141  explicit Kernel(int width, int height, unsigned int nKernelParams,
142  SpatialFunction const &spatialFunction = NullSpatialFunction());
143 
155  explicit Kernel(int width, int height, const std::vector<SpatialFunctionPtr> spatialFunctionList);
156 
157  // prevent copying and assignment (to avoid problems from type slicing)
158  Kernel(const Kernel &) = delete;
159  Kernel(Kernel &&) = delete;
160  Kernel &operator=(const Kernel &) = delete;
161  Kernel &operator=(Kernel &&) = delete;
162 
163  ~Kernel() override = default;
164 
176  virtual std::shared_ptr<Kernel> clone() const = 0;
177 
188  virtual std::shared_ptr<Kernel> resized(int width, int height) const = 0;
189 
207  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
208  double y = 0.0) const;
209 
213  lsst::geom::Extent2I const getDimensions() const { return lsst::geom::Extent2I(_width, _height); }
214 
216  _width = dims.getX();
217  _height = dims.getY();
218  }
219  inline void setWidth(int width) { _width = width; }
220  inline void setHeight(int height) { _height = height; }
221 
225  inline int getWidth() const { return _width; }
226 
230  inline int getHeight() const { return _height; }
231 
235  inline lsst::geom::Point2I getCtr() const { return lsst::geom::Point2I(_ctrX, _ctrY); }
236 
240  inline lsst::geom::Box2I getBBox() const {
241  return lsst::geom::Box2I(lsst::geom::Point2I(-_ctrX, -_ctrY), lsst::geom::Extent2I(_width, _height));
242  }
243 
247  inline unsigned int getNKernelParameters() const { return _nKernelParams; }
248 
252  inline int getNSpatialParameters() const {
253  return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
254  }
255 
266  SpatialFunctionPtr getSpatialFunction(unsigned int index) const;
267 
275 
278  virtual double getKernelParameter(unsigned int i) const { return getKernelParameters()[i]; }
279 
288 
297 
309 
313  inline void setCtr(lsst::geom::Point2I ctr) {
314  _ctrX = ctr.getX();
315  _ctrY = ctr.getY();
316  _setKernelXY();
317  }
318 
323  std::vector<std::vector<double>> spatialParams;
325  for (; spFuncIter != _spatialFunctionList.end(); ++spFuncIter) {
326  spatialParams.push_back((*spFuncIter)->getParameters());
327  }
328  return spatialParams;
329  }
330 
334  inline bool isSpatiallyVarying() const { return _spatialFunctionList.size() != 0; }
335 
342  inline void setKernelParameters(std::vector<double> const &params) {
343  if (this->isSpatiallyVarying()) {
344  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Kernel is spatially varying");
345  }
346  const unsigned int nParams = this->getNKernelParameters();
347  if (nParams != params.size()) {
349  (boost::format("Number of parameters is wrong, saw %d expected %d") % nParams %
350  params.size())
351  .str());
352  }
353  for (unsigned int ii = 0; ii < nParams; ++ii) {
354  this->setKernelParameter(ii, params[ii]);
355  }
356  }
357 
364  inline void setKernelParameters(std::pair<double, double> const &params) {
365  this->setKernelParameter(0, params.first);
366  this->setKernelParameter(1, params.second);
367  }
368 
378 
385  void computeKernelParametersFromSpatialModel(std::vector<double> &kernelParams, double x, double y) const;
386 
390  virtual std::string toString(std::string const &prefix = "") const;
391 
398  virtual void computeCache(int const
399  ) {}
400 
404  virtual int getCacheSize() const { return 0; };
405 
406 #if 0 // fails to compile with icc; is it actually used?
407  virtual void toFile(std::string fileName) const;
408 #endif
409 
410  struct PersistenceHelper;
411 
412 protected:
413  std::string getPythonModule() const override;
414 
425  virtual void setKernelParameter(unsigned int ind, double value) const;
426 
435  void setKernelParametersFromSpatialModel(double x, double y) const;
436 
448  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const = 0;
449 
451 
452 private:
453  int _width;
454  int _height;
455  int _ctrX;
456  int _ctrY;
457  unsigned int _nKernelParams;
458 
459  // Set the Kernel's ideas about the x- and y- coordinates
460  virtual void _setKernelXY() {}
461 };
462 
464 
472 class FixedKernel : public afw::table::io::PersistableFacade<FixedKernel>, public Kernel {
473 public:
477  explicit FixedKernel();
478 
483  );
484 
488  explicit FixedKernel(lsst::afw::math::Kernel const &kernel,
489  lsst::geom::Point2D const &pos
490  );
491 
492  FixedKernel(const FixedKernel &) = delete;
493  FixedKernel(FixedKernel &&) = delete;
494  FixedKernel &operator=(const FixedKernel &) = delete;
496 
497  ~FixedKernel() override = default;
498 
499  std::shared_ptr<Kernel> clone() const override;
500 
501  std::shared_ptr<Kernel> resized(int width, int height) const override;
502 
503  std::string toString(std::string const &prefix = "") const override;
504 
505  virtual Pixel getSum() const { return _sum; }
506 
507  bool isPersistable() const noexcept override { return true; }
508 
509  class Factory;
510 
511 protected:
512  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
513 
514  std::string getPersistenceName() const override;
515 
516  void write(OutputArchiveHandle &handle) const override;
517 
518 private:
520  Pixel _sum;
521 };
522 
536 class AnalyticKernel : public afw::table::io::PersistableFacade<AnalyticKernel>, public Kernel {
537 public:
540 
544  explicit AnalyticKernel();
545 
558  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
559  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
560 
574  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
575  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
576 
577  AnalyticKernel(const AnalyticKernel &) = delete;
581 
582  ~AnalyticKernel() override = default;
583 
584  std::shared_ptr<Kernel> clone() const override;
585 
586  std::shared_ptr<Kernel> resized(int width, int height) const override;
587 
608  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
609  double y = 0.0) const;
610 
611  std::vector<double> getKernelParameters() const override;
612 
616  virtual KernelFunctionPtr getKernelFunction() const;
617 
618  std::string toString(std::string const &prefix = "") const override;
619 
620  bool isPersistable() const noexcept override { return true; }
621 
622  class Factory;
623 
624 protected:
625  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
626 
627  std::string getPersistenceName() const override;
628 
629  void write(OutputArchiveHandle &handle) const override;
630 
631 protected:
632  void setKernelParameter(unsigned int ind, double value) const override;
633 
635 };
636 
644 class DeltaFunctionKernel : public afw::table::io::PersistableFacade<DeltaFunctionKernel>, public Kernel {
645 public:
646  // Traits values for this class of Kernel
648 
658  explicit DeltaFunctionKernel(int width, int height, lsst::geom::Point2I const &point);
659 
664 
665  ~DeltaFunctionKernel() override = default;
666 
667  std::shared_ptr<Kernel> clone() const override;
668 
669  std::shared_ptr<Kernel> resized(int width, int height) const override;
670 
671  lsst::geom::Point2I getPixel() const { return _pixel; }
672 
673  std::string toString(std::string const &prefix = "") const override;
674 
675  bool isPersistable() const noexcept override { return true; }
676 
677  class Factory;
678 
679 protected:
680  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
681 
682  std::string getPersistenceName() const override;
683 
684  void write(OutputArchiveHandle &handle) const override;
685 
686 private:
687  lsst::geom::Point2I _pixel;
688 };
689 
704 class LinearCombinationKernel : public afw::table::io::PersistableFacade<LinearCombinationKernel>,
705  public Kernel {
706 public:
710  explicit LinearCombinationKernel();
711 
718  explicit LinearCombinationKernel(KernelList const &kernelList,
719  std::vector<double> const &kernelParameters);
720 
728  explicit LinearCombinationKernel(KernelList const &kernelList,
729  Kernel::SpatialFunction const &spatialFunction);
730 
740  explicit LinearCombinationKernel(KernelList const &kernelList,
741  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
742 
747 
748  ~LinearCombinationKernel() override = default;
749 
750  std::shared_ptr<Kernel> clone() const override;
751 
752  std::shared_ptr<Kernel> resized(int width, int height) const override;
753 
754  std::vector<double> getKernelParameters() const override;
755 
759  virtual KernelList const &getKernelList() const;
760 
765 
769  int getNBasisKernels() const { return static_cast<int>(_kernelList.size()); };
770 
776  void checkKernelList(const KernelList &kernelList) const;
777 
781  bool isDeltaFunctionBasis() const { return _isDeltaFunctionBasis; };
782 
818 
819  std::string toString(std::string const &prefix = "") const override;
820 
821  bool isPersistable() const noexcept override { return true; }
822 
823  class Factory;
824 
825 protected:
826  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
827 
828  std::string getPersistenceName() const override;
829 
830  void write(OutputArchiveHandle &handle) const override;
831 
832  void setKernelParameter(unsigned int ind, double value) const override;
833 
834 private:
838  void _setKernelList(KernelList const &kernelList);
839 
840  KernelList _kernelList;
843  std::vector<double> _kernelSumList;
844  mutable std::vector<double> _kernelParams;
845  bool _isDeltaFunctionBasis;
846 };
847 
861 class SeparableKernel : public afw::table::io::PersistableFacade<SeparableKernel>, public Kernel {
862 public:
865 
869  explicit SeparableKernel();
870 
883  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
884  KernelFunction const &kernelRowFunction,
885  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
886 
900  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
901  KernelFunction const &kernelRowFunction,
902  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
903 
904  SeparableKernel(const SeparableKernel &) = delete;
908 
909  ~SeparableKernel() override = default;
910 
911  std::shared_ptr<Kernel> clone() const override;
912 
913  std::shared_ptr<Kernel> resized(int width, int height) const override;
914 
931  double computeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList, bool doNormalize,
932  double x = 0.0, double y = 0.0) const;
933 
934  double getKernelParameter(unsigned int i) const override {
935  unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
936  if (i < ncol) {
937  return _kernelColFunctionPtr->getParameter(i);
938  } else {
939  i -= ncol;
940  return _kernelRowFunctionPtr->getParameter(i);
941  }
942  }
943  std::vector<double> getKernelParameters() const override;
944 
949 
954 
955  std::string toString(std::string const &prefix = "") const override;
956 
957  /***
958  * Compute a cache of values for the x and y kernel functions
959  *
960  * A value of 0 disables the cache for maximum accuracy.
961  * 10,000 typically results in a warping error of a fraction of a count.
962  * 100,000 typically results in a warping error of less than 0.01 count.
963  *
964  * @param cacheSize cache size (number of double precision array elements in the x and y caches)
965  */
966  void computeCache(int const cacheSize) override;
967 
971  int getCacheSize() const override;
972 
973 protected:
974  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const override;
975 
976  void setKernelParameter(unsigned int ind, double value) const override;
977 
978 private:
992  double basicComputeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList,
993  bool doNormalize) const;
994 
995  KernelFunctionPtr _kernelColFunctionPtr;
996  KernelFunctionPtr _kernelRowFunctionPtr;
997  mutable std::vector<Pixel> _localColList; // used by doComputeImage
998  mutable std::vector<Pixel> _localRowList;
999  mutable std::vector<double> _kernelX; // used by SeparableKernel::basicComputeVectors
1000  mutable std::vector<double> _kernelY;
1001  //
1002  // Cached values of the row- and column- kernels
1003  //
1004  mutable std::vector<std::vector<double>> _kernelRowCache;
1005  mutable std::vector<std::vector<double>> _kernelColCache;
1006 
1007  virtual void _setKernelXY() override {
1008  lsst::geom::Extent2I const dim = getDimensions();
1009  lsst::geom::Point2I const ctr = getCtr();
1010 
1011  assert(dim[0] == static_cast<int>(_kernelX.size()));
1012  for (int i = 0; i != dim.getX(); ++i) {
1013  _kernelX[i] = i - ctr.getX();
1014  }
1015 
1016  assert(dim[1] == static_cast<int>(_kernelY.size()));
1017  for (int i = 0; i != dim.getY(); ++i) {
1018  _kernelY[i] = i - ctr.getY();
1019  }
1020  }
1021 };
1022 } // namespace math
1023 } // namespace afw
1024 } // namespace lsst
1025 
1026 #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:79
int y
Definition: SpanSet.cc:49
A kernel described by a function.
Definition: Kernel.h:536
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:620
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:634
AnalyticKernel & operator=(AnalyticKernel &&)=delete
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
Definition: Kernel.h:539
AnalyticKernel()
Construct an empty spatially invariant AnalyticKernel of size 0x0.
~AnalyticKernel() override=default
lsst::afw::math::Function2< Pixel > KernelFunction
Definition: Kernel.h:538
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:644
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:671
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:675
deltafunction_kernel_tag kernel_fill_factor
Definition: Kernel.h:647
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:472
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:179
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
Definition: FixedKernel.cc:61
FixedKernel()
Construct an empty FixedKernel of size 0x0.
Definition: FixedKernel.cc:42
FixedKernel & operator=(FixedKernel &&)=delete
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
Definition: FixedKernel.cc:104
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
Definition: FixedKernel.cc:67
~FixedKernel() override=default
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:507
virtual Pixel getSum() const
Definition: Kernel.h:505
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
Definition: FixedKernel.cc:127
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: FixedKernel.cc:181
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:111
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
Definition: Kernel.h:213
virtual void _setKernelXY()
Definition: Kernel.h:460
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:450
Kernel & operator=(const Kernel &)=delete
lsst::afw::math::Function2< double > SpatialFunction
Definition: Kernel.h:115
Kernel(const Kernel &)=delete
virtual void computeCache(int const)
Compute a cache of Kernel values, if desired.
Definition: Kernel.h:398
int getHeight() const
Return the Kernel's height.
Definition: Kernel.h:230
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
Definition: Kernel.h:235
void setKernelParameters(std::vector< double > const &params)
Set the kernel parameters of a spatially invariant kernel.
Definition: Kernel.h:342
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
Definition: Kernel.h:247
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
Definition: Kernel.h:278
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:252
void setWidth(int width)
Definition: Kernel.h:219
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
Definition: Kernel.cc:166
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
Definition: Kernel.cc:175
~Kernel() override=default
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:114
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:195
lsst::afw::math::NullFunction2< double > NullSpatialFunction
Definition: Kernel.h:116
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
Definition: Kernel.cc:144
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model)
Definition: Kernel.cc:153
generic_kernel_tag kernel_fill_factor
Definition: Kernel.h:119
void setCtr(lsst::geom::Point2I ctr)
Set index of kernel's center.
Definition: Kernel.h:313
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
Definition: Kernel.h:404
void setKernelParameters(std::pair< double, double > const &params)
Set the kernel parameters of a 2-component spatially invariant kernel.
Definition: Kernel.h:364
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:183
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:322
int getWidth() const
Return the Kernel's width.
Definition: Kernel.h:225
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:334
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:177
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Definition: Kernel.cc:224
void setHeight(int height)
Definition: Kernel.h:220
void setDimensions(lsst::geom::Extent2I dims)
Definition: Kernel.h:215
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:235
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:85
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:119
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:58
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
Definition: Kernel.cc:228
Kernel(Kernel &&)=delete
lsst::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:240
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:705
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:821
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:769
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:781
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:861
~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.
double getKernelParameter(unsigned int i) const override
Return a particular Kernel Parameter (no bounds checking).
Definition: Kernel.h:934
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)
lsst::afw::math::Function1< Pixel > KernelFunction
Definition: Kernel.h:863
std::shared_ptr< KernelFunction > KernelFunctionPtr
Definition: Kernel.h:864
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:1007
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.
std::vector< std::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:463
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)
afw::table::Key< int > cacheSize
Definition: CoaddPsf.cc:339
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