LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
KernelSolution.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
12 #ifndef LSST_IP_DIFFIM_KERNELSOLUTION_H
13 #define LSST_IP_DIFFIM_KERNELSOLUTION_H
14 
15 #include <memory>
16 #include "Eigen/Core"
17 
18 #include "lsst/afw/math.h"
19 #include "lsst/afw/image.h"
20 #include "lsst/geom.h"
21 #include "lsst/daf/base.h"
22 
23 namespace lsst {
24 namespace ip {
25 namespace diffim {
26 
27  /*
28  * @brief Method used to solve for M and B
29  */
30 
32  public:
36 
38  NONE = 0,
41  LU = 3,
42  EIGENVECTOR = 4
43  };
44 
47  SVD = 1
48  };
49 
50  explicit KernelSolution(Eigen::MatrixXd mMat,
51  Eigen::VectorXd bVec,
52  bool fitForBackground);
53  explicit KernelSolution(bool fitForBackground);
54  explicit KernelSolution();
55 
56  virtual ~KernelSolution() {};
57  virtual void solve();
58  virtual void solve(Eigen::MatrixXd const& mMat,
59  Eigen::VectorXd const& bVec);
61  virtual double getConditionNumber(ConditionNumberType conditionType);
62  virtual double getConditionNumber(Eigen::MatrixXd const& mMat, ConditionNumberType conditionType);
63 
64  inline Eigen::MatrixXd const& getM() {return _mMat;}
65  inline Eigen::VectorXd const& getB() {return _bVec;}
66  void printM() {std::cout << _mMat << std::endl;}
67  void printB() {std::cout << _bVec << std::endl;}
68  void printA() {std::cout << _aVec << std::endl;}
69  inline int getId() const { return _id; }
70 
71  protected:
72  int _id;
73  Eigen::MatrixXd _mMat;
74  Eigen::VectorXd _bVec;
75  Eigen::VectorXd _aVec;
78  static int _SolutionId;
79 
80  };
81 
82  template <typename InputT>
84  public:
86 
88  bool fitForBackground);
89  virtual ~StaticKernelSolution() {};
90 
91  /* Overrides KernelSolution */
92  void solve();
93 
94  /* Used by RegularizedKernelSolution */
95  virtual void build(lsst::afw::image::Image<InputT> const &templateImage,
96  lsst::afw::image::Image<InputT> const &scienceImage,
100  virtual double getBackground();
101  virtual double getKsum();
103 
104  protected:
105  Eigen::MatrixXd _cMat;
106  Eigen::VectorXd _iVec;
107  Eigen::VectorXd _ivVec;
108 
110  double _background;
111  double _kSum;
112 
113  void _setKernel();
114  void _setKernelUncertainty();
115  };
116 
117 
118  template <typename InputT>
120  public:
122 
124  bool fitForBackground);
125  virtual ~MaskedKernelSolution() {};
126  virtual void buildOrig(lsst::afw::image::Image<InputT> const &templateImage,
127  lsst::afw::image::Image<InputT> const &scienceImage,
129  const &varianceEstimate,
131 
132  virtual void buildWithMask(lsst::afw::image::Image<InputT> const &templateImage,
133  lsst::afw::image::Image<InputT> const &scienceImage,
135  const &varianceEstimate,
137 
138  virtual void buildSingleMaskOrig(lsst::afw::image::Image<InputT> const &templateImage,
139  lsst::afw::image::Image<InputT> const &scienceImage,
141  const &varianceEstimate,
142  lsst::geom::Box2I maskBox);
143  };
144 
145 
146 
147  template <typename InputT>
149  public:
151 
153  bool fitForBackground,
154  Eigen::MatrixXd const& hMat,
156  );
158  void solve();
159  double getLambda() {return _lambda;}
160  double estimateRisk(double maxCond);
161 
162  /* Include additive term (_lambda * _hMat) in M matrix? */
163  Eigen::MatrixXd getM(bool includeHmat = true);
164 
165  private:
166  Eigen::MatrixXd const _hMat;
167  double _lambda;
169 
170  std::vector<double> _createLambdaSteps();
171  };
172 
173 
175  public:
177 
178  /* Creates a polynomial SpatialFunction */
180  lsst::afw::math::Kernel::SpatialFunctionPtr spatialKernelFunction,
183  );
184 
186 
187  void addConstraint(float xCenter, float yCenter,
188  Eigen::MatrixXd const& qMat,
189  Eigen::VectorXd const& wVec);
190 
191  void solve();
195 
196  private:
197  lsst::afw::math::Kernel::SpatialFunctionPtr _spatialKernelFunction;
198  bool _constantFirstTerm;
199 
202  double _kSum;
203 
205  int _nbases;
206  int _nkt;
207  int _nbt;
208  int _nt;
209 
210  void _setKernel();
211  void _setKernelUncertainty();
212  };
213 
214 }}} // end of namespace lsst::ip::diffim
215 
216 #endif
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
Class for storing generic metadata.
Definition: PropertySet.h:67
An integer coordinate rectangle.
Definition: Box.h:55
bool _fitForBackground
Background terms included in fit.
virtual double getConditionNumber(ConditionNumberType conditionType)
int _id
Unique ID for object.
Eigen::VectorXd _bVec
Derived least squares B vector.
std::shared_ptr< KernelSolution > Ptr
Eigen::VectorXd _aVec
Derived least squares solution matrix.
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
lsst::afw::math::Kernel::Pixel PixelT
Eigen::VectorXd const & getB()
Eigen::MatrixXd _mMat
Derived least squares M matrix.
static int _SolutionId
Unique identifier for solution.
Eigen::MatrixXd const & getM()
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > ImageT
virtual void buildWithMask(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::afw::image::Mask< lsst::afw::image::MaskPixel > const &pixelMask)
virtual void buildSingleMaskOrig(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::geom::Box2I maskBox)
MaskedKernelSolution(lsst::afw::math::KernelList const &basisList, bool fitForBackground)
std::shared_ptr< MaskedKernelSolution< InputT > > Ptr
virtual void buildOrig(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::afw::image::Mask< lsst::afw::image::MaskPixel > pixelMask)
std::shared_ptr< RegularizedKernelSolution< InputT > > Ptr
RegularizedKernelSolution(lsst::afw::math::KernelList const &basisList, bool fitForBackground, Eigen::MatrixXd const &hMat, lsst::daf::base::PropertySet const &ps)
std::pair< std::shared_ptr< lsst::afw::math::LinearCombinationKernel >, lsst::afw::math::Kernel::SpatialFunctionPtr > getSolutionPair()
std::shared_ptr< lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > > makeKernelImage(lsst::geom::Point2D const &pos)
SpatialKernelSolution(lsst::afw::math::KernelList const &basisList, lsst::afw::math::Kernel::SpatialFunctionPtr spatialKernelFunction, lsst::afw::math::Kernel::SpatialFunctionPtr background, lsst::daf::base::PropertySet const &ps)
void addConstraint(float xCenter, float yCenter, Eigen::MatrixXd const &qMat, Eigen::VectorXd const &wVec)
std::shared_ptr< SpatialKernelSolution > Ptr
double _background
Derived differential background estimate.
virtual std::pair< std::shared_ptr< lsst::afw::math::Kernel >, double > getSolutionPair()
void _setKernel()
Set kernel after solution.
virtual std::shared_ptr< lsst::afw::math::Kernel > getKernel()
Eigen::VectorXd _iVec
Vectorized I.
std::shared_ptr< lsst::afw::math::Kernel > _kernel
Derived single-object convolution kernel.
void _setKernelUncertainty()
Not implemented.
virtual std::shared_ptr< lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > > makeKernelImage()
Eigen::VectorXd _ivVec
Inverse variance.
std::shared_ptr< StaticKernelSolution< InputT > > Ptr
StaticKernelSolution(lsst::afw::math::KernelList const &basisList, bool fitForBackground)
virtual void build(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate)
T endl(T... args)
A base class for image defects.