LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Kernel.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_MATH_KERNEL_H
26 #define LSST_AFW_MATH_KERNEL_H
27 
36 #include <utility>
37 #include <vector>
38 
39 #include "boost/mpl/or.hpp"
40 #include "boost/shared_ptr.hpp"
41 #include "boost/make_shared.hpp"
42 #include "boost/static_assert.hpp"
43 #include "boost/type_traits/is_same.hpp"
44 #include "boost/type_traits/is_base_and_derived.hpp"
45 
46 #include "boost/serialization/shared_ptr.hpp"
47 #include "boost/serialization/vector.hpp"
48 #include "boost/serialization/export.hpp"
49 
51 #include "lsst/daf/base/Citizen.h"
52 #include "lsst/afw/geom.h"
53 #include "lsst/afw/image/Image.h"
54 #include "lsst/afw/image/Utils.h"
55 #include "lsst/afw/math/Function.h"
56 #include "lsst/afw/math/traits.h"
57 
59 
60 namespace lsst {
61 namespace afw {
62 
63 namespace formatters {
64 class KernelFormatter;
65 }
66 
67 namespace math {
68 
69 #ifndef SWIG
70 using boost::serialization::make_nvp;
71 #endif
72 
135  public afw::table::io::PersistableFacade<Kernel>,
137  {
138 
139  public:
140  typedef double Pixel;
141  typedef PTR(Kernel) Ptr;
143  typedef PTR(lsst::afw::math::Function2<double>) SpatialFunctionPtr;
144  typedef lsst::afw::math::Function2<double> SpatialFunction;
145  typedef lsst::afw::math::NullFunction2<double> NullSpatialFunction;
146 
147  // Traits values for this class of Kernel
149 
155  explicit Kernel();
156 
165  explicit Kernel(
166  int width,
167  int height,
168  unsigned int nKernelParams,
169  SpatialFunction const &spatialFunction=NullSpatialFunction()
171  );
172 
180  explicit Kernel(
181  int width,
182  int height,
183  const std::vector<SpatialFunctionPtr> spatialFunctionList
185  );
186 
187  virtual ~Kernel() {}
188 
200  virtual PTR(Kernel) clone() const = 0;
201 
215  double computeImage(
216  lsst::afw::image::Image<Pixel> &image,
217  bool doNormalize,
219  double x = 0.0,
220  double y = 0.0
221  ) const;
222 
226  geom::Extent2I const getDimensions() const {
227  return geom::Extent2I(_width, _height); }
228 
230  _width = dims.getX();
231  _height = dims.getY();
232 
233  }
234  inline void setWidth(int width) { _width = width; }
235  inline void setHeight(int height) { _height = height; }
236 
240  inline int getWidth() const {
241  return _width;
242  }
243 
247  inline int getHeight() const {
248  return _height;
249  }
250 
256  }
257 
263  inline int getCtrX() const {
264  return _ctrX;
265  }
266 
272  inline int getCtrY() const {
273  return _ctrY;
274  }
275 
280  return lsst::afw::geom::Box2I(
283  );
284  }
285 
289  inline unsigned int getNKernelParameters() const {
290  return _nKernelParams;
291  }
292 
296  inline int getNSpatialParameters() const {
297  return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
298  }
299 
310  unsigned int index
311  ) const;
313 
320  std::vector<SpatialFunctionPtr> getSpatialFunctionList() const;
321 
324  virtual double getKernelParameter(unsigned int i) const {
325  return getKernelParameters()[i];
326  }
327 
335  virtual std::vector<double> getKernelParameters() const;
336 
345 
357 
361  inline void setCtr(lsst::afw::geom::Point2I ctr) {
362  _ctrX = ctr.getX();
363  _ctrY = ctr.getY();
364  _setKernelXY();
365  }
366 
372  inline void setCtrX(int ctrX) {
373  _ctrX = ctrX;
374  _setKernelXY();
375  }
376 
382  inline void setCtrY(int ctrY) {
383  _ctrY = ctrY;
384  _setKernelXY();
385  }
386 
390  inline std::vector<std::vector<double> > getSpatialParameters() const {
391  std::vector<std::vector<double> > spatialParams;
392  std::vector<SpatialFunctionPtr>::const_iterator spFuncIter = _spatialFunctionList.begin();
393  for ( ; spFuncIter != _spatialFunctionList.end(); ++spFuncIter) {
394  spatialParams.push_back((*spFuncIter)->getParameters());
395  }
396  return spatialParams;
397  }
398 
402  inline bool isSpatiallyVarying() const {
403  return _spatialFunctionList.size() != 0;
404  }
405 
412  inline void setKernelParameters(std::vector<double> const &params) {
413  if (this->isSpatiallyVarying()) {
414  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
415  "Kernel is spatially varying");
416  }
417  const unsigned int nParams = this->getNKernelParameters();
418  if (nParams != params.size()) {
419  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
420  (boost::format("Number of parameters is wrong, saw %d expected %d") %
421  nParams % params.size()).str());
422  }
423  for (unsigned int ii = 0; ii < nParams; ++ii) {
424  this->setKernelParameter(ii, params[ii]);
425  }
426  }
427 
434  inline void setKernelParameters(std::pair<double, double> const& params) {
435  this->setKernelParameter(0, params.first);
436  this->setKernelParameter(1, params.second);
437  }
438 
447  void setSpatialParameters(const std::vector<std::vector<double> > params);
448 
456  std::vector<double> &kernelParams, double x, double y) const;
457 
461  virtual std::string toString(std::string const& prefix="") const;
462 
469  virtual void computeCache(
470  int const
471  ) {}
472 
476  virtual int getCacheSize() const { return 0; };
477 
478 #if 0 // fails to compile with icc; is it actually used?
479  virtual void toFile(std::string fileName) const;
480 #endif
481 
482  struct PersistenceHelper;
483 
484  protected:
485 
486  virtual std::string getPythonModule() const;
487 
498  virtual void setKernelParameter(unsigned int ind, double value) const;
499 
508  void setKernelParametersFromSpatialModel(double x, double y) const;
509 
519  virtual double doComputeImage(
521  bool doNormalize
522  ) const = 0;
523 
524  std::vector<SpatialFunctionPtr> _spatialFunctionList;
525 
526  private:
528 
529  int _width;
530  int _height;
531  int _ctrX;
532  int _ctrY;
533  unsigned int _nKernelParams;
534 
535  // prevent copying and assignment (to avoid problems from type slicing)
536  Kernel(const Kernel&);
537  Kernel& operator=(const Kernel&);
538  // Set the Kernel's ideas about the x- and y- coordinates
539  virtual void _setKernelXY() {}
540  };
541 
542  typedef std::vector<PTR(Kernel)> KernelList;
543 
551  class FixedKernel : public afw::table::io::PersistableFacade<FixedKernel>, public Kernel {
552  public:
553  typedef PTR(FixedKernel) Ptr;
555 
559  explicit FixedKernel();
560 
564  explicit FixedKernel(
565  lsst::afw::image::Image<Pixel> const &image
566  );
567 
571  explicit FixedKernel(
572  lsst::afw::math::Kernel const& kernel,
573  lsst::afw::geom::Point2D const& pos
574  );
575 
576  virtual ~FixedKernel() {}
577 
578  virtual PTR(Kernel) clone() const;
579 
580  virtual std::string toString(std::string const& prefix = "") const;
581 
582  virtual Pixel getSum() const {
583  return _sum;
584  }
585 
586  virtual bool isPersistable() const { return true; }
587 
588  class Factory;
589 
590  protected:
591  double doComputeImage(
593  bool doNormalize
594  ) const;
595 
596  virtual std::string getPersistenceName() const;
597 
598  virtual void write(OutputArchiveHandle & handle) const;
599 
600  private:
603 
605  template <class Archive>
606  void serialize(Archive& ar, unsigned int const version) {
607  ar & make_nvp("k",
608  boost::serialization::base_object<Kernel>(*this));
609  ar & make_nvp("img", _image);
610  ar & make_nvp("sum", _sum);
611  }
612  };
613 
614 
628  class AnalyticKernel : public afw::table::io::PersistableFacade<AnalyticKernel>, public Kernel {
629  public:
632  typedef lsst::afw::math::Function2<Pixel> KernelFunction;
633  typedef PTR(lsst::afw::math::Function2<Pixel>) KernelFunctionPtr;
634 
638  explicit AnalyticKernel();
639 
645  explicit AnalyticKernel(
646  int width,
647  int height,
648  KernelFunction const &kernelFunction,
649  Kernel::SpatialFunction const &spatialFunction=NullSpatialFunction()
650  );
653 
661  explicit AnalyticKernel(
662  int width,
663  int height,
664  KernelFunction const &kernelFunction,
665  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList
666  );
668 
669  virtual ~AnalyticKernel() {}
670 
671  virtual PTR(Kernel) clone() const;
672 
673 
690  double computeImage(
691  lsst::afw::image::Image<Pixel> &image,
692  bool doNormalize,
695  double x = 0.0,
696  double y = 0.0
697  ) const;
698 
699  virtual std::vector<double> getKernelParameters() const;
700 
704  virtual KernelFunctionPtr getKernelFunction() const;
705 
706  virtual std::string toString(std::string const& prefix="") const;
707 
708  virtual bool isPersistable() const { return true; }
709 
710  class Factory;
711 
712  protected:
713  virtual double doComputeImage(
715  bool doNormalize
716  ) const;
717 
718  virtual std::string getPersistenceName() const;
719 
720  virtual void write(OutputArchiveHandle & handle) const;
721 
722  protected:
723  virtual void setKernelParameter(unsigned int ind, double value) const;
724 
726 
728  template <class Archive>
729  void serialize(Archive& ar, unsigned int const version) {
730  ar & make_nvp("k",
731  boost::serialization::base_object<Kernel>(*this));
732  ar & make_nvp("fn", _kernelFunctionPtr);
733  }
734  };
735 
736 
744  class DeltaFunctionKernel : public afw::table::io::PersistableFacade<DeltaFunctionKernel>,
745  public Kernel
746  {
747  public:
750  // Traits values for this class of Kernel
752 
758  explicit DeltaFunctionKernel(
759  int width,
760  int height,
761  lsst::afw::geom::Point2I const &point
762  );
763 
764  virtual ~DeltaFunctionKernel() {}
765 
766  virtual PTR(Kernel) clone() const;
767 
768  lsst::afw::geom::Point2I getPixel() const { return _pixel; }
769 
770  virtual std::string toString(std::string const& prefix="") const;
771 
772  virtual bool isPersistable() const { return true; }
773 
774  class Factory;
775 
776  protected:
777  virtual double doComputeImage(
779  bool doNormalize
780  ) const;
781 
782  virtual std::string getPersistenceName() const;
783 
784  virtual void write(OutputArchiveHandle & handle) const;
785 
786  private:
788 
790  template <class Archive>
791  void serialize(Archive& ar, unsigned int const version) {
792  boost::serialization::void_cast_register<
794  static_cast<DeltaFunctionKernel*>(0),
795  static_cast<Kernel*>(0));
796  }
797  };
798 
799 
814  class LinearCombinationKernel : public afw::table::io::PersistableFacade<LinearCombinationKernel>,
815  public Kernel
816  {
817  public:
820 
824  explicit LinearCombinationKernel();
825 
829  explicit LinearCombinationKernel(
830  KernelList const &kernelList,
831  std::vector<double> const &kernelParameters
832  );
833 
838  explicit LinearCombinationKernel(
839  KernelList const &kernelList,
840  Kernel::SpatialFunction const &spatialFunction
841  );
843 
850  explicit LinearCombinationKernel(
851  KernelList const &kernelList,
852  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList
854  );
855 
856  virtual ~LinearCombinationKernel() {}
857 
858  virtual PTR(Kernel) clone() const;
859 
860  virtual std::vector<double> getKernelParameters() const;
861 
865  virtual KernelList const &getKernelList() const;
866 
870  std::vector<double> getKernelSumList() const;
871 
875  int getNBasisKernels() const { return static_cast<int>(_kernelList.size()); };
876 
882  void checkKernelList(const KernelList &kernelList) const;
883 
887  bool isDeltaFunctionBasis() const { return _isDeltaFunctionBasis; };
888 
923  PTR(Kernel) refactor() const;
924 
925  virtual std::string toString(std::string const& prefix="") const;
926 
927  virtual bool isPersistable() const { return true; }
928 
929  class Factory;
930 
931  protected:
932  virtual double doComputeImage(
934  bool doNormalize
935  ) const;
936 
937  virtual std::string getPersistenceName() const;
938 
939  virtual void write(OutputArchiveHandle & handle) const;
940 
941  virtual void setKernelParameter(unsigned int ind, double value) const;
942 
943  private:
947  void _setKernelList(KernelList const &kernelList);
948 
950  std::vector<PTR(lsst::afw::image::Image<Pixel>)> _kernelImagePtrList;
952  std::vector<double> _kernelSumList;
953  mutable std::vector<double> _kernelParams;
955 
957  template <class Archive>
958  void serialize(Archive& ar, unsigned int const version) {
959  ar & make_nvp("k", boost::serialization::base_object<Kernel>(*this));
960  ar & make_nvp("klist", _kernelList);
961  ar & make_nvp("kimglist", _kernelImagePtrList);
962  ar & make_nvp("ksumlist", _kernelSumList);
963  ar & make_nvp("params", _kernelParams);
964  if (version > 0) {
965  ar & make_nvp("deltaBasis", _isDeltaFunctionBasis);
966  }
967  else if (Archive::is_loading::value) {
968  _isDeltaFunctionBasis = false;
969  }
970  }
971  };
972 
986  class SeparableKernel : public afw::table::io::PersistableFacade<SeparableKernel>, public Kernel {
987  public:
990  typedef lsst::afw::math::Function1<Pixel> KernelFunction;
991  typedef PTR(KernelFunction) KernelFunctionPtr;
992 
996  explicit SeparableKernel();
997 
1002  explicit SeparableKernel(
1003  int width,
1004  int height,
1005  KernelFunction const& kernelColFunction,
1006  KernelFunction const& kernelRowFunction,
1007  Kernel::SpatialFunction const& spatialFunction=NullSpatialFunction()
1008  );
1011 
1018  explicit SeparableKernel(
1019  int width,
1020  int height,
1021  KernelFunction const& kernelColFunction,
1022  KernelFunction const& kernelRowFunction,
1023  std::vector<Kernel::SpatialFunctionPtr> const& spatialFunctionList
1024  );
1026  virtual ~SeparableKernel() {}
1027 
1028  virtual PTR(Kernel) clone() const;
1029 
1041  double computeVectors(
1042  std::vector<Pixel> &colList,
1043  std::vector<Pixel> &rowList,
1044  bool doNormalize,
1045  double x = 0.0,
1046  double y = 0.0
1047  ) const;
1048 
1049  virtual double getKernelParameter(unsigned int i) const {
1050  unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
1051  if (i < ncol) {
1052  return _kernelColFunctionPtr->getParameter(i);
1053  } else {
1054  i -= ncol;
1055  return _kernelRowFunctionPtr->getParameter(i);
1056  }
1057  }
1058  virtual std::vector<double> getKernelParameters() const;
1059 
1064 
1069 
1070  virtual std::string toString(std::string const& prefix="") const;
1071 
1072  /***
1073  * @brief Compute a cache of values for the x and y kernel functions
1074  *
1075  * A value of 0 disables the cache for maximum accuracy.
1076  * 10,000 typically results in a warping error of a fraction of a count.
1077  * 100,000 typically results in a warping error of less than 0.01 count.
1078  */
1079  virtual void computeCache(
1080  int const cacheSize
1081  );
1082 
1086  virtual int getCacheSize() const;
1087 
1088  protected:
1089  virtual double doComputeImage(
1091  bool doNormalize
1092  ) const;
1093 
1094  virtual void setKernelParameter(unsigned int ind, double value) const;
1095 
1096  private:
1107  double basicComputeVectors(
1108  std::vector<Pixel> &colList,
1109  std::vector<Pixel> &rowList,
1110  bool doNormalize
1111  ) const;
1112 
1115  mutable std::vector<Pixel> _localColList; // used by doComputeImage
1116  mutable std::vector<Pixel> _localRowList;
1117  mutable std::vector<double> _kernelX; // used by SeparableKernel::basicComputeVectors
1118  mutable std::vector<double> _kernelY;
1119  //
1120  // Cached values of the row- and column- kernels
1121  //
1122  mutable std::vector<std::vector<double> > _kernelRowCache;
1123  mutable std::vector<std::vector<double> > _kernelColCache;
1124 
1126  template <class Archive>
1127  void serialize(Archive& ar, unsigned int const version) {
1128  ar & make_nvp("k",
1129  boost::serialization::base_object<Kernel>(*this));
1130  ar & make_nvp("colfn", _kernelColFunctionPtr);
1131  ar & make_nvp("rowfn", _kernelRowFunctionPtr);
1132  ar & make_nvp("cols", _localColList);
1133  ar & make_nvp("rows", _localRowList);
1134  ar & make_nvp("kernelX", _kernelX);
1135  ar & make_nvp("kernelY", _kernelY);
1136  }
1137 
1138  virtual void _setKernelXY() {
1140  lsst::afw::geom::Point2I const ctr = getCtr();
1141 
1142  assert (dim[0] == static_cast<int>(_kernelX.size()));
1143  for (int i = 0; i != dim.getX(); ++i) {
1144  _kernelX[i] = i - ctr.getX();
1145  }
1146 
1147  assert (dim[1] == static_cast<int>(_kernelY.size()));
1148  for (int i = 0; i != dim.getY(); ++i) {
1149  _kernelY[i] = i - ctr.getY();
1150  }
1151  }
1152  };
1153 
1154 }}} // lsst:afw::math
1155 
1156 namespace boost {
1157 namespace serialization {
1158 
1159 template <class Archive>
1161  Archive& ar, lsst::afw::math::DeltaFunctionKernel const* k,
1162  unsigned int const file_version) {
1163  int width = k->getWidth();
1164  int height = k->getHeight();
1165  int x = k->getPixel().getX();
1166  int y = k->getPixel().getY();
1167  ar << make_nvp("width", width);
1168  ar << make_nvp("height", height);
1169  ar << make_nvp("pixX", x);
1170  ar << make_nvp("pixY", y);
1171 }
1172 
1173 template <class Archive>
1175  Archive& ar, lsst::afw::math::DeltaFunctionKernel* k,
1176  unsigned int const file_version) {
1177  int width;
1178  int height;
1179  int x;
1180  int y;
1181  ar >> make_nvp("width", width);
1182  ar >> make_nvp("height", height);
1183  ar >> make_nvp("pixX", x);
1184  ar >> make_nvp("pixY", y);
1186  width, height, lsst::afw::geom::Point2I(x, y));
1187 }
1188 
1189 }}
1190 
1191 #ifndef SWIG
1192 BOOST_CLASS_VERSION(lsst::afw::math::LinearCombinationKernel, 1)
1193 #endif
1194 
1195 #endif // !defined(LSST_AFW_MATH_KERNEL_H)
int y
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: FixedKernel.cc:102
lsst::afw::image::Image< Pixel > _image
Definition: Kernel.h:601
virtual int getCacheSize() const
Get the current cache size (0 if none)
std::vector< double > _kernelY
Definition: Kernel.h:1118
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.
friend class boost::serialization::access
Definition: Kernel.h:789
std::vector< double > _kernelParams
Definition: Kernel.h:953
An include file to include the header files for lsst::afw::geom.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:708
void load_construct_data(Archive &ar, lsst::meas::algorithms::DoubleGaussianPsf *p, unsigned int const )
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:240
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:143
#define PTR(...)
Definition: base.h:41
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
Definition: Kernel.cc:257
void setHeight(int height)
Definition: Kernel.h:235
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
Definition: Kernel.h:476
boost::shared_ptr< Kernel const > ConstPtr
Definition: Kernel.h:142
virtual KernelList const & getKernelList() const
Get the fixed basis kernels.
void save_construct_data(Archive &ar, lsst::meas::algorithms::DoubleGaussianPsf const *p, unsigned int const )
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Definition: Kernel.cc:253
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:264
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:247
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:224
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
virtual double getKernelParameter(unsigned int i) const
Definition: Kernel.h:324
lsst::afw::geom::Point2I _pixel
Definition: Kernel.h:787
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
Definition: Kernel.cc:196
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:524
#define CONST_PTR(...)
Definition: base.h:47
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
lsst::afw::geom::Box2I growBBox(lsst::afw::geom::Box2I const &bbox) const
Definition: Kernel.cc:201
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:986
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
Definition: Kernel.cc:186
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
void setCtrY(int ctrY)
Set y index of kernel&#39;s center.
Definition: Kernel.h:382
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
Definition: Kernel.h:289
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
Definition: Kernel.h:296
std::vector< double > getKernelSumList() const
Get the sum of the pixels of each fixed basis kernel.
Traits to describe kernels, allowing for compile-time optimisation.
void _setKernelList(KernelList const &kernelList)
Set _kernelList by cloning each input kernel and update the kernel image cache.
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:114
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:254
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
Definition: FixedKernel.cc:76
std::vector< Pixel > _localRowList
Definition: Kernel.h:1116
friend class boost::serialization::access
Definition: Kernel.h:604
Point< int, 2 > Point2I
Definition: PSF.h:39
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model) ...
Definition: Kernel.cc:171
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
A Function taking two arguments.
Definition: Function.h:300
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1123
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:402
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) ...
An integer coordinate rectangle.
Definition: Box.h:53
tbl::Key< int > cacheSize
Definition: CoaddPsf.cc:318
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:791
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:729
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:772
virtual void computeCache(int const cacheSize)
Compute a cache of Kernel values, if desired.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: FixedKernel.cc:165
a class used in function calls to indicate that no Function2 is being provided
Definition: Function.h:536
virtual boost::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
std::vector< Pixel > _localColList
Definition: Kernel.h:1115
std::vector< double > _kernelX
Definition: Kernel.h:1117
A set of classes of general utility in connection with images.
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying) ...
Definition: Kernel.h:390
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
friend class boost::serialization::access
Definition: Kernel.h:727
boost::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
Definition: Kernel.h:633
boost::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:814
virtual boost::shared_ptr< Kernel > clone() const
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:469
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
geom::Extent2I const getDimensions() const
Return the Kernel&#39;s dimensions (width, height)
Definition: Kernel.h:226
A Function taking one argument.
Definition: Function.h:229
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
std::vector< std::vector< double > > _kernelRowCache
Definition: Kernel.h:1122
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Support for 2-D images.
void setKernelParameters(std::vector< double > const &params)
Set the kernel parameters of a spatially invariant kernel.
Definition: Kernel.h:412
KernelFunctionPtr _kernelFunctionPtr
Definition: Kernel.h:725
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel&#39;s center.
Definition: Kernel.h:361
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
boost::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 double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
friend class boost::serialization::access
Definition: Kernel.h:956
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Interface for Persistable base class.
int x
virtual void _setKernelXY()
Definition: Kernel.h:539
int getNBasisKernels() const
Get the number of basis kernels.
Definition: Kernel.h:875
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:279
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
#define LSST_PERSIST_FORMATTER(formatter...)
Definition: Persistable.h:98
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
Kernel has only one non-zero pixel.
Definition: traits.h:59
table::Key< int > kernelFunction
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
lsst::afw::geom::Point2I getPixel() const
Definition: Kernel.h:768
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
Definition: Kernel.cc:162
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
virtual Pixel getSum() const
Definition: Kernel.h:582
Define the basic Function classes.
virtual void _setKernelXY()
Definition: Kernel.h:1138
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
unsigned int _nKernelParams
Definition: Kernel.h:533
Point< double, 2 > Point2D
Definition: Point.h:286
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
double basicComputeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row) ...
Base class for all persistable classes.
Definition: Persistable.h:74
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
boost::shared_ptr< KernelFunction > KernelFunctionPtr
Definition: Kernel.h:991
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:586
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:542
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:958
A kernel described by a function.
Definition: Kernel.h:628
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:927
void setWidth(int width)
Definition: Kernel.h:234
int getCtrY() const
Return y index of kernel&#39;s center.
Definition: Kernel.h:272
void setCtrX(int ctrX)
Set x index of kernel&#39;s center.
Definition: Kernel.h:372
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: FixedKernel.cc:167
lsst::afw::geom::Box2I shrinkBBox(lsst::afw::geom::Box2I const &bbox) const
Definition: Kernel.cc:207
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
friend class boost::serialization::access
Definition: Kernel.h:1125
void setDimensions(geom::Extent2I dims)
Definition: Kernel.h:229
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:182
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Extent< int, 2 > Extent2I
Definition: Extent.h:355
void setSpatialParameters(const std::vector< std::vector< double > > params)
Set the parameters of all spatial functions.
Definition: Kernel.cc:139
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:744
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:606
void setKernelParameters(std::pair< double, double > const &params)
Set the kernel parameters of a 2-component spatially invariant kernel.
Definition: Kernel.h:434
virtual double getKernelParameter(unsigned int i) const
Definition: Kernel.h:1049
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:1127
DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
Tags carrying information about Kernels Kernel with no special properties.
Definition: traits.h:58
A kernel created from an Image.
Definition: Kernel.h:551
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:94
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Definition: FixedKernel.cc:70
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
int getCtrX() const
Return x index of kernel&#39;s center.
Definition: Kernel.h:263