lsst.jointcal  16.0-20-g17d57d5+5
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 value,
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 value) const override { return value * getValue(); }
127 
129  double transformError(double x, double y, double value, double valueErr) const override {
130  return getValue() * valueErr;
131  }
132 
135  return std::make_shared<FluxTransfoSpatiallyInvariant>(getValue());
136  }
137 
139  void computeParameterDerivatives(double x, double y, double value,
140  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
141  // the derivative of a spatially constant transfo w.r.t. that value is just the value.
142  derivatives[0] = value;
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 value,
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:
204  PhotometryTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox, bool identity);
205 
215  PhotometryTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients,
216  afw::geom::Box2D const &bbox);
217 
219  double transformError(double x, double y, double value, double valueErr) const override { return 0; }
220 
222  void dump(std::ostream &stream = std::cout) const override { stream << _coefficients; }
223 
225  int getNpar() const override { return _nParameters; }
226 
228  void offsetParams(Eigen::VectorXd const &delta) override;
229 
231  ndarray::Array<double, 2, 2> getCoefficients() const { return ndarray::copy(_coefficients); }
232 
234  Eigen::VectorXd getParameters() const override;
235 
236  ndarray::Size getOrder() const { return _order; }
237 
238  afw::geom::Box2D getBBox() const { return _bbox; }
239 
240  double mean() const;
241 
242 protected:
246  double computeChebyshev(double x, double y) const;
247 
252  void computeChebyshevDerivatives(double x, double y, Eigen::Ref<Eigen::VectorXd> derivatives) const;
253 
254 private:
255  afw::geom::Box2D _bbox; // the domain of this function
256  afw::geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
257 
258  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
259  ndarray::Size _order;
260  ndarray::Size _nParameters;
261 
262  // Compute the integral of this function over its bounding-box.
263  double integrate() const;
264 };
265 
270 public:
271  FluxTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox)
272  : PhotometryTransfoChebyshev(order, bbox, true) {}
273 
274  FluxTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients, afw::geom::Box2D const &bbox)
275  : PhotometryTransfoChebyshev(coefficients, bbox) {}
276 
278  double transform(double x, double y, double value) const override {
279  return value * computeChebyshev(x, y);
280  }
281 
283  void computeParameterDerivatives(double x, double y, double value,
284  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
285  computeChebyshevDerivatives(x, y, derivatives);
286  derivatives *= value;
287  }
288 
291  return std::make_shared<FluxTransfoChebyshev>(getCoefficients(), getBBox());
292  }
293 };
294 
299 public:
300  MagnitudeTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox)
301  : PhotometryTransfoChebyshev(order, bbox, false) {}
302 
303  MagnitudeTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients, afw::geom::Box2D const &bbox)
304  : PhotometryTransfoChebyshev(coefficients, bbox) {}
305 
307  double transform(double x, double y, double value) const override {
308  return value + computeChebyshev(x, y);
309  }
310 
312  void computeParameterDerivatives(double x, double y, double value,
313  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
314  // The derivatives here are independent of value
315  computeChebyshevDerivatives(x, y, derivatives);
316  }
317 
320  return std::make_shared<FluxTransfoChebyshev>(getCoefficients(), getBBox());
321  }
322 };
323 
324 } // namespace jointcal
325 } // namespace lsst
326 
327 #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.
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).
double transform(double x, double y, double value) const override
Return the transform of value at (x,y).
ndarray::Array< double, 2, 2 > getCoefficients() const
Get a copy of the coefficients of the polynomials, as a 2d array (NOTE: layout is [y][x]) ...
table::Box2IKey bbox
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).
nth-order 2d Chebyshev photometry transfo, times the input flux.
Photometric offset independent of position, defined as (fluxMag0)^-1.
MagnitudeTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox)
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.
std::shared_ptr< PhotometryTransfo > clone() const override
return a copy (allocated by new) of the transformation.
double transform(double x, double y, double value) const override
Return the transform of value at (x,y).
void computeParameterDerivatives(double x, double y, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
Class for a simple mapping implementing a generic Gtransfo.
friend std::ostream & operator<<(std::ostream &s, PhotometryTransfo const &transfo)
virtual int getNpar() const =0
Return the number of parameters (used to compute chisq)
void computeParameterDerivatives(double x, double y, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
FluxTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox)
double transformError(double x, double y, double value, double valueErr) const override
Return the transformed valueErr at Point(x,y).
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).
FluxTransfoChebyshev(ndarray::Array< double, 2, 2 > const &coefficients, afw::geom::Box2D const &bbox)
MagnitudeTransfoChebyshev(ndarray::Array< double, 2, 2 > const &coefficients, afw::geom::Box2D const &bbox)
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
void dump(std::ostream &stream=std::cout) const override
dumps the transfo coefficients to stream.
double transform(double x, double y, double value) const override
Return the transform of value at (x,y).
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.
virtual void computeParameterDerivatives(double x, double y, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const =0
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.
double transformError(double x, double y, double value, double valueErr) const override
Return the transformed valueErr at Point(x,y).
void computeParameterDerivatives(double x, double y, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
T setprecision(T... args)
nth-order 2d Chebyshev photometry transfo, plus the input flux.
void computeParameterDerivatives(double x, double y, double value, Eigen::Ref< Eigen::VectorXd > derivatives) const override
Compute the derivatives with respect to the parameters (i.e.
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
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)