LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
PhotometryTransform.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_TRANSFORM_H
26 #define LSST_JOINTCAL_PHOTOMETRY_TRANSFORM_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  transform.dump(s);
73  return s;
74  }
75 
77  virtual std::size_t getNpar() const = 0;
78 
87  virtual void offsetParams(Eigen::VectorXd const &delta) = 0;
88 
90  virtual std::shared_ptr<PhotometryTransform> 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 PhotometryTransformSpatiallyInvariant(double value) : _value(value) {}
113 
115  void dump(std::ostream &stream = std::cout) const override { stream << std::setprecision(10) << _value; }
116 
118  std::size_t 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:
146  explicit FluxTransformSpatiallyInvariant(double value = 1)
148 
150  double transform(double x, double y, double value) const override { return value * getValue(); }
151 
153  double transformError(double x, double y, double value, double valueErr) const override {
154  return getValue() * valueErr;
155  }
156 
159  return std::make_shared<FluxTransformSpatiallyInvariant>(getValue());
160  }
161 
163  void computeParameterDerivatives(double x, double y, double value,
164  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
165  // the derivative of a spatially constant transform w.r.t. that value is just the value.
166  derivatives[0] = value;
167  }
168 };
169 
177 public:
178  explicit MagnitudeTransformSpatiallyInvariant(double value = 0)
180 
182  double transform(double x, double y, double mag) const override { return mag + getValue(); }
183 
185  double transformError(double x, double y, double value, double valueErr) const override {
186  return valueErr;
187  }
188 
191  return std::make_shared<MagnitudeTransformSpatiallyInvariant>(getValue());
192  }
193 
195  void computeParameterDerivatives(double x, double y, double value,
196  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
197  // the derivative of a spatially constant transform w.r.t. that value is 1.
198  derivatives[0] = 1;
199  }
200 };
201 
220 public:
228  PhotometryTransformChebyshev(size_t order, geom::Box2D const &bbox, bool identity);
229 
239  PhotometryTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, 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  std::size_t 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  geom::Box2D getBBox() const { return _bbox; }
262 
264  double mean(geom::Box2D const &bbox) const;
266  double mean() const;
267 
268  // Compute the integral of this function over a bounding-box (default to our bbox).
269  double integrate(geom::Box2D const &bbox) const;
271  double integrate() const;
272 
273 protected:
277  double computeChebyshev(double x, double y) const;
278 
283  void computeChebyshevDerivatives(double x, double y, Eigen::Ref<Eigen::VectorXd> derivatives) const;
284 
285 private:
286  geom::Box2D _bbox; // the domain of this function
287  geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
288 
289  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
290  ndarray::Size _order;
291  ndarray::Size _nParameters;
292 
294  double oneIntegral(double x, double y) const;
295 };
296 
301 public:
303  : PhotometryTransformChebyshev(order, bbox, true) {}
304 
305  FluxTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox)
306  : PhotometryTransformChebyshev(coefficients, bbox) {}
307 
309  double transform(double x, double y, double value) const override {
310  return value * computeChebyshev(x, y);
311  }
312 
314  void computeParameterDerivatives(double x, double y, double value,
315  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
316  computeChebyshevDerivatives(x, y, derivatives);
317  derivatives *= value;
318  }
319 
322  return std::make_shared<FluxTransformChebyshev>(getCoefficients(), getBBox());
323  }
324 };
325 
330 public:
332  : PhotometryTransformChebyshev(order, bbox, false) {}
333 
334  MagnitudeTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox)
335  : PhotometryTransformChebyshev(coefficients, bbox) {}
336 
338  double transform(double x, double y, double value) const override {
339  return value + computeChebyshev(x, y);
340  }
341 
343  void computeParameterDerivatives(double x, double y, double value,
344  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
345  // The derivatives here are independent of value
346  computeChebyshevDerivatives(x, y, derivatives);
347  }
348 
351  return std::make_shared<FluxTransformChebyshev>(getCoefficients(), getBBox());
352  }
353 };
354 
355 } // namespace jointcal
356 } // namespace lsst
357 
358 #endif // LSST_JOINTCAL_PHOTOMETRY_TRANSFORM_H
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
std::shared_ptr< PhotometryTransform > 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).
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]) ...
void dump(std::ostream &stream=std::cout) const override
dumps the transform coefficients to stream.
virtual Eigen::VectorXd getParameters() const =0
Get a copy of the parameters of this model, in the same order as offsetParams.
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by some (negative) amount during fitting.
MagnitudeTransformChebyshev(size_t order, geom::Box2D const &bbox)
A point in a plane.
Definition: Point.h:36
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
std::shared_ptr< PhotometryTransform > clone() const override
return a copy (allocated by new) of the transformation.
An affine coordinate transformation consisting of a linear transformation and an offset.
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.
double transform(double x, double y, double value) const override
Return the transform of value at (x,y).
virtual std::shared_ptr< PhotometryTransform > clone() const =0
return a copy (allocated by new) of the transformation.
Photometric offset independent of position, defined as (fluxMag0)^-1.
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.
friend std::ostream & operator<<(std::ostream &s, PhotometryTransform const &transform)
int y
Definition: SpanSet.cc:49
Photometry offset independent of position.
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.
nth-order 2d Chebyshev photometry transform, times the input flux.
A photometric transform, defined in terms of the input flux or magnitude.
double x
coordinate
Definition: Point.h:41
nth-order 2d Chebyshev photometry transform, plus the input flux.
double transform(double x, double y, double mag) const override
Return the transform of value at (x,y).
Eigen::VectorXd getParameters() const override
Get a copy of the parameters of this model, in the same order as offsetParams.
MagnitudeTransformChebyshev(ndarray::Array< double, 2, 2 > const &coefficients, geom::Box2D const &bbox)
A base class for image defects.
double transform(Point const &in, double value) const
Return the transformed value at Point(x,y).
std::size_t getNpar() const override
Return the number of parameters (used to compute chisq)
void dump(std::ostream &stream=std::cout) const override
dumps the transform coefficients to stream.
double transformError(double x, double y, double value, double valueErr) const override
Return the transformed valueErr at Point(x,y).
double transformError(Point const &in, double value, double valueErr) const
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).
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).
virtual double transformError(double x, double y, double value, double valueErr) const =0
Return the transformed valueErr at Point(x,y).
FluxTransformChebyshev(ndarray::Array< double, 2, 2 > const &coefficients, geom::Box2D const &bbox)
double x
FluxTransformChebyshev(size_t order, geom::Box2D const &bbox)
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.
std::shared_ptr< PhotometryTransform > clone() const override
return a copy (allocated by new) of the transformation.
virtual void offsetParams(Eigen::VectorXd const &delta)=0
Offset the parameters by some (negative) amount during fitting.
virtual void dump(std::ostream &stream=std::cout) const =0
dumps the transform coefficients to stream.
virtual std::size_t getNpar() const =0
Return the number of parameters (used to compute chisq)
std::size_t getNpar() const override
Return the number of parameters (used to compute chisq)
virtual double transform(double x, double y, double value) const =0
Return the transform of value at (x,y).
nth-order 2d Chebyshev photometry transform.
Photometric offset independent of position, defined as -2.5 * log(flux / fluxMag0).
std::shared_ptr< PhotometryTransform > clone() const override
return a copy (allocated by new) of the transformation.
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)
STL class.
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
ndarray::Array< double const, 2, 2 > coefficients