lsst.afw  14.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "boost/serialization/shared_ptr.hpp"
38 #include "boost/serialization/vector.hpp"
39 #include "boost/serialization/export.hpp"
40 
41 #include "lsst/daf/base/Persistable.h"
42 #include "lsst/daf/base/Citizen.h"
43 #include "lsst/afw/geom.h"
44 #include "lsst/afw/image/Image.h"
45 #include "lsst/afw/image/Utils.h"
46 #include "lsst/afw/math/Function.h"
47 #include "lsst/afw/math/traits.h"
48 
50 
51 namespace lsst {
52 namespace afw {
53 
54 namespace formatters {
55 class KernelFormatter;
56 }
57 
58 namespace math {
59 
60 using boost::serialization::make_nvp;
61 
123 class Kernel : public lsst::daf::base::Citizen,
124  public lsst::daf::base::Persistable,
125  public afw::table::io::PersistableFacade<Kernel>,
127 public:
128  typedef double Pixel;
129  typedef std::shared_ptr<lsst::afw::math::Function2<double>> SpatialFunctionPtr;
132 
133  // Traits values for this class of Kernel
135 
141  explicit Kernel();
142 
156  explicit Kernel(int width, int height, unsigned int nKernelParams,
157  SpatialFunction const &spatialFunction = NullSpatialFunction());
158 
170  explicit Kernel(int width, int height, const std::vector<SpatialFunctionPtr> spatialFunctionList);
171 
172  virtual ~Kernel() {}
173 
185  virtual std::shared_ptr<Kernel> clone() const = 0;
186 
197  virtual std::shared_ptr<Kernel> resized(int width, int height) const = 0;
198 
216  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
217  double y = 0.0) const;
218 
222  geom::Extent2I const getDimensions() const { return geom::Extent2I(_width, _height); }
223 
225  _width = dims.getX();
226  _height = dims.getY();
227  }
228  inline void setWidth(int width) { _width = width; }
229  inline void setHeight(int height) { _height = height; }
230 
234  inline int getWidth() const { return _width; }
235 
239  inline int getHeight() const { return _height; }
240 
244  inline lsst::afw::geom::Point2I getCtr() const { return lsst::afw::geom::Point2I(_ctrX, _ctrY); }
245 
251  inline int getCtrX() const { return _ctrX; }
252 
258  inline int getCtrY() const { return _ctrY; }
259 
264  return lsst::afw::geom::Box2I(lsst::afw::geom::Point2I(-_ctrX, -_ctrY),
265  lsst::afw::geom::Extent2I(_width, _height));
266  }
267 
271  inline unsigned int getNKernelParameters() const { return _nKernelParams; }
272 
276  inline int getNSpatialParameters() const {
277  return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
278  }
279 
290  SpatialFunctionPtr getSpatialFunction(unsigned int index) const;
291 
298  std::vector<SpatialFunctionPtr> getSpatialFunctionList() const;
299 
302  virtual double getKernelParameter(unsigned int i) const { return getKernelParameters()[i]; }
303 
311  virtual std::vector<double> getKernelParameters() const;
312 
321 
333 
337  inline void setCtr(lsst::afw::geom::Point2I ctr) {
338  _ctrX = ctr.getX();
339  _ctrY = ctr.getY();
340  _setKernelXY();
341  }
342 
348  inline void setCtrX(int ctrX) {
349  _ctrX = ctrX;
350  _setKernelXY();
351  }
352 
358  inline void setCtrY(int ctrY) {
359  _ctrY = ctrY;
360  _setKernelXY();
361  }
362 
366  inline std::vector<std::vector<double>> getSpatialParameters() const {
367  std::vector<std::vector<double>> spatialParams;
368  std::vector<SpatialFunctionPtr>::const_iterator spFuncIter = _spatialFunctionList.begin();
369  for (; spFuncIter != _spatialFunctionList.end(); ++spFuncIter) {
370  spatialParams.push_back((*spFuncIter)->getParameters());
371  }
372  return spatialParams;
373  }
374 
378  inline bool isSpatiallyVarying() const { return _spatialFunctionList.size() != 0; }
379 
386  inline void setKernelParameters(std::vector<double> const &params) {
387  if (this->isSpatiallyVarying()) {
388  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Kernel is spatially varying");
389  }
390  const unsigned int nParams = this->getNKernelParameters();
391  if (nParams != params.size()) {
392  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
393  (boost::format("Number of parameters is wrong, saw %d expected %d") % nParams %
394  params.size())
395  .str());
396  }
397  for (unsigned int ii = 0; ii < nParams; ++ii) {
398  this->setKernelParameter(ii, params[ii]);
399  }
400  }
401 
408  inline void setKernelParameters(std::pair<double, double> const &params) {
409  this->setKernelParameter(0, params.first);
410  this->setKernelParameter(1, params.second);
411  }
412 
421  void setSpatialParameters(const std::vector<std::vector<double>> params);
422 
429  void computeKernelParametersFromSpatialModel(std::vector<double> &kernelParams, double x, double y) const;
430 
434  virtual std::string toString(std::string const &prefix = "") const;
435 
442  virtual void computeCache(int const
443  ) {}
444 
448  virtual int getCacheSize() const { return 0; };
449 
450 #if 0 // fails to compile with icc; is it actually used?
451  virtual void toFile(std::string fileName) const;
452 #endif
453 
454  struct PersistenceHelper;
455 
456 protected:
457  virtual std::string getPythonModule() const;
458 
469  virtual void setKernelParameter(unsigned int ind, double value) const;
470 
479  void setKernelParametersFromSpatialModel(double x, double y) const;
480 
492  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const = 0;
493 
494  std::vector<SpatialFunctionPtr> _spatialFunctionList;
495 
496 private:
497  LSST_PERSIST_FORMATTER(lsst::afw::formatters::KernelFormatter)
498 
499  int _width;
500  int _height;
501  int _ctrX;
502  int _ctrY;
503  unsigned int _nKernelParams;
504 
505  // prevent copying and assignment (to avoid problems from type slicing)
506  Kernel(const Kernel &);
507  Kernel &operator=(const Kernel &);
508  // Set the Kernel's ideas about the x- and y- coordinates
509  virtual void _setKernelXY() {}
510 };
511 
512 typedef std::vector<std::shared_ptr<Kernel>> KernelList;
513 
521 class FixedKernel : public afw::table::io::PersistableFacade<FixedKernel>, public Kernel {
522 public:
526  explicit FixedKernel();
527 
532  );
533 
537  explicit FixedKernel(lsst::afw::math::Kernel const &kernel,
538  lsst::afw::geom::Point2D const &pos
539  );
540 
541  virtual ~FixedKernel() {}
542 
543  virtual std::shared_ptr<Kernel> clone() const;
544 
545  virtual std::shared_ptr<Kernel> resized(int width, int height) const;
546 
547  virtual std::string toString(std::string const &prefix = "") const;
548 
549  virtual Pixel getSum() const { return _sum; }
550 
551  virtual bool isPersistable() const { return true; }
552 
553  class Factory;
554 
555 protected:
556  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
557 
558  virtual std::string getPersistenceName() const;
559 
560  virtual void write(OutputArchiveHandle &handle) const;
561 
562 private:
564  Pixel _sum;
565 
567  template <class Archive>
568  void serialize(Archive &ar, unsigned int const version) {
569  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
570  ar &make_nvp("img", _image);
571  ar &make_nvp("sum", _sum);
572  }
573 };
574 
588 class AnalyticKernel : public afw::table::io::PersistableFacade<AnalyticKernel>, public Kernel {
589 public:
591  typedef std::shared_ptr<lsst::afw::math::Function2<Pixel>> KernelFunctionPtr;
592 
596  explicit AnalyticKernel();
597 
610  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
611  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
612 
626  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
627  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
628 
629  virtual ~AnalyticKernel() {}
630 
631  virtual std::shared_ptr<Kernel> clone() const;
632 
633  virtual std::shared_ptr<Kernel> resized(int width, int height) const;
634 
655  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
656  double y = 0.0) const;
657 
658  virtual std::vector<double> getKernelParameters() const;
659 
663  virtual KernelFunctionPtr getKernelFunction() const;
664 
665  virtual std::string toString(std::string const &prefix = "") const;
666 
667  virtual bool isPersistable() const { return true; }
668 
669  class Factory;
670 
671 protected:
672  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
673 
674  virtual std::string getPersistenceName() const;
675 
676  virtual void write(OutputArchiveHandle &handle) const;
677 
678 protected:
679  virtual void setKernelParameter(unsigned int ind, double value) const;
680 
682 
684  template <class Archive>
685  void serialize(Archive &ar, unsigned int const version) {
686  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
687  ar &make_nvp("fn", _kernelFunctionPtr);
688  }
689 };
690 
698 class DeltaFunctionKernel : public afw::table::io::PersistableFacade<DeltaFunctionKernel>, public Kernel {
699 public:
700  // Traits values for this class of Kernel
702 
712  explicit DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point);
713 
714  virtual ~DeltaFunctionKernel() {}
715 
716  virtual std::shared_ptr<Kernel> clone() const;
717 
718  virtual std::shared_ptr<Kernel> resized(int width, int height) const;
719 
720  lsst::afw::geom::Point2I getPixel() const { return _pixel; }
721 
722  virtual std::string toString(std::string const &prefix = "") const;
723 
724  virtual bool isPersistable() const { return true; }
725 
726  class Factory;
727 
728 protected:
729  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
730 
731  virtual std::string getPersistenceName() const;
732 
733  virtual void write(OutputArchiveHandle &handle) const;
734 
735 private:
737 
739  template <class Archive>
740  void serialize(Archive &ar, unsigned int const version) {
741  boost::serialization::void_cast_register<DeltaFunctionKernel, Kernel>(
742  static_cast<DeltaFunctionKernel *>(0), static_cast<Kernel *>(0));
743  }
744 };
745 
760 class LinearCombinationKernel : public afw::table::io::PersistableFacade<LinearCombinationKernel>,
761  public Kernel {
762 public:
766  explicit LinearCombinationKernel();
767 
774  explicit LinearCombinationKernel(KernelList const &kernelList,
775  std::vector<double> const &kernelParameters);
776 
784  explicit LinearCombinationKernel(KernelList const &kernelList,
785  Kernel::SpatialFunction const &spatialFunction);
786 
796  explicit LinearCombinationKernel(KernelList const &kernelList,
797  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
798 
800 
801  virtual std::shared_ptr<Kernel> clone() const;
802 
803  virtual std::shared_ptr<Kernel> resized(int width, int height) const;
804 
805  virtual std::vector<double> getKernelParameters() const;
806 
810  virtual KernelList const &getKernelList() const;
811 
815  std::vector<double> getKernelSumList() const;
816 
820  int getNBasisKernels() const { return static_cast<int>(_kernelList.size()); };
821 
827  void checkKernelList(const KernelList &kernelList) const;
828 
832  bool isDeltaFunctionBasis() const { return _isDeltaFunctionBasis; };
833 
868  std::shared_ptr<Kernel> refactor() const;
869 
870  virtual std::string toString(std::string const &prefix = "") const;
871 
872  virtual bool isPersistable() const { return true; }
873 
874  class Factory;
875 
876 protected:
877  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
878 
879  virtual std::string getPersistenceName() const;
880 
881  virtual void write(OutputArchiveHandle &handle) const;
882 
883  virtual void setKernelParameter(unsigned int ind, double value) const;
884 
885 private:
889  void _setKernelList(KernelList const &kernelList);
890 
891  KernelList _kernelList;
892  std::vector<std::shared_ptr<lsst::afw::image::Image<Pixel>>> _kernelImagePtrList;
894  std::vector<double> _kernelSumList;
895  mutable std::vector<double> _kernelParams;
896  bool _isDeltaFunctionBasis;
897 
899  template <class Archive>
900  void serialize(Archive &ar, unsigned int const version) {
901  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
902  ar &make_nvp("klist", _kernelList);
903  ar &make_nvp("kimglist", _kernelImagePtrList);
904  ar &make_nvp("ksumlist", _kernelSumList);
905  ar &make_nvp("params", _kernelParams);
906  if (version > 0) {
907  ar &make_nvp("deltaBasis", _isDeltaFunctionBasis);
908  } else if (Archive::is_loading::value) {
909  _isDeltaFunctionBasis = false;
910  }
911  }
912 };
913 
927 class SeparableKernel : public afw::table::io::PersistableFacade<SeparableKernel>, public Kernel {
928 public:
930  typedef std::shared_ptr<KernelFunction> KernelFunctionPtr;
931 
935  explicit SeparableKernel();
936 
949  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
950  KernelFunction const &kernelRowFunction,
951  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
952 
966  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
967  KernelFunction const &kernelRowFunction,
968  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
969  virtual ~SeparableKernel() {}
970 
971  virtual std::shared_ptr<Kernel> clone() const;
972 
973  virtual std::shared_ptr<Kernel> resized(int width, int height) const;
974 
991  double computeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList, bool doNormalize,
992  double x = 0.0, double y = 0.0) const;
993 
994  virtual double getKernelParameter(unsigned int i) const {
995  unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
996  if (i < ncol) {
997  return _kernelColFunctionPtr->getParameter(i);
998  } else {
999  i -= ncol;
1000  return _kernelRowFunctionPtr->getParameter(i);
1001  }
1002  }
1003  virtual std::vector<double> getKernelParameters() const;
1004 
1009 
1014 
1015  virtual std::string toString(std::string const &prefix = "") const;
1016 
1017  /***
1018  * Compute a cache of values for the x and y kernel functions
1019  *
1020  * A value of 0 disables the cache for maximum accuracy.
1021  * 10,000 typically results in a warping error of a fraction of a count.
1022  * 100,000 typically results in a warping error of less than 0.01 count.
1023  *
1024  * @param cacheSize cache size (number of double precision array elements in the x and y caches)
1025  */
1026  virtual void computeCache(int const cacheSize);
1027 
1031  virtual int getCacheSize() const;
1032 
1033 protected:
1034  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
1035 
1036  virtual void setKernelParameter(unsigned int ind, double value) const;
1037 
1038 private:
1052  double basicComputeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList,
1053  bool doNormalize) const;
1054 
1055  KernelFunctionPtr _kernelColFunctionPtr;
1056  KernelFunctionPtr _kernelRowFunctionPtr;
1057  mutable std::vector<Pixel> _localColList; // used by doComputeImage
1058  mutable std::vector<Pixel> _localRowList;
1059  mutable std::vector<double> _kernelX; // used by SeparableKernel::basicComputeVectors
1060  mutable std::vector<double> _kernelY;
1061  //
1062  // Cached values of the row- and column- kernels
1063  //
1064  mutable std::vector<std::vector<double>> _kernelRowCache;
1065  mutable std::vector<std::vector<double>> _kernelColCache;
1066 
1068  template <class Archive>
1069  void serialize(Archive &ar, unsigned int const version) {
1070  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
1071  ar &make_nvp("colfn", _kernelColFunctionPtr);
1072  ar &make_nvp("rowfn", _kernelRowFunctionPtr);
1073  ar &make_nvp("cols", _localColList);
1074  ar &make_nvp("rows", _localRowList);
1075  ar &make_nvp("kernelX", _kernelX);
1076  ar &make_nvp("kernelY", _kernelY);
1077  }
1078 
1079  virtual void _setKernelXY() {
1081  lsst::afw::geom::Point2I const ctr = getCtr();
1082 
1083  assert(dim[0] == static_cast<int>(_kernelX.size()));
1084  for (int i = 0; i != dim.getX(); ++i) {
1085  _kernelX[i] = i - ctr.getX();
1086  }
1087 
1088  assert(dim[1] == static_cast<int>(_kernelY.size()));
1089  for (int i = 0; i != dim.getY(); ++i) {
1090  _kernelY[i] = i - ctr.getY();
1091  }
1092  }
1093 };
1094 }
1095 }
1096 } // lsst:afw::math
1097 
1098 namespace boost {
1099 namespace serialization {
1100 
1101 template <class Archive>
1103  unsigned int const file_version) {
1104  int width = k->getWidth();
1105  int height = k->getHeight();
1106  int x = k->getPixel().getX();
1107  int y = k->getPixel().getY();
1108  ar << make_nvp("width", width);
1109  ar << make_nvp("height", height);
1110  ar << make_nvp("pixX", x);
1111  ar << make_nvp("pixY", y);
1112 }
1113 
1114 template <class Archive>
1116  unsigned int const file_version) {
1117  int width;
1118  int height;
1119  int x;
1120  int y;
1121  ar >> make_nvp("width", width);
1122  ar >> make_nvp("height", height);
1123  ar >> make_nvp("pixX", x);
1124  ar >> make_nvp("pixY", y);
1125  ::new (k) lsst::afw::math::DeltaFunctionKernel(width, height, lsst::afw::geom::Point2I(x, y));
1126 }
1127 }
1128 }
1129 
1130 BOOST_CLASS_VERSION(lsst::afw::math::LinearCombinationKernel, 1)
1131 
1132 #endif // !defined(LSST_AFW_MATH_KERNEL_H)
std::vector< double > getKernelSumList() const
Get the sum of the pixels of each fixed basis kernel.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
Definition: FixedKernel.cc:62
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
Definition: Kernel.h:994
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
friend class boost::serialization::access
Definition: Kernel.h:738
std::shared_ptr< KernelFunction > KernelFunctionPtr
Definition: Kernel.h:930
virtual int getCacheSize() const
Get the current cache size (0 if none)
geom::Extent2I const getDimensions() const
Return the Kernel&#39;s dimensions (width, height)
Definition: Kernel.h:222
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) ...
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:667
void setDimensions(geom::Extent2I dims)
Definition: Kernel.h:224
void setWidth(int width)
Definition: Kernel.h:228
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: Kernel.cc:237
int getCtrY() const
Return y index of kernel&#39;s center.
Definition: Kernel.h:258
lsst::afw::math::Function1< Pixel > KernelFunction
Definition: Kernel.h:929
void setKernelParameters(std::vector< double > const &params)
Set the kernel parameters of a spatially invariant kernel.
Definition: Kernel.h:386
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:263
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:197
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:927
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
Definition: Kernel.h:276
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:685
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:129
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: FixedKernel.cc:175
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying) ...
Definition: Kernel.h:366
void setHeight(int height)
Definition: Kernel.h:229
lsst::afw::math::NullFunction2< double > NullSpatialFunction
Definition: Kernel.h:131
Extent< int, 2 > Extent2I
Definition: Extent.h:341
int getCtrX() const
Return x index of kernel&#39;s center.
Definition: Kernel.h:251
friend class boost::serialization::access
Definition: Kernel.h:566
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Definition: Kernel.cc:226
lsst::afw::math::Function2< double > SpatialFunction
Definition: Kernel.h:130
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: FixedKernel.cc:123
A Function taking two arguments.
Definition: Function.h:266
LinearCombinationKernel()
Construct an empty LinearCombinationKernel of size 0x0.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:724
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
bool isDeltaFunctionBasis() const
Return true if all basis kernels are instances of DeltaFunctionKernel.
Definition: Kernel.h:832
An integer coordinate rectangle.
Definition: Box.h:55
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:239
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:73
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:234
a class used in function calls to indicate that no Function2 is being provided
Definition: Function.h:476
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
version
Definition: conf.py:12
void setCtrY(int ctrY)
Set y index of kernel&#39;s center.
Definition: Kernel.h:358
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
Definition: Kernel.h:302
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
Definition: Kernel.cc:179
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
KernelFunctionPtr _kernelFunctionPtr
Definition: Kernel.h:681
friend class boost::serialization::access
Definition: Kernel.h:683
int getNBasisKernels() const
Get the number of basis kernels.
Definition: Kernel.h:820
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
Definition: Kernel.cc:230
FixedKernel()
Construct an empty FixedKernel of size 0x0.
Definition: FixedKernel.cc:37
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
Definition: Kernel.h:271
void setCtrX(int ctrX)
Set x index of kernel&#39;s center.
Definition: Kernel.h:348
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.
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:88
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:760
void setKernelParameters(std::pair< double, double > const &params)
Set the kernel parameters of a 2-component spatially invariant kernel.
Definition: Kernel.h:408
void load_construct_data(Archive &ar, lsst::afw::math::DeltaFunctionKernel *k, unsigned int const file_version)
Definition: Kernel.h:1115
lsst::afw::geom::Box2I growBBox(lsst::afw::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:181
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
virtual std::shared_ptr< Kernel > resized(int width, int height) const =0
Return a pointer to a clone with specified kernel dimensions.
A Function taking one argument.
Definition: Function.h:207
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model) ...
Definition: Kernel.cc:157
SeparableKernel()
Construct an empty spatially invariant SeparableKernel of size 0x0.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:872
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
Definition: Kernel.h:448
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
generic_kernel_tag kernel_fill_factor
Definition: Kernel.h:134
double x
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel&#39;s center.
Definition: Kernel.h:337
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:244
friend class boost::serialization::access
Definition: Kernel.h:898
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Formatter for persistence of Kernel instances.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual KernelList const & getKernelList() const
Get the fixed basis kernels.
void setSpatialParameters(const std::vector< std::vector< double >> params)
Set the parameters of all spatial functions.
Definition: Kernel.cc:123
virtual void computeCache(int const cacheSize)
Compute a cache of Kernel values, if desired.
Kernel has only one non-zero pixel.
Definition: traits.h:56
lsst::afw::geom::Point2I getPixel() const
Definition: Kernel.h:720
table::Key< int > kernelFunction
std::vector< std::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:512
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
AnalyticKernel()
Construct an empty spatially invariant AnalyticKernel of size 0x0.
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:494
lsst::afw::math::Function2< Pixel > KernelFunction
Definition: Kernel.h:590
afw::table::Key< afw::table::Array< ImagePixelT > > image
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:53
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:107
virtual Pixel getSum() const
Definition: Kernel.h:549
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: FixedKernel.cc:177
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
Definition: Kernel.cc:148
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
lsst::afw::geom::Box2I shrinkBBox(lsst::afw::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:186
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Definition: FixedKernel.cc:56
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
Definition: FixedKernel.cc:100
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Point< int, 2 > Point2I
Definition: Point.h:270
deltafunction_kernel_tag kernel_fill_factor
Definition: Kernel.h:701
A kernel described by a function.
Definition: Kernel.h:588
std::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
Definition: Kernel.h:591
friend class boost::serialization::access
Definition: Kernel.h:1067
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:173
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:123
void save_construct_data(Archive &ar, lsst::afw::math::DeltaFunctionKernel const *k, unsigned int const file_version)
Definition: Kernel.h:1102
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
Definition: Kernel.cc:170
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...
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:698
virtual std::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
virtual void computeCache(int const )
Compute a cache of Kernel values, if desired.
Definition: Kernel.h:442
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Tags carrying information about Kernels Kernel with no special properties.
Definition: traits.h:53
A kernel created from an Image.
Definition: Kernel.h:521
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:551
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:378