lsst.afw  13.0-73-gb2a4e38
 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 
204  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
205  double y = 0.0) const;
206 
210  geom::Extent2I const getDimensions() const { return geom::Extent2I(_width, _height); }
211 
213  _width = dims.getX();
214  _height = dims.getY();
215  }
216  inline void setWidth(int width) { _width = width; }
217  inline void setHeight(int height) { _height = height; }
218 
222  inline int getWidth() const { return _width; }
223 
227  inline int getHeight() const { return _height; }
228 
232  inline lsst::afw::geom::Point2I getCtr() const { return lsst::afw::geom::Point2I(_ctrX, _ctrY); }
233 
239  inline int getCtrX() const { return _ctrX; }
240 
246  inline int getCtrY() const { return _ctrY; }
247 
252  return lsst::afw::geom::Box2I(lsst::afw::geom::Point2I(-_ctrX, -_ctrY),
253  lsst::afw::geom::Extent2I(_width, _height));
254  }
255 
259  inline unsigned int getNKernelParameters() const { return _nKernelParams; }
260 
264  inline int getNSpatialParameters() const {
265  return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
266  }
267 
278  SpatialFunctionPtr getSpatialFunction(unsigned int index) const;
279 
286  std::vector<SpatialFunctionPtr> getSpatialFunctionList() const;
287 
290  virtual double getKernelParameter(unsigned int i) const { return getKernelParameters()[i]; }
291 
299  virtual std::vector<double> getKernelParameters() const;
300 
309 
321 
325  inline void setCtr(lsst::afw::geom::Point2I ctr) {
326  _ctrX = ctr.getX();
327  _ctrY = ctr.getY();
328  _setKernelXY();
329  }
330 
336  inline void setCtrX(int ctrX) {
337  _ctrX = ctrX;
338  _setKernelXY();
339  }
340 
346  inline void setCtrY(int ctrY) {
347  _ctrY = ctrY;
348  _setKernelXY();
349  }
350 
354  inline std::vector<std::vector<double>> getSpatialParameters() const {
355  std::vector<std::vector<double>> spatialParams;
356  std::vector<SpatialFunctionPtr>::const_iterator spFuncIter = _spatialFunctionList.begin();
357  for (; spFuncIter != _spatialFunctionList.end(); ++spFuncIter) {
358  spatialParams.push_back((*spFuncIter)->getParameters());
359  }
360  return spatialParams;
361  }
362 
366  inline bool isSpatiallyVarying() const { return _spatialFunctionList.size() != 0; }
367 
374  inline void setKernelParameters(std::vector<double> const &params) {
375  if (this->isSpatiallyVarying()) {
376  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "Kernel is spatially varying");
377  }
378  const unsigned int nParams = this->getNKernelParameters();
379  if (nParams != params.size()) {
380  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
381  (boost::format("Number of parameters is wrong, saw %d expected %d") % nParams %
382  params.size())
383  .str());
384  }
385  for (unsigned int ii = 0; ii < nParams; ++ii) {
386  this->setKernelParameter(ii, params[ii]);
387  }
388  }
389 
396  inline void setKernelParameters(std::pair<double, double> const &params) {
397  this->setKernelParameter(0, params.first);
398  this->setKernelParameter(1, params.second);
399  }
400 
409  void setSpatialParameters(const std::vector<std::vector<double>> params);
410 
417  void computeKernelParametersFromSpatialModel(std::vector<double> &kernelParams, double x, double y) const;
418 
422  virtual std::string toString(std::string const &prefix = "") const;
423 
430  virtual void computeCache(int const
431  ) {}
432 
436  virtual int getCacheSize() const { return 0; };
437 
438 #if 0 // fails to compile with icc; is it actually used?
439  virtual void toFile(std::string fileName) const;
440 #endif
441 
442  struct PersistenceHelper;
443 
444 protected:
445  virtual std::string getPythonModule() const;
446 
457  virtual void setKernelParameter(unsigned int ind, double value) const;
458 
467  void setKernelParametersFromSpatialModel(double x, double y) const;
468 
480  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const = 0;
481 
482  std::vector<SpatialFunctionPtr> _spatialFunctionList;
483 
484 private:
485  LSST_PERSIST_FORMATTER(lsst::afw::formatters::KernelFormatter)
486 
487  int _width;
488  int _height;
489  int _ctrX;
490  int _ctrY;
491  unsigned int _nKernelParams;
492 
493  // prevent copying and assignment (to avoid problems from type slicing)
494  Kernel(const Kernel &);
495  Kernel &operator=(const Kernel &);
496  // Set the Kernel's ideas about the x- and y- coordinates
497  virtual void _setKernelXY() {}
498 };
499 
500 typedef std::vector<std::shared_ptr<Kernel>> KernelList;
501 
509 class FixedKernel : public afw::table::io::PersistableFacade<FixedKernel>, public Kernel {
510 public:
514  explicit FixedKernel();
515 
520  );
521 
525  explicit FixedKernel(lsst::afw::math::Kernel const &kernel,
526  lsst::afw::geom::Point2D const &pos
527  );
528 
529  virtual ~FixedKernel() {}
530 
531  virtual std::shared_ptr<Kernel> clone() const;
532 
533  virtual std::string toString(std::string const &prefix = "") const;
534 
535  virtual Pixel getSum() const { return _sum; }
536 
537  virtual bool isPersistable() const { return true; }
538 
539  class Factory;
540 
541 protected:
542  double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
543 
544  virtual std::string getPersistenceName() const;
545 
546  virtual void write(OutputArchiveHandle &handle) const;
547 
548 private:
550  Pixel _sum;
551 
553  template <class Archive>
554  void serialize(Archive &ar, unsigned int const version) {
555  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
556  ar &make_nvp("img", _image);
557  ar &make_nvp("sum", _sum);
558  }
559 };
560 
574 class AnalyticKernel : public afw::table::io::PersistableFacade<AnalyticKernel>, public Kernel {
575 public:
577  typedef std::shared_ptr<lsst::afw::math::Function2<Pixel>> KernelFunctionPtr;
578 
582  explicit AnalyticKernel();
583 
596  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
597  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
598 
612  explicit AnalyticKernel(int width, int height, KernelFunction const &kernelFunction,
613  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
614 
615  virtual ~AnalyticKernel() {}
616 
617  virtual std::shared_ptr<Kernel> clone() const;
618 
639  double computeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize, double x = 0.0,
640  double y = 0.0) const;
641 
642  virtual std::vector<double> getKernelParameters() const;
643 
647  virtual KernelFunctionPtr getKernelFunction() const;
648 
649  virtual std::string toString(std::string const &prefix = "") const;
650 
651  virtual bool isPersistable() const { return true; }
652 
653  class Factory;
654 
655 protected:
656  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
657 
658  virtual std::string getPersistenceName() const;
659 
660  virtual void write(OutputArchiveHandle &handle) const;
661 
662 protected:
663  virtual void setKernelParameter(unsigned int ind, double value) const;
664 
666 
668  template <class Archive>
669  void serialize(Archive &ar, unsigned int const version) {
670  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
671  ar &make_nvp("fn", _kernelFunctionPtr);
672  }
673 };
674 
682 class DeltaFunctionKernel : public afw::table::io::PersistableFacade<DeltaFunctionKernel>, public Kernel {
683 public:
684  // Traits values for this class of Kernel
686 
696  explicit DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point);
697 
698  virtual ~DeltaFunctionKernel() {}
699 
700  virtual std::shared_ptr<Kernel> clone() const;
701 
702  lsst::afw::geom::Point2I getPixel() const { return _pixel; }
703 
704  virtual std::string toString(std::string const &prefix = "") const;
705 
706  virtual bool isPersistable() const { return true; }
707 
708  class Factory;
709 
710 protected:
711  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
712 
713  virtual std::string getPersistenceName() const;
714 
715  virtual void write(OutputArchiveHandle &handle) const;
716 
717 private:
719 
721  template <class Archive>
722  void serialize(Archive &ar, unsigned int const version) {
723  boost::serialization::void_cast_register<DeltaFunctionKernel, Kernel>(
724  static_cast<DeltaFunctionKernel *>(0), static_cast<Kernel *>(0));
725  }
726 };
727 
742 class LinearCombinationKernel : public afw::table::io::PersistableFacade<LinearCombinationKernel>,
743  public Kernel {
744 public:
748  explicit LinearCombinationKernel();
749 
756  explicit LinearCombinationKernel(KernelList const &kernelList,
757  std::vector<double> const &kernelParameters);
758 
766  explicit LinearCombinationKernel(KernelList const &kernelList,
767  Kernel::SpatialFunction const &spatialFunction);
768 
778  explicit LinearCombinationKernel(KernelList const &kernelList,
779  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
780 
782 
783  virtual std::shared_ptr<Kernel> clone() const;
784 
785  virtual std::vector<double> getKernelParameters() const;
786 
790  virtual KernelList const &getKernelList() const;
791 
795  std::vector<double> getKernelSumList() const;
796 
800  int getNBasisKernels() const { return static_cast<int>(_kernelList.size()); };
801 
807  void checkKernelList(const KernelList &kernelList) const;
808 
812  bool isDeltaFunctionBasis() const { return _isDeltaFunctionBasis; };
813 
848  std::shared_ptr<Kernel> refactor() const;
849 
850  virtual std::string toString(std::string const &prefix = "") const;
851 
852  virtual bool isPersistable() const { return true; }
853 
854  class Factory;
855 
856 protected:
857  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
858 
859  virtual std::string getPersistenceName() const;
860 
861  virtual void write(OutputArchiveHandle &handle) const;
862 
863  virtual void setKernelParameter(unsigned int ind, double value) const;
864 
865 private:
869  void _setKernelList(KernelList const &kernelList);
870 
871  KernelList _kernelList;
872  std::vector<std::shared_ptr<lsst::afw::image::Image<Pixel>>> _kernelImagePtrList;
874  std::vector<double> _kernelSumList;
875  mutable std::vector<double> _kernelParams;
876  bool _isDeltaFunctionBasis;
877 
879  template <class Archive>
880  void serialize(Archive &ar, unsigned int const version) {
881  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
882  ar &make_nvp("klist", _kernelList);
883  ar &make_nvp("kimglist", _kernelImagePtrList);
884  ar &make_nvp("ksumlist", _kernelSumList);
885  ar &make_nvp("params", _kernelParams);
886  if (version > 0) {
887  ar &make_nvp("deltaBasis", _isDeltaFunctionBasis);
888  } else if (Archive::is_loading::value) {
889  _isDeltaFunctionBasis = false;
890  }
891  }
892 };
893 
907 class SeparableKernel : public afw::table::io::PersistableFacade<SeparableKernel>, public Kernel {
908 public:
910  typedef std::shared_ptr<KernelFunction> KernelFunctionPtr;
911 
915  explicit SeparableKernel();
916 
929  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
930  KernelFunction const &kernelRowFunction,
931  Kernel::SpatialFunction const &spatialFunction = NullSpatialFunction());
932 
946  explicit SeparableKernel(int width, int height, KernelFunction const &kernelColFunction,
947  KernelFunction const &kernelRowFunction,
948  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList);
949  virtual ~SeparableKernel() {}
950 
951  virtual std::shared_ptr<Kernel> clone() const;
952 
969  double computeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList, bool doNormalize,
970  double x = 0.0, double y = 0.0) const;
971 
972  virtual double getKernelParameter(unsigned int i) const {
973  unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
974  if (i < ncol) {
975  return _kernelColFunctionPtr->getParameter(i);
976  } else {
977  i -= ncol;
978  return _kernelRowFunctionPtr->getParameter(i);
979  }
980  }
981  virtual std::vector<double> getKernelParameters() const;
982 
987 
992 
993  virtual std::string toString(std::string const &prefix = "") const;
994 
995  /***
996  * Compute a cache of values for the x and y kernel functions
997  *
998  * A value of 0 disables the cache for maximum accuracy.
999  * 10,000 typically results in a warping error of a fraction of a count.
1000  * 100,000 typically results in a warping error of less than 0.01 count.
1001  *
1002  * @param cacheSize cache size (number of double precision array elements in the x and y caches)
1003  */
1004  virtual void computeCache(int const cacheSize);
1005 
1009  virtual int getCacheSize() const;
1010 
1011 protected:
1012  virtual double doComputeImage(lsst::afw::image::Image<Pixel> &image, bool doNormalize) const;
1013 
1014  virtual void setKernelParameter(unsigned int ind, double value) const;
1015 
1016 private:
1030  double basicComputeVectors(std::vector<Pixel> &colList, std::vector<Pixel> &rowList,
1031  bool doNormalize) const;
1032 
1033  KernelFunctionPtr _kernelColFunctionPtr;
1034  KernelFunctionPtr _kernelRowFunctionPtr;
1035  mutable std::vector<Pixel> _localColList; // used by doComputeImage
1036  mutable std::vector<Pixel> _localRowList;
1037  mutable std::vector<double> _kernelX; // used by SeparableKernel::basicComputeVectors
1038  mutable std::vector<double> _kernelY;
1039  //
1040  // Cached values of the row- and column- kernels
1041  //
1042  mutable std::vector<std::vector<double>> _kernelRowCache;
1043  mutable std::vector<std::vector<double>> _kernelColCache;
1044 
1046  template <class Archive>
1047  void serialize(Archive &ar, unsigned int const version) {
1048  ar &make_nvp("k", boost::serialization::base_object<Kernel>(*this));
1049  ar &make_nvp("colfn", _kernelColFunctionPtr);
1050  ar &make_nvp("rowfn", _kernelRowFunctionPtr);
1051  ar &make_nvp("cols", _localColList);
1052  ar &make_nvp("rows", _localRowList);
1053  ar &make_nvp("kernelX", _kernelX);
1054  ar &make_nvp("kernelY", _kernelY);
1055  }
1056 
1057  virtual void _setKernelXY() {
1059  lsst::afw::geom::Point2I const ctr = getCtr();
1060 
1061  assert(dim[0] == static_cast<int>(_kernelX.size()));
1062  for (int i = 0; i != dim.getX(); ++i) {
1063  _kernelX[i] = i - ctr.getX();
1064  }
1065 
1066  assert(dim[1] == static_cast<int>(_kernelY.size()));
1067  for (int i = 0; i != dim.getY(); ++i) {
1068  _kernelY[i] = i - ctr.getY();
1069  }
1070  }
1071 };
1072 }
1073 }
1074 } // lsst:afw::math
1075 
1076 namespace boost {
1077 namespace serialization {
1078 
1079 template <class Archive>
1081  unsigned int const file_version) {
1082  int width = k->getWidth();
1083  int height = k->getHeight();
1084  int x = k->getPixel().getX();
1085  int y = k->getPixel().getY();
1086  ar << make_nvp("width", width);
1087  ar << make_nvp("height", height);
1088  ar << make_nvp("pixX", x);
1089  ar << make_nvp("pixY", y);
1090 }
1091 
1092 template <class Archive>
1094  unsigned int const file_version) {
1095  int width;
1096  int height;
1097  int x;
1098  int y;
1099  ar >> make_nvp("width", width);
1100  ar >> make_nvp("height", height);
1101  ar >> make_nvp("pixX", x);
1102  ar >> make_nvp("pixY", y);
1103  ::new (k) lsst::afw::math::DeltaFunctionKernel(width, height, lsst::afw::geom::Point2I(x, y));
1104 }
1105 }
1106 }
1107 
1108 BOOST_CLASS_VERSION(lsst::afw::math::LinearCombinationKernel, 1)
1109 
1110 #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 > clone() const
Return a pointer to a deep copy of this kernel.
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
Definition: Kernel.h:972
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:720
std::shared_ptr< KernelFunction > KernelFunctionPtr
Definition: Kernel.h:910
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:210
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:651
void setDimensions(geom::Extent2I dims)
Definition: Kernel.h:212
void setWidth(int width)
Definition: Kernel.h:216
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:246
lsst::afw::math::Function1< Pixel > KernelFunction
Definition: Kernel.h:909
void setKernelParameters(std::vector< double > const &params)
Set the kernel parameters of a spatially invariant kernel.
Definition: Kernel.h:374
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:251
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:907
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
Definition: Kernel.h:264
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:669
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:137
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying) ...
Definition: Kernel.h:354
void setHeight(int height)
Definition: Kernel.h:217
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:239
friend class boost::serialization::access
Definition: Kernel.h:552
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:85
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:706
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:812
An integer coordinate rectangle.
Definition: Box.h:55
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:227
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:222
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:346
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:290
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
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:665
friend class boost::serialization::access
Definition: Kernel.h:667
int getNBasisKernels() const
Get the number of basis kernels.
Definition: Kernel.h:800
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:259
void setCtrX(int ctrX)
Set x index of kernel&#39;s center.
Definition: Kernel.h:336
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:742
void setKernelParameters(std::pair< double, double > const &params)
Set the kernel parameters of a 2-component spatially invariant kernel.
Definition: Kernel.h:396
void load_construct_data(Archive &ar, lsst::afw::math::DeltaFunctionKernel *k, unsigned int const file_version)
Definition: Kernel.h:1093
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.
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:852
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
Definition: Kernel.h:436
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
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:325
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:232
friend class boost::serialization::access
Definition: Kernel.h:878
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Formatter for persistence of Kernel instances.
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:702
table::Key< int > kernelFunction
std::vector< std::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:500
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:482
lsst::afw::math::Function2< Pixel > KernelFunction
Definition: Kernel.h:576
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:535
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: FixedKernel.cc:139
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:62
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:685
A kernel described by a function.
Definition: Kernel.h:574
std::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
Definition: Kernel.h:577
friend class boost::serialization::access
Definition: Kernel.h:1045
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:1080
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:682
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:430
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:509
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:537
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:366