lsst.jointcal  16.0-18-gdf247dd+7
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 
214  PhotometryTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients,
215  afw::geom::Box2D const &bbox);
216 
218  double transformError(double x, double y, double value, double valueErr) const override { return 0; }
219 
221  void dump(std::ostream &stream = std::cout) const override { stream << _coefficients; }
222 
224  int getNpar() const override { return _nParameters; }
225 
227  void offsetParams(Eigen::VectorXd const &delta) override;
228 
230  ndarray::Array<double, 2, 2> getCoefficients() const { return ndarray::copy(_coefficients); }
231 
233  Eigen::VectorXd getParameters() const override;
234 
235  ndarray::Size getOrder() const { return _order; }
236 
237  afw::geom::Box2D getBBox() const { return _bbox; }
238 
239  double mean() const;
240 
241 protected:
245  double computeChebyshev(double x, double y) const;
246 
251  void computeChebyshevDerivatives(double x, double y, Eigen::Ref<Eigen::VectorXd> derivatives) const;
252 
253 private:
254  afw::geom::Box2D _bbox; // the domain of this function
255  afw::geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
256 
257  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
258  ndarray::Size _order;
259  ndarray::Size _nParameters;
260 
261  // Compute the integral of this function over its bounding-box.
262  double integrate() const;
263 };
264 
269 public:
270  FluxTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox)
271  : PhotometryTransfoChebyshev(order, bbox, true) {}
272 
273  FluxTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients, afw::geom::Box2D const &bbox)
274  : PhotometryTransfoChebyshev(coefficients, bbox) {}
275 
277  double transform(double x, double y, double value) const override {
278  return value * computeChebyshev(x, y);
279  }
280 
282  void computeParameterDerivatives(double x, double y, double value,
283  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
284  computeChebyshevDerivatives(x, y, derivatives);
285  derivatives *= value;
286  }
287 
290  return std::make_shared<FluxTransfoChebyshev>(getCoefficients(), getBBox());
291  }
292 };
293 
295 public:
296  MagnitudeTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox)
297  : PhotometryTransfoChebyshev(order, bbox, false) {}
298 
299  MagnitudeTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients, afw::geom::Box2D const &bbox)
300  : PhotometryTransfoChebyshev(coefficients, bbox) {}
301 
303  double transform(double x, double y, double value) const override {
304  return value + computeChebyshev(x, y);
305  }
306 
308  void computeParameterDerivatives(double x, double y, double value,
309  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
310  // The derivatives here are independent of value
311  computeChebyshevDerivatives(x, y, derivatives);
312  }
313 
316  return std::make_shared<FluxTransfoChebyshev>(getCoefficients(), getBBox());
317  }
318 };
319 
320 } // namespace jointcal
321 } // namespace lsst
322 
323 #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)
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)