lsst.jointcal  16.0-7-g6e35192+1
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 
30 public:
32  virtual double transform(double x, double y, double value) const = 0;
33 
35  double transform(Point const &in, double value) const { return transform(in.x, in.y, value); }
36 
38  virtual double transformError(double x, double y, double value, double valueErr) const = 0;
39 
41  double transformError(Point const &in, double value, double valueErr) const {
42  return transformError(in.x, in.y, value, valueErr);
43  }
44 
46  virtual void dump(std::ostream &stream = std::cout) const = 0;
47 
48  friend std::ostream &operator<<(std::ostream &s, PhotometryTransfo const &transfo) {
49  transfo.dump(s);
50  return s;
51  }
52 
54  virtual int getNpar() const = 0;
55 
64  virtual void offsetParams(Eigen::VectorXd const &delta) = 0;
65 
67  virtual std::shared_ptr<PhotometryTransfo> clone() const = 0;
68 
77  virtual void computeParameterDerivatives(double x, double y, double instFlux,
78  Eigen::Ref<Eigen::VectorXd> derivatives) const = 0;
79 
81  virtual Eigen::VectorXd getParameters() const = 0;
82 };
83 
88 public:
89  explicit PhotometryTransfoSpatiallyInvariant(double value) : _value(value) {}
90 
92  void dump(std::ostream &stream = std::cout) const override { stream << std::setprecision(10) << _value; }
93 
95  int getNpar() const override { return 1; }
96 
98  void offsetParams(Eigen::VectorXd const &delta) override { _value -= delta[0]; };
99 
101  Eigen::VectorXd getParameters() const override {
102  Eigen::VectorXd parameters(1);
103  parameters[0] = _value;
104  return parameters;
105  }
106 
107 protected:
108  double getValue() const { return _value; }
109 
110 private:
112  double _value;
113 };
114 
122 public:
124 
126  double transform(double x, double y, double instFlux) const override { return instFlux * getValue(); }
127 
129  double transformError(double x, double y, double flux, double fluxErr) const override {
130  return getValue() * fluxErr;
131  }
132 
135  return std::make_shared<FluxTransfoSpatiallyInvariant>(getValue());
136  }
137 
139  void computeParameterDerivatives(double x, double y, double instFlux,
140  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
141  // the derivative of a spatially constant transfo w.r.t. that value is just the instFlux.
142  derivatives[0] = instFlux;
143  }
144 };
145 
153 public:
154  explicit MagnitudeTransfoSpatiallyInvariant(double value = 0)
156 
158  double transform(double x, double y, double mag) const override { return mag + getValue(); }
159 
161  double transformError(double x, double y, double value, double valueErr) const override {
162  return valueErr;
163  }
164 
167  return std::make_shared<MagnitudeTransfoSpatiallyInvariant>(getValue());
168  }
169 
171  void computeParameterDerivatives(double x, double y, double mag,
172  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
173  // the derivative of a spatially constant transfo w.r.t. that value is 1.
174  derivatives[0] = 1;
175  }
176 };
177 
196 public:
203  PhotometryTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox);
204 
213  PhotometryTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients,
214  afw::geom::Box2D const &bbox);
215 
217  double transform(double x, double y, double instFlux) const override;
218 
220  double transformError(double x, double y, double value, double valueErr) const override { return 0; }
221 
223  void dump(std::ostream &stream = std::cout) const override { stream << _coefficients; }
224 
226  int getNpar() const override { return _nParameters; }
227 
229  void offsetParams(Eigen::VectorXd const &delta) override;
230 
233  return std::make_shared<PhotometryTransfoChebyshev>(ndarray::copy(_coefficients), _bbox);
234  }
235 
237  void computeParameterDerivatives(double x, double y, double instFlux,
238  Eigen::Ref<Eigen::VectorXd> derivatives) const override;
239 
241  ndarray::Array<double, 2, 2> getCoefficients() { return ndarray::copy(_coefficients); }
242 
244  Eigen::VectorXd getParameters() const override;
245 
246  ndarray::Size getOrder() const { return _order; }
247 
248  afw::geom::Box2D getBBox() const { return _bbox; }
249 
250  double mean() const;
251 
252 private:
253  afw::geom::Box2D _bbox; // the domain of this function
254  afw::geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
255 
256  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
257  ndarray::Size _order;
258  ndarray::Size _nParameters;
259 
260  // Compute the integral of this function over its bounding-box.
261  double integrate() const;
262 };
263 
264 } // namespace jointcal
265 } // namespace lsst
266 
267 #endif // LSST_JOINTCAL_PHOTOMETRY_TRANSFO_H
Photometric offset independent of position, defined as -2.5 * log(flux / fluxMag0).
double transform(double x, double y, double mag) const override
Return the transform of value at (x,y).
virtual Eigen::VectorXd getParameters() const =0
Get a copy of the parameters of this model, in the same order as offsetParams.
double transformError(double x, double y, double flux, double fluxErr) const override
Return the transformed valueErr at Point(x,y).
A point in a plane.
Definition: Point.h:13
double transformError(double x, double y, double value, double valueErr) const override
Return the transformed valueErr at Point(x,y).
virtual void dump(std::ostream &stream=std::cout) const =0
dumps the transfo coefficients to stream.
virtual double transform(double x, double y, double value) const =0
Return the transform of value at (x,y).
Photometric offset independent of position, defined as (fluxMag0)^-1.
int getNpar() const override
Return the number of parameters (used to compute chisq)
double transformError(Point const &in, double value, double valueErr) const
Return the transformed valueErr at Point(x,y).
std::shared_ptr< PhotometryTransfo > clone() const override
return a copy (allocated by new) of the transformation.
double x
coordinate
Definition: Point.h:18
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.
double transform(double x, double y, double instFlux) const override
Return the transform of value at (x,y).
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 =0
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.
double transform(Point const &in, double value) const
Return the transformed value at Point(x,y).
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.
Eigen::VectorXd getParameters() const override
Get a copy of the parameters of this model, in the same order as offsetParams.
Photometry offset independent of position.
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.
std::shared_ptr< PhotometryTransfo > clone() const override
return a copy (allocated by new) of the transformation.
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by some (negative) amount during fitting.
double transformError(double x, double y, double value, double valueErr) const override
Return the transformed valueErr at Point(x,y).
T setprecision(T... args)
A photometric transform, defined in terms of the input flux or magnitude.
STL class.
virtual double transformError(double x, double y, double value, double valueErr) const =0
Return the transformed valueErr at Point(x,y).
int y
void computeParameterDerivatives(double x, double y, double mag, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
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)