lsst.jointcal  15.0-11-gda8ddd7
PhotometryTransfo.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 #ifndef LSST_JOINTCAL_PHOTOMETRY_TRANSFO_H
3 #define LSST_JOINTCAL_PHOTOMETRY_TRANSFO_H
4 
5 #include <iostream>
6 #include <sstream>
7 #include <memory>
8 
9 #include "Eigen/Core"
10 #include "ndarray.h"
11 
13 #include "lsst/afw/geom/Box.h"
14 #include "lsst/afw/geom/Point.h"
15 #include "lsst/jointcal/Point.h"
16 
17 namespace lsst {
18 namespace jointcal {
19 
20 class Point;
21 
22 class PhotometryTransfoSpatiallyInvariant;
23 
24 /*
25  * A photometric transform, defined as a scalar multiple of the input flux.
26  *
27  * Unit agnostic: a higher level Model must keep track of the units going into and out of of its Transfos.
28  *
29  * inputFlux * transfo(x,y) -> correctedFlux
30  *
31  * @seealso lsst::afw::image::PhotoCalib
32  */
34 public:
36  virtual double transform(double x, double y, double instFlux) const = 0;
37 
39  double transform(Point const &in, double instFlux) const { return transform(in.x, in.y, instFlux); }
40 
42  virtual void dump(std::ostream &stream = std::cout) const = 0;
43 
44  friend std::ostream &operator<<(std::ostream &s, PhotometryTransfo const &transfo) {
45  transfo.dump(s);
46  return s;
47  }
48 
50  virtual int getNpar() const { return 0; }
51 
60  virtual void offsetParams(Eigen::VectorXd const &delta) = 0;
61 
63  virtual std::shared_ptr<PhotometryTransfo> clone() const = 0;
64 
73  virtual void computeParameterDerivatives(double x, double y, double instFlux,
74  Eigen::Ref<Eigen::VectorXd> derivatives) const = 0;
75 
77  virtual Eigen::VectorXd getParameters() const = 0;
78 };
79 
80 /*
81  * Photometric offset independent of position, defined as (fluxMag0)^-1.
82  *
83  * initialCalibFlux * SpatiallyInvariantTransfo -> correctedFlux
84  *
85  */
87 public:
88  PhotometryTransfoSpatiallyInvariant(double value = 1) : _value(value) {}
89 
91  double transform(double x, double y, double instFlux) const override { return instFlux * _value; }
92 
94  void dump(std::ostream &stream = std::cout) const override { stream << _value; }
95 
97  int getNpar() const override { return 1; }
98 
100  void offsetParams(Eigen::VectorXd const &delta) override { _value -= delta[0]; };
101 
104  return std::make_shared<PhotometryTransfoSpatiallyInvariant>(_value);
105  }
106 
108  void computeParameterDerivatives(double x, double y, double instFlux,
109  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
110  // the derivative of a spatially constant transfo w.r.t. that value is just the instFlux.
111  derivatives[0] = instFlux;
112  }
113 
115  Eigen::VectorXd getParameters() const override {
116  Eigen::VectorXd parameters(1);
117  parameters[0] = _value;
118  return parameters;
119  }
120 
121 protected:
122  void setValue(double value) { _value = value; }
123 
124  friend class PhotometryTransfo;
125 
126 private:
128  double _value;
129 };
130 
149 public:
156  PhotometryTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox);
157 
166  PhotometryTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients,
167  afw::geom::Box2D const &bbox);
168 
170  double transform(double x, double y, double instFlux) const override;
171 
173  void dump(std::ostream &stream = std::cout) const override { stream << _coefficients; }
174 
176  int getNpar() const override { return _nParameters; }
177 
179  void offsetParams(Eigen::VectorXd const &delta) override;
180 
183  return std::make_shared<PhotometryTransfoChebyshev>(ndarray::copy(_coefficients), _bbox);
184  }
185 
187  void computeParameterDerivatives(double x, double y, double instFlux,
188  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
189 
191  ndarray::Array<double, 2, 2> getCoefficients() { return ndarray::copy(_coefficients); }
192 
194  Eigen::VectorXd getParameters() const override;
195 
196  ndarray::Size getOrder() const { return _order; }
197 
198  afw::geom::Box2D getBBox() const { return _bbox; }
199 
200  // Compute the mean of this function over its bounding-box.
201  double mean() const;
202 
203 private:
204  afw::geom::Box2D _bbox; // the domain of this function
205  afw::geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
206 
207  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
208  ndarray::Size _order;
209  ndarray::Size _nParameters;
210 
211  // Compute the integral of this function over its bounding-box.
212  double integrate() const;
213 };
214 
215 } // namespace jointcal
216 } // namespace lsst
217 
218 #endif // LSST_JOINTCAL_PHOTOMETRY_TRANSFO_H
virtual Eigen::VectorXd getParameters() const =0
Get a copy of the parameters of this model, in the same order as offsetParams.
A point in a plane.
Definition: Point.h:13
virtual void dump(std::ostream &stream=std::cout) const =0
dumps the transfo coefficients to stream.
int getNpar() const override
Return the number of parameters (used to compute chisq)
double transform(double x, double y, double instFlux) const override
Apply the transform to instFlux at (x,y), put result in flux.
double x
coordinate
Definition: Point.h:18
double transform(Point const &in, double instFlux) const
Return the transformed instFlux at (x,y).
virtual std::shared_ptr< PhotometryTransfo > clone() const =0
return a copy (allocated by new) of the transformation.
Class for a simple mapping implementing a generic Gtransfo.
friend std::ostream & operator<<(std::ostream &s, PhotometryTransfo const &transfo)
virtual void computeParameterDerivatives(double x, double y, double instFlux, Eigen::Ref< Eigen::VectorXd > derivatives) const =0
Compute the derivatives with respect to the parameters (i.e.
virtual int getNpar() const
Return the number of parameters (used to compute chisq)
ndarray::Array< double, 2, 2 > getCoefficients()
Get a copy of the coefficients of the polynomials, as a 2d array (NOTE: layout is [y][x]) ...
virtual void offsetParams(Eigen::VectorXd const &delta)=0
Offset the parameters by some (negative) amount during fitting.
void computeParameterDerivatives(double x, double y, double instFlux, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
std::shared_ptr< PhotometryTransfo > clone() const override
return a copy (allocated by new) of the transformation.
virtual double transform(double x, double y, double instFlux) const =0
Apply the transform to instFlux at (x,y), put result in flux.
Eigen::VectorXd getParameters() const override
Get a copy of the parameters of this model, in the same order as offsetParams.
double x
ndarray::Array< double const, 2, 2 > coefficients
std::shared_ptr< PhotometryTransfo > clone() const override
return a copy (allocated by new) of the transformation.
table::Box2IKey bbox
void dump(std::ostream &stream=std::cout) const override
dumps the transfo coefficients to stream.
nth-order 2d Chebyshev photometry transfo.
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by some (negative) amount during fitting.
STL class.
int y
UnaryFunctionT::result_type integrate(UnaryFunctionT func, typename UnaryFunctionT::argument_type const a, typename UnaryFunctionT::argument_type const b, double eps=1.0e-6)
void dump(std::ostream &stream=std::cout) const override
dumps the transfo coefficients to stream.
int getNpar() const override
Return the number of parameters (used to compute chisq)