LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
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 
36 #include <memory>
37 #include <type_traits>
38 #include <utility>
39 #include <vector>
40 
41 #include "boost/mpl/or.hpp"
42 
43 #include "boost/serialization/shared_ptr.hpp"
44 #include "boost/serialization/vector.hpp"
45 #include "boost/serialization/export.hpp"
46 
48 #include "lsst/daf/base/Citizen.h"
49 #include "lsst/afw/geom.h"
50 #include "lsst/afw/image/Image.h"
51 #include "lsst/afw/image/Utils.h"
52 #include "lsst/afw/math/Function.h"
53 #include "lsst/afw/math/traits.h"
54 
56 
57 namespace lsst {
58 namespace afw {
59 
60 namespace formatters {
61 class KernelFormatter;
62 }
63 
64 namespace math {
65 
66 #ifndef SWIG
67 using boost::serialization::make_nvp;
68 #endif
69 
132  public afw::table::io::PersistableFacade<Kernel>,
134  {
135 
136  public:
137  typedef double Pixel;
138  typedef PTR(Kernel) Ptr;
140  typedef PTR(lsst::afw::math::Function2<double>) SpatialFunctionPtr;
141  typedef lsst::afw::math::Function2<double> SpatialFunction;
142  typedef lsst::afw::math::NullFunction2<double> NullSpatialFunction;
143 
144  // Traits values for this class of Kernel
146 
152  explicit Kernel();
153 
162  explicit Kernel(
163  int width,
164  int height,
165  unsigned int nKernelParams,
166  SpatialFunction const &spatialFunction=NullSpatialFunction()
168  );
169 
177  explicit Kernel(
178  int width,
179  int height,
180  const std::vector<SpatialFunctionPtr> spatialFunctionList
182  );
183 
184  virtual ~Kernel() {}
185 
197  virtual PTR(Kernel) clone() const = 0;
198 
212  double computeImage(
213  lsst::afw::image::Image<Pixel> &image,
214  bool doNormalize,
216  double x = 0.0,
217  double y = 0.0
218  ) const;
219 
223  geom::Extent2I const getDimensions() const {
224  return geom::Extent2I(_width, _height); }
225 
227  _width = dims.getX();
228  _height = dims.getY();
229 
230  }
231  inline void setWidth(int width) { _width = width; }
232  inline void setHeight(int height) { _height = height; }
233 
237  inline int getWidth() const {
238  return _width;
239  }
240 
244  inline int getHeight() const {
245  return _height;
246  }
247 
253  }
254 
260  inline int getCtrX() const {
261  return _ctrX;
262  }
263 
269  inline int getCtrY() const {
270  return _ctrY;
271  }
272 
277  return lsst::afw::geom::Box2I(
280  );
281  }
282 
286  inline unsigned int getNKernelParameters() const {
287  return _nKernelParams;
288  }
289 
293  inline int getNSpatialParameters() const {
294  return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
295  }
296 
307  unsigned int index
308  ) const;
310 
317  std::vector<SpatialFunctionPtr> getSpatialFunctionList() const;
318 
321  virtual double getKernelParameter(unsigned int i) const {
322  return getKernelParameters()[i];
323  }
324 
332  virtual std::vector<double> getKernelParameters() const;
333 
342 
354 
358  inline void setCtr(lsst::afw::geom::Point2I ctr) {
359  _ctrX = ctr.getX();
360  _ctrY = ctr.getY();
361  _setKernelXY();
362  }
363 
369  inline void setCtrX(int ctrX) {
370  _ctrX = ctrX;
371  _setKernelXY();
372  }
373 
379  inline void setCtrY(int ctrY) {
380  _ctrY = ctrY;
381  _setKernelXY();
382  }
383 
387  inline std::vector<std::vector<double> > getSpatialParameters() const {
388  std::vector<std::vector<double> > spatialParams;
389  std::vector<SpatialFunctionPtr>::const_iterator spFuncIter = _spatialFunctionList.begin();
390  for ( ; spFuncIter != _spatialFunctionList.end(); ++spFuncIter) {
391  spatialParams.push_back((*spFuncIter)->getParameters());
392  }
393  return spatialParams;
394  }
395 
399  inline bool isSpatiallyVarying() const {
400  return _spatialFunctionList.size() != 0;
401  }
402 
409  inline void setKernelParameters(std::vector<double> const &params) {
410  if (this->isSpatiallyVarying()) {
411  throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
412  "Kernel is spatially varying");
413  }
414  const unsigned int nParams = this->getNKernelParameters();
415  if (nParams != params.size()) {
416  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
417  (boost::format("Number of parameters is wrong, saw %d expected %d") %
418  nParams % params.size()).str());
419  }
420  for (unsigned int ii = 0; ii < nParams; ++ii) {
421  this->setKernelParameter(ii, params[ii]);
422  }
423  }
424 
431  inline void setKernelParameters(std::pair<double, double> const& params) {
432  this->setKernelParameter(0, params.first);
433  this->setKernelParameter(1, params.second);
434  }
435 
444  void setSpatialParameters(const std::vector<std::vector<double> > params);
445 
453  std::vector<double> &kernelParams, double x, double y) const;
454 
458  virtual std::string toString(std::string const& prefix="") const;
459 
466  virtual void computeCache(
467  int const
468  ) {}
469 
473  virtual int getCacheSize() const { return 0; };
474 
475 #if 0 // fails to compile with icc; is it actually used?
476  virtual void toFile(std::string fileName) const;
477 #endif
478 
479  struct PersistenceHelper;
480 
481  protected:
482 
483  virtual std::string getPythonModule() const;
484 
495  virtual void setKernelParameter(unsigned int ind, double value) const;
496 
505  void setKernelParametersFromSpatialModel(double x, double y) const;
506 
516  virtual double doComputeImage(
518  bool doNormalize
519  ) const = 0;
520 
521  std::vector<SpatialFunctionPtr> _spatialFunctionList;
522 
523  private:
525 
526  int _width;
527  int _height;
528  int _ctrX;
529  int _ctrY;
530  unsigned int _nKernelParams;
531 
532  // prevent copying and assignment (to avoid problems from type slicing)
533  Kernel(const Kernel&);
534  Kernel& operator=(const Kernel&);
535  // Set the Kernel's ideas about the x- and y- coordinates
536  virtual void _setKernelXY() {}
537  };
538 
539  typedef std::vector<PTR(Kernel)> KernelList;
540 
548  class FixedKernel : public afw::table::io::PersistableFacade<FixedKernel>, public Kernel {
549  public:
550  typedef PTR(FixedKernel) Ptr;
552 
556  explicit FixedKernel();
557 
561  explicit FixedKernel(
562  lsst::afw::image::Image<Pixel> const &image
563  );
564 
568  explicit FixedKernel(
569  lsst::afw::math::Kernel const& kernel,
570  lsst::afw::geom::Point2D const& pos
571  );
572 
573  virtual ~FixedKernel() {}
574 
575  virtual PTR(Kernel) clone() const;
576 
577  virtual std::string toString(std::string const& prefix = "") const;
578 
579  virtual Pixel getSum() const {
580  return _sum;
581  }
582 
583  virtual bool isPersistable() const { return true; }
584 
585  class Factory;
586 
587  protected:
588  double doComputeImage(
590  bool doNormalize
591  ) const;
592 
593  virtual std::string getPersistenceName() const;
594 
595  virtual void write(OutputArchiveHandle & handle) const;
596 
597  private:
600 
602  template <class Archive>
603  void serialize(Archive& ar, unsigned int const version) {
604  ar & make_nvp("k",
605  boost::serialization::base_object<Kernel>(*this));
606  ar & make_nvp("img", _image);
607  ar & make_nvp("sum", _sum);
608  }
609  };
610 
611 
625  class AnalyticKernel : public afw::table::io::PersistableFacade<AnalyticKernel>, public Kernel {
626  public:
629  typedef lsst::afw::math::Function2<Pixel> KernelFunction;
630  typedef PTR(lsst::afw::math::Function2<Pixel>) KernelFunctionPtr;
631 
635  explicit AnalyticKernel();
636 
642  explicit AnalyticKernel(
643  int width,
644  int height,
645  KernelFunction const &kernelFunction,
646  Kernel::SpatialFunction const &spatialFunction=NullSpatialFunction()
647  );
650 
658  explicit AnalyticKernel(
659  int width,
660  int height,
661  KernelFunction const &kernelFunction,
662  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList
663  );
665 
666  virtual ~AnalyticKernel() {}
667 
668  virtual PTR(Kernel) clone() const;
669 
670 
687  double computeImage(
688  lsst::afw::image::Image<Pixel> &image,
689  bool doNormalize,
692  double x = 0.0,
693  double y = 0.0
694  ) const;
695 
696  virtual std::vector<double> getKernelParameters() const;
697 
701  virtual KernelFunctionPtr getKernelFunction() const;
702 
703  virtual std::string toString(std::string const& prefix="") const;
704 
705  virtual bool isPersistable() const { return true; }
706 
707  class Factory;
708 
709  protected:
710  virtual double doComputeImage(
712  bool doNormalize
713  ) const;
714 
715  virtual std::string getPersistenceName() const;
716 
717  virtual void write(OutputArchiveHandle & handle) const;
718 
719  protected:
720  virtual void setKernelParameter(unsigned int ind, double value) const;
721 
723 
725  template <class Archive>
726  void serialize(Archive& ar, unsigned int const version) {
727  ar & make_nvp("k",
728  boost::serialization::base_object<Kernel>(*this));
729  ar & make_nvp("fn", _kernelFunctionPtr);
730  }
731  };
732 
733 
741  class DeltaFunctionKernel : public afw::table::io::PersistableFacade<DeltaFunctionKernel>,
742  public Kernel
743  {
744  public:
747  // Traits values for this class of Kernel
749 
755  explicit DeltaFunctionKernel(
756  int width,
757  int height,
758  lsst::afw::geom::Point2I const &point
759  );
760 
761  virtual ~DeltaFunctionKernel() {}
762 
763  virtual PTR(Kernel) clone() const;
764 
765  lsst::afw::geom::Point2I getPixel() const { return _pixel; }
766 
767  virtual std::string toString(std::string const& prefix="") const;
768 
769  virtual bool isPersistable() const { return true; }
770 
771  class Factory;
772 
773  protected:
774  virtual double doComputeImage(
776  bool doNormalize
777  ) const;
778 
779  virtual std::string getPersistenceName() const;
780 
781  virtual void write(OutputArchiveHandle & handle) const;
782 
783  private:
785 
787  template <class Archive>
788  void serialize(Archive& ar, unsigned int const version) {
789  boost::serialization::void_cast_register<
791  static_cast<DeltaFunctionKernel*>(0),
792  static_cast<Kernel*>(0));
793  }
794  };
795 
796 
811  class LinearCombinationKernel : public afw::table::io::PersistableFacade<LinearCombinationKernel>,
812  public Kernel
813  {
814  public:
817 
821  explicit LinearCombinationKernel();
822 
826  explicit LinearCombinationKernel(
827  KernelList const &kernelList,
828  std::vector<double> const &kernelParameters
829  );
830 
835  explicit LinearCombinationKernel(
836  KernelList const &kernelList,
837  Kernel::SpatialFunction const &spatialFunction
838  );
840 
847  explicit LinearCombinationKernel(
848  KernelList const &kernelList,
849  std::vector<Kernel::SpatialFunctionPtr> const &spatialFunctionList
851  );
852 
853  virtual ~LinearCombinationKernel() {}
854 
855  virtual PTR(Kernel) clone() const;
856 
857  virtual std::vector<double> getKernelParameters() const;
858 
862  virtual KernelList const &getKernelList() const;
863 
867  std::vector<double> getKernelSumList() const;
868 
872  int getNBasisKernels() const { return static_cast<int>(_kernelList.size()); };
873 
879  void checkKernelList(const KernelList &kernelList) const;
880 
884  bool isDeltaFunctionBasis() const { return _isDeltaFunctionBasis; };
885 
920  PTR(Kernel) refactor() const;
921 
922  virtual std::string toString(std::string const& prefix="") const;
923 
924  virtual bool isPersistable() const { return true; }
925 
926  class Factory;
927 
928  protected:
929  virtual double doComputeImage(
931  bool doNormalize
932  ) const;
933 
934  virtual std::string getPersistenceName() const;
935 
936  virtual void write(OutputArchiveHandle & handle) const;
937 
938  virtual void setKernelParameter(unsigned int ind, double value) const;
939 
940  private:
944  void _setKernelList(KernelList const &kernelList);
945 
947  std::vector<PTR(lsst::afw::image::Image<Pixel>)> _kernelImagePtrList;
949  std::vector<double> _kernelSumList;
950  mutable std::vector<double> _kernelParams;
952 
954  template <class Archive>
955  void serialize(Archive& ar, unsigned int const version) {
956  ar & make_nvp("k", boost::serialization::base_object<Kernel>(*this));
957  ar & make_nvp("klist", _kernelList);
958  ar & make_nvp("kimglist", _kernelImagePtrList);
959  ar & make_nvp("ksumlist", _kernelSumList);
960  ar & make_nvp("params", _kernelParams);
961  if (version > 0) {
962  ar & make_nvp("deltaBasis", _isDeltaFunctionBasis);
963  }
964  else if (Archive::is_loading::value) {
965  _isDeltaFunctionBasis = false;
966  }
967  }
968  };
969 
983  class SeparableKernel : public afw::table::io::PersistableFacade<SeparableKernel>, public Kernel {
984  public:
987  typedef lsst::afw::math::Function1<Pixel> KernelFunction;
988  typedef PTR(KernelFunction) KernelFunctionPtr;
989 
993  explicit SeparableKernel();
994 
999  explicit SeparableKernel(
1000  int width,
1001  int height,
1002  KernelFunction const& kernelColFunction,
1003  KernelFunction const& kernelRowFunction,
1004  Kernel::SpatialFunction const& spatialFunction=NullSpatialFunction()
1005  );
1008 
1015  explicit SeparableKernel(
1016  int width,
1017  int height,
1018  KernelFunction const& kernelColFunction,
1019  KernelFunction const& kernelRowFunction,
1020  std::vector<Kernel::SpatialFunctionPtr> const& spatialFunctionList
1021  );
1023  virtual ~SeparableKernel() {}
1024 
1025  virtual PTR(Kernel) clone() const;
1026 
1038  double computeVectors(
1039  std::vector<Pixel> &colList,
1040  std::vector<Pixel> &rowList,
1041  bool doNormalize,
1042  double x = 0.0,
1043  double y = 0.0
1044  ) const;
1045 
1046  virtual double getKernelParameter(unsigned int i) const {
1047  unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
1048  if (i < ncol) {
1049  return _kernelColFunctionPtr->getParameter(i);
1050  } else {
1051  i -= ncol;
1052  return _kernelRowFunctionPtr->getParameter(i);
1053  }
1054  }
1055  virtual std::vector<double> getKernelParameters() const;
1056 
1061 
1066 
1067  virtual std::string toString(std::string const& prefix="") const;
1068 
1069  /***
1070  * @brief Compute a cache of values for the x and y kernel functions
1071  *
1072  * A value of 0 disables the cache for maximum accuracy.
1073  * 10,000 typically results in a warping error of a fraction of a count.
1074  * 100,000 typically results in a warping error of less than 0.01 count.
1075  */
1076  virtual void computeCache(
1077  int const cacheSize
1078  );
1079 
1083  virtual int getCacheSize() const;
1084 
1085  protected:
1086  virtual double doComputeImage(
1088  bool doNormalize
1089  ) const;
1090 
1091  virtual void setKernelParameter(unsigned int ind, double value) const;
1092 
1093  private:
1104  double basicComputeVectors(
1105  std::vector<Pixel> &colList,
1106  std::vector<Pixel> &rowList,
1107  bool doNormalize
1108  ) const;
1109 
1112  mutable std::vector<Pixel> _localColList; // used by doComputeImage
1113  mutable std::vector<Pixel> _localRowList;
1114  mutable std::vector<double> _kernelX; // used by SeparableKernel::basicComputeVectors
1115  mutable std::vector<double> _kernelY;
1116  //
1117  // Cached values of the row- and column- kernels
1118  //
1119  mutable std::vector<std::vector<double> > _kernelRowCache;
1120  mutable std::vector<std::vector<double> > _kernelColCache;
1121 
1123  template <class Archive>
1124  void serialize(Archive& ar, unsigned int const version) {
1125  ar & make_nvp("k",
1126  boost::serialization::base_object<Kernel>(*this));
1127  ar & make_nvp("colfn", _kernelColFunctionPtr);
1128  ar & make_nvp("rowfn", _kernelRowFunctionPtr);
1129  ar & make_nvp("cols", _localColList);
1130  ar & make_nvp("rows", _localRowList);
1131  ar & make_nvp("kernelX", _kernelX);
1132  ar & make_nvp("kernelY", _kernelY);
1133  }
1134 
1135  virtual void _setKernelXY() {
1137  lsst::afw::geom::Point2I const ctr = getCtr();
1138 
1139  assert (dim[0] == static_cast<int>(_kernelX.size()));
1140  for (int i = 0; i != dim.getX(); ++i) {
1141  _kernelX[i] = i - ctr.getX();
1142  }
1143 
1144  assert (dim[1] == static_cast<int>(_kernelY.size()));
1145  for (int i = 0; i != dim.getY(); ++i) {
1146  _kernelY[i] = i - ctr.getY();
1147  }
1148  }
1149  };
1150 
1151 }}} // lsst:afw::math
1152 
1153 namespace boost {
1154 namespace serialization {
1155 
1156 template <class Archive>
1158  Archive& ar, lsst::afw::math::DeltaFunctionKernel const* k,
1159  unsigned int const file_version) {
1160  int width = k->getWidth();
1161  int height = k->getHeight();
1162  int x = k->getPixel().getX();
1163  int y = k->getPixel().getY();
1164  ar << make_nvp("width", width);
1165  ar << make_nvp("height", height);
1166  ar << make_nvp("pixX", x);
1167  ar << make_nvp("pixY", y);
1168 }
1169 
1170 template <class Archive>
1172  Archive& ar, lsst::afw::math::DeltaFunctionKernel* k,
1173  unsigned int const file_version) {
1174  int width;
1175  int height;
1176  int x;
1177  int y;
1178  ar >> make_nvp("width", width);
1179  ar >> make_nvp("height", height);
1180  ar >> make_nvp("pixX", x);
1181  ar >> make_nvp("pixY", y);
1183  width, height, lsst::afw::geom::Point2I(x, y));
1184 }
1185 
1186 }}
1187 
1188 #ifndef SWIG
1189 BOOST_CLASS_VERSION(lsst::afw::math::LinearCombinationKernel, 1)
1190 #endif
1191 
1192 #endif // !defined(LSST_AFW_MATH_KERNEL_H)
int y
std::vector< double > getKernelSumList() const
Get the sum of the pixels of each fixed basis kernel.
virtual double getKernelParameter(unsigned int i) const
Definition: Kernel.h:1046
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:786
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:140
An include file to include the header files for lsst::afw::geom.
void load_construct_data(Archive &ar, lsst::meas::algorithms::DoubleGaussianPsf *p, unsigned int const )
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:223
double computeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize, double x=0.0, double y=0.0) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row) ...
std::vector< std::vector< double > > _kernelRowCache
Definition: Kernel.h:1119
A set of classes of general utility in connection with images.
boost::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
Definition: Kernel.h:630
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1111
#define LSST_PERSIST_FORMATTER(formatter...)
Definition: Persistable.h:98
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
Definition: Kernel.cc:186
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:705
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...
Interface for Persistable base class.
void setDimensions(geom::Extent2I dims)
Definition: Kernel.h:226
void save_construct_data(Archive &ar, lsst::meas::algorithms::DoubleGaussianPsf const *p, unsigned int const )
void setWidth(int width)
Definition: Kernel.h:231
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
KernelList _kernelList
basis kernels
Definition: Kernel.h:946
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
lsst::afw::geom::Box2I growBBox(lsst::afw::geom::Box2I const &bbox) const
Definition: Kernel.cc:201
int getCtrY() const
Return y index of kernel&#39;s center.
Definition: Kernel.h:269
void setKernelParameters(std::vector< double > const &params)
Set the kernel parameters of a spatially invariant kernel.
Definition: Kernel.h:409
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:276
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:224
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:983
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
Definition: Kernel.h:293
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:726
Point< double, 2 > Point2D
Definition: Point.h:288
std::vector< Pixel > _localColList
Definition: Kernel.h:1112
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: FixedKernel.cc:165
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying) ...
Definition: Kernel.h:387
Traits to describe kernels, allowing for compile-time optimisation.
void setHeight(int height)
Definition: Kernel.h:232
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:788
boost::shared_ptr< KernelFunction > KernelFunctionPtr
Definition: Kernel.h:988
int getCtrX() const
Return x index of kernel&#39;s center.
Definition: Kernel.h:260
friend class boost::serialization::access
Definition: Kernel.h:601
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
Definition: Kernel.cc:253
Point< int, 2 > Point2I
Definition: PSF.h:39
#define CONST_PTR(...)
Definition: base.h:47
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Extent< int, 2 > Extent2I
Definition: Extent.h:358
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: FixedKernel.cc:102
A Function taking two arguments.
Definition: Function.h:300
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:769
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
lsst::afw::geom::Point2I _pixel
Definition: Kernel.h:784
std::vector< Pixel > _localRowList
Definition: Kernel.h:1113
An integer coordinate rectangle.
Definition: Box.h:53
tbl::Key< int > cacheSize
Definition: CoaddPsf.cc:327
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:244
std::vector< double > _kernelX
Definition: Kernel.h:1114
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:72
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) ...
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:237
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:1124
a class used in function calls to indicate that no Function2 is being provided
Definition: Function.h:536
boost::shared_ptr< Kernel const > ConstPtr
Definition: Kernel.h:139
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:955
void setCtrY(int ctrY)
Set y index of kernel&#39;s center.
Definition: Kernel.h:379
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual double getKernelParameter(unsigned int i) const
Definition: Kernel.h:321
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:196
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
KernelFunctionPtr _kernelFunctionPtr
Definition: Kernel.h:722
friend class boost::serialization::access
Definition: Kernel.h:724
int getNBasisKernels() const
Get the number of basis kernels.
Definition: Kernel.h:872
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
Definition: Kernel.cc:257
std::vector< double > _kernelParams
Definition: Kernel.h:950
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
Definition: Kernel.h:286
void setCtrX(int ctrX)
Set x index of kernel&#39;s center.
Definition: Kernel.h:369
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
virtual KernelList const & getKernelList() const
Get the fixed basis kernels.
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:94
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:811
void setKernelParameters(std::pair< double, double > const &params)
Set the kernel parameters of a 2-component spatially invariant kernel.
Definition: Kernel.h:431
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
A Function taking one argument.
Definition: Function.h:229
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:924
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
Definition: Kernel.h:473
unsigned int _nKernelParams
Definition: Kernel.h:530
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Support for 2-D images.
double x
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel&#39;s center.
Definition: Kernel.h:358
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:251
virtual boost::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
friend class boost::serialization::access
Definition: Kernel.h:953
void setSpatialParameters(const std::vector< std::vector< double > > params)
Set the parameters of all spatial functions.
Definition: Kernel.cc:139
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1120
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
void serialize(Archive &ar, unsigned int const version)
Definition: Kernel.h:603
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Definition: FixedKernel.cc:70
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual void computeCache(int const cacheSize)
Compute a cache of Kernel values, if desired.
Kernel has only one non-zero pixel.
Definition: traits.h:59
lsst::afw::geom::Point2I getPixel() const
Definition: Kernel.h:765
table::Key< int > kernelFunction
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 std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1110
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:521
#define PTR(...)
Definition: base.h:41
Define the basic Function classes.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
void _setKernelList(KernelList const &kernelList)
Set _kernelList by cloning each input kernel and update the kernel image cache.
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:947
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:112
virtual Pixel getSum() const
Definition: Kernel.h:579
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: FixedKernel.cc:167
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
Definition: Kernel.cc:162
std::vector< double > _kernelY
Definition: Kernel.h:1115
std::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:949
Base class for all persistable classes.
Definition: Persistable.h:74
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:76
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:53
A kernel described by a function.
Definition: Kernel.h:625
lsst::afw::image::Image< Pixel > _image
Definition: Kernel.h:598
virtual void _setKernelXY()
Definition: Kernel.h:536
friend class boost::serialization::access
Definition: Kernel.h:1122
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:180
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:131
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:741
virtual void computeCache(int const )
Compute a cache of Kernel values, if desired.
Definition: Kernel.h:466
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
lsst::afw::geom::Box2I shrinkBBox(lsst::afw::geom::Box2I const &bbox) const
Definition: Kernel.cc:207
Tags carrying information about Kernels Kernel with no special properties.
Definition: traits.h:58
A kernel created from an Image.
Definition: Kernel.h:548
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:539
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Kernel.h:583
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:399