LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
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/geom/Box.h"
37 #include "lsst/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 print(std::ostream &out) const = 0;
70 
72  transform.print(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 
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  virtual ~PhotometryTransform() = default;
106 };
107 
112 public:
113  explicit PhotometryTransformSpatiallyInvariant(double value) : _value(value) {}
114 
116  void print(std::ostream &out) const override {
117  out << "PhotometryTransformSpatiallyInvariant: " << std::setprecision(10) << _value;
118  }
119 
121  std::size_t getNpar() const override { return 1; }
122 
124  void offsetParams(Eigen::VectorXd const &delta) override { _value -= delta[0]; };
125 
127  Eigen::VectorXd getParameters() const override {
128  Eigen::VectorXd parameters(1);
129  parameters[0] = _value;
130  return parameters;
131  }
132 
133 protected:
134  double getValue() const { return _value; }
135 
136 private:
138  double _value;
139 };
140 
148 public:
149  explicit FluxTransformSpatiallyInvariant(double value = 1)
151 
153  double transform(double x, double y, double value) const override { return value * getValue(); }
154 
156  double transformError(double x, double y, double value, double valueErr) const override {
157  return getValue() * valueErr;
158  }
159 
162  return std::make_shared<FluxTransformSpatiallyInvariant>(getValue());
163  }
164 
166  void computeParameterDerivatives(double x, double y, double value,
167  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
168  // the derivative of a spatially constant transform w.r.t. that value is just the value.
169  derivatives[0] = value;
170  }
171 };
172 
180 public:
181  explicit MagnitudeTransformSpatiallyInvariant(double value = 0)
183 
185  double transform(double x, double y, double mag) const override { return mag + getValue(); }
186 
188  double transformError(double x, double y, double value, double valueErr) const override {
189  return valueErr;
190  }
191 
194  return std::make_shared<MagnitudeTransformSpatiallyInvariant>(getValue());
195  }
196 
198  void computeParameterDerivatives(double x, double y, double value,
199  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
200  // the derivative of a spatially constant transform w.r.t. that value is 1.
201  derivatives[0] = 1;
202  }
203 };
204 
223 public:
231  PhotometryTransformChebyshev(size_t order, geom::Box2D const &bbox, bool identity);
232 
242  PhotometryTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox);
243 
245  double transformError(double x, double y, double value, double valueErr) const override { return 0; }
246 
248  void print(std::ostream &out) const override { out << "PhotometryTransformChebyshev: " << _coefficients; }
249 
251  std::size_t getNpar() const override { return _nParameters; }
252 
254  void offsetParams(Eigen::VectorXd const &delta) override;
255 
257  ndarray::Array<double, 2, 2> getCoefficients() const { return ndarray::copy(_coefficients); }
258 
260  Eigen::VectorXd getParameters() const override;
261 
262  ndarray::Size getOrder() const { return _order; }
263 
264  geom::Box2D getBBox() const { return _bbox; }
265 
267  double mean(geom::Box2D const &bbox) const;
269  double mean() const;
270 
271  // Compute the integral of this function over a bounding-box (default to our bbox).
272  double integrate(geom::Box2D const &bbox) const;
274  double integrate() const;
275 
276 protected:
280  double computeChebyshev(double x, double y) const;
281 
286  void computeChebyshevDerivatives(double x, double y, Eigen::Ref<Eigen::VectorXd> derivatives) const;
287 
288 private:
289  geom::Box2D _bbox; // the domain of this function
290  geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
291 
292  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
293  ndarray::Size _order;
294  ndarray::Size _nParameters;
295 
297  double oneIntegral(double x, double y) const;
298 };
299 
304 public:
307 
308  FluxTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox)
310 
312  double transform(double x, double y, double value) const override {
313  return value * computeChebyshev(x, y);
314  }
315 
317  void computeParameterDerivatives(double x, double y, double value,
318  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
319  computeChebyshevDerivatives(x, y, derivatives);
320  derivatives *= value;
321  }
322 
325  return std::make_shared<FluxTransformChebyshev>(getCoefficients(), getBBox());
326  }
327 };
328 
333 public:
336 
337  MagnitudeTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox)
339 
341  double transform(double x, double y, double value) const override {
342  return value + computeChebyshev(x, y);
343  }
344 
346  void computeParameterDerivatives(double x, double y, double value,
347  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
348  // The derivatives here are independent of value
349  computeChebyshevDerivatives(x, y, derivatives);
350  }
351 
354  return std::make_shared<FluxTransformChebyshev>(getCoefficients(), getBBox());
355  }
356 };
357 
358 } // namespace jointcal
359 } // namespace lsst
360 
361 #endif // LSST_JOINTCAL_PHOTOMETRY_TRANSFORM_H
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
ndarray::Array< double const, 2, 2 > coefficients
double x
int y
Definition: SpanSet.cc:48
An affine coordinate transformation consisting of a linear transformation and an offset.
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
nth-order 2d Chebyshev photometry transform, times the input flux.
FluxTransformChebyshev(ndarray::Array< double, 2, 2 > const &coefficients, geom::Box2D const &bbox)
std::shared_ptr< PhotometryTransform > 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.
FluxTransformChebyshev(size_t order, geom::Box2D const &bbox)
Photometric offset independent of position, defined as (fluxMag0)^-1.
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).
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.
nth-order 2d Chebyshev photometry transform, plus the input flux.
double transform(double x, double y, double value) const override
Return the transform of value at (x,y).
MagnitudeTransformChebyshev(size_t order, geom::Box2D const &bbox)
MagnitudeTransformChebyshev(ndarray::Array< double, 2, 2 > const &coefficients, geom::Box2D const &bbox)
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.
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.
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 mag) const override
Return the transform of value at (x,y).
nth-order 2d Chebyshev photometry transform.
void offsetParams(Eigen::VectorXd const &delta) override
Offset the parameters by some (negative) amount during fitting.
std::size_t getNpar() const override
Return the number of parameters (used to compute chisq)
void print(std::ostream &out) const override
Print the transform coefficients to stream.
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])
Eigen::VectorXd getParameters() const override
Get a copy of the parameters of this model, in the same order as offsetParams.
PhotometryTransformChebyshev(size_t order, geom::Box2D const &bbox, bool identity)
Create a Chebyshev transform with terms up to order in (x*y).
void computeChebyshevDerivatives(double x, double y, Eigen::Ref< Eigen::VectorXd > derivatives) const
Set the derivatives of this polynomial at x,y.
double transformError(double x, double y, double value, double valueErr) const override
Return the transformed valueErr at Point(x,y).
double computeChebyshev(double x, double y) const
Return the value of this polynomial at x,y.
A photometric transform, defined in terms of the input flux or magnitude.
friend std::ostream & operator<<(std::ostream &s, PhotometryTransform const &transform)
virtual double transformError(double x, double y, double value, double valueErr) const =0
Return the transformed valueErr at Point(x,y).
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.
virtual std::shared_ptr< PhotometryTransform > clone() const =0
return a copy (allocated by new) of the transformation.
virtual double transform(double x, double y, double value) const =0
Return the transform of value at (x,y).
double transform(Point const &in, double value) const
Return the transformed value at Point(x,y).
virtual Eigen::VectorXd getParameters() const =0
Get a copy of the parameters of this model, in the same order as offsetParams.
virtual std::size_t getNpar() const =0
Return the number of parameters (used to compute chisq)
virtual ~PhotometryTransform()=default
double transformError(Point const &in, double value, double valueErr) const
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.
virtual void print(std::ostream &out) const =0
Print the transform coefficients to stream.
Photometry offset independent of position.
std::size_t getNpar() const override
Return the number of parameters (used to compute chisq)
void print(std::ostream &out) const override
Print the transform coefficients to stream.
Eigen::VectorXd getParameters() const override
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.
A point in a plane.
Definition: Point.h:37
double x
coordinate
Definition: Point.h:42
A base class for image defects.
T setprecision(T... args)
table::Key< int > order