LSSTApplications  16.0-10-g4f78f78+16,16.0-10-gc1446dd+42,16.0-11-g09ed895+1,16.0-13-g7649090,16.0-14-g0a28612+1,16.0-14-g6c7ed55+16,16.0-15-ga29f190+1,16.0-16-g89065d4+14,16.0-16-gd8e3590+16,16.0-16-ge6a35c8+6,16.0-17-g7e0e4ff+10,16.0-17-ga3d2e9f,16.0-19-gb830ed4e+16,16.0-2-g0febb12+21,16.0-2-g9d5294e+61,16.0-2-ga8830df+5,16.0-24-gc1c7f52+9,16.0-25-g07af9f2+1,16.0-3-ge00e371+21,16.0-36-g07840cb1,16.0-4-g18f3627+5,16.0-4-g5f3a788+20,16.0-4-ga3eb747+10,16.0-4-gabf74b7+16,16.0-4-gade8416+9,16.0-4-gb13d127+5,16.0-5-g6a53317+21,16.0-5-gb3f8a4b+74,16.0-5-gef99c9f+12,16.0-6-g9321be7+4,16.0-6-gcbc7b31+22,16.0-6-gf49912c+16,16.0-63-gae20905ba,16.0-7-gd2eeba5+31,16.0-8-g21fd5fe+16,16.0-8-g3a9f023+12,16.0-8-g4734f7a,16.0-9-g85d1a16+16,16.0-9-gf5c1f43,master-g07ce7b41a7,w.2018.48
LSSTDataManagementBasePackage
PhotometryTransfo.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * This file is part of jointcal.
4  *
5  * Developed for the LSST Data Management System.
6  * This product includes software developed by the LSST Project
7  * (https://www.lsst.org).
8  * See the COPYRIGHT file at the top-level directory of this distribution
9  * for details of code ownership.
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef LSST_JOINTCAL_PHOTOMETRY_TRANSFO_H
26 #define LSST_JOINTCAL_PHOTOMETRY_TRANSFO_H
27 
28 #include <iostream>
29 #include <sstream>
30 #include <memory>
31 
32 #include "Eigen/Core"
33 #include "ndarray.h"
34 
36 #include "lsst/afw/geom/Box.h"
37 #include "lsst/afw/geom/Point.h"
38 #include "lsst/jointcal/Point.h"
39 
40 namespace lsst {
41 namespace jointcal {
42 
43 class Point;
44 
53 public:
55  virtual double transform(double x, double y, double value) const = 0;
56 
58  double transform(Point const &in, double value) const { return transform(in.x, in.y, value); }
59 
61  virtual double transformError(double x, double y, double value, double valueErr) const = 0;
62 
64  double transformError(Point const &in, double value, double valueErr) const {
65  return transformError(in.x, in.y, value, valueErr);
66  }
67 
69  virtual void dump(std::ostream &stream = std::cout) const = 0;
70 
72  transfo.dump(s);
73  return s;
74  }
75 
77  virtual int getNpar() const = 0;
78 
87  virtual void offsetParams(Eigen::VectorXd const &delta) = 0;
88 
90  virtual std::shared_ptr<PhotometryTransfo> clone() const = 0;
91 
100  virtual void computeParameterDerivatives(double x, double y, double value,
101  Eigen::Ref<Eigen::VectorXd> derivatives) const = 0;
102 
104  virtual Eigen::VectorXd getParameters() const = 0;
105 };
106 
111 public:
112  explicit PhotometryTransfoSpatiallyInvariant(double value) : _value(value) {}
113 
115  void dump(std::ostream &stream = std::cout) const override { stream << std::setprecision(10) << _value; }
116 
118  int getNpar() const override { return 1; }
119 
121  void offsetParams(Eigen::VectorXd const &delta) override { _value -= delta[0]; };
122 
124  Eigen::VectorXd getParameters() const override {
125  Eigen::VectorXd parameters(1);
126  parameters[0] = _value;
127  return parameters;
128  }
129 
130 protected:
131  double getValue() const { return _value; }
132 
133 private:
135  double _value;
136 };
137 
145 public:
147 
149  double transform(double x, double y, double value) const override { return value * getValue(); }
150 
152  double transformError(double x, double y, double value, double valueErr) const override {
153  return getValue() * valueErr;
154  }
155 
158  return std::make_shared<FluxTransfoSpatiallyInvariant>(getValue());
159  }
160 
162  void computeParameterDerivatives(double x, double y, double value,
163  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
164  // the derivative of a spatially constant transfo w.r.t. that value is just the value.
165  derivatives[0] = value;
166  }
167 };
168 
176 public:
177  explicit MagnitudeTransfoSpatiallyInvariant(double value = 0)
179 
181  double transform(double x, double y, double mag) const override { return mag + getValue(); }
182 
184  double transformError(double x, double y, double value, double valueErr) const override {
185  return valueErr;
186  }
187 
190  return std::make_shared<MagnitudeTransfoSpatiallyInvariant>(getValue());
191  }
192 
194  void computeParameterDerivatives(double x, double y, double value,
195  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
196  // the derivative of a spatially constant transfo w.r.t. that value is 1.
197  derivatives[0] = 1;
198  }
199 };
200 
219 public:
227  PhotometryTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox, bool identity);
228 
238  PhotometryTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients,
239  afw::geom::Box2D const &bbox);
240 
242  double transformError(double x, double y, double value, double valueErr) const override { return 0; }
243 
245  void dump(std::ostream &stream = std::cout) const override { stream << _coefficients; }
246 
248  int getNpar() const override { return _nParameters; }
249 
251  void offsetParams(Eigen::VectorXd const &delta) override;
252 
254  ndarray::Array<double, 2, 2> getCoefficients() const { return ndarray::copy(_coefficients); }
255 
257  Eigen::VectorXd getParameters() const override;
258 
259  ndarray::Size getOrder() const { return _order; }
260 
261  afw::geom::Box2D getBBox() const { return _bbox; }
262 
263  double mean() const;
264 
265 protected:
269  double computeChebyshev(double x, double y) const;
270 
275  void computeChebyshevDerivatives(double x, double y, Eigen::Ref<Eigen::VectorXd> derivatives) const;
276 
277 private:
278  afw::geom::Box2D _bbox; // the domain of this function
279  afw::geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
280 
281  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
282  ndarray::Size _order;
283  ndarray::Size _nParameters;
284 
285  // Compute the integral of this function over its bounding-box.
286  double integrate() const;
287 };
288 
293 public:
295  : PhotometryTransfoChebyshev(order, bbox, true) {}
296 
297  FluxTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients, afw::geom::Box2D const &bbox)
298  : PhotometryTransfoChebyshev(coefficients, bbox) {}
299 
301  double transform(double x, double y, double value) const override {
302  return value * computeChebyshev(x, y);
303  }
304 
306  void computeParameterDerivatives(double x, double y, double value,
307  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
308  computeChebyshevDerivatives(x, y, derivatives);
309  derivatives *= value;
310  }
311 
314  return std::make_shared<FluxTransfoChebyshev>(getCoefficients(), getBBox());
315  }
316 };
317 
322 public:
324  : PhotometryTransfoChebyshev(order, bbox, false) {}
325 
326  MagnitudeTransfoChebyshev(ndarray::Array<double, 2, 2> const &coefficients, afw::geom::Box2D const &bbox)
327  : PhotometryTransfoChebyshev(coefficients, bbox) {}
328 
330  double transform(double x, double y, double value) const override {
331  return value + computeChebyshev(x, y);
332  }
333 
335  void computeParameterDerivatives(double x, double y, double value,
336  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
337  // The derivatives here are independent of value
338  computeChebyshevDerivatives(x, y, derivatives);
339  }
340 
343  return std::make_shared<FluxTransfoChebyshev>(getCoefficients(), getBBox());
344  }
345 };
346 
347 } // namespace jointcal
348 } // namespace lsst
349 
350 #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:36
double transformError(double x, double y, double value, double valueErr) const override
Return the transformed valueErr at Point(x,y).
A floating-point coordinate rectangle geometry.
Definition: Box.h:294
double transform(double x, double y, double value) const override
Return the transform of value at (x,y).
An affine coordinate transformation consisting of a linear transformation and an offset.
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]) ...
virtual void dump(std::ostream &stream=std::cout) const =0
dumps the transfo coefficients to stream.
int y
Definition: SpanSet.cc:49
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:41
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.
A base class for image defects.
Definition: cameraGeom.dox:3
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.
table::Box2IKey bbox
Definition: Detector.cc:166
solver_t * s
FluxTransfoChebyshev(size_t order, afw::geom::Box2D const &bbox)
double x
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.
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).
UnaryFunctionT::result_type integrate(UnaryFunctionT func, typename UnaryFunctionT::argument_type const a, typename UnaryFunctionT::argument_type const b, double eps=1.0e-6)
The 1D integrator.
Definition: Integrate.h:886
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)
ndarray::Array< double const, 2, 2 > coefficients