LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
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 };
106 
111 public:
112  explicit PhotometryTransformSpatiallyInvariant(double value) : _value(value) {}
113 
115  void print(std::ostream &out) const override {
116  out << "PhotometryTransformSpatiallyInvariant: " << std::setprecision(10) << _value;
117  }
118 
120  std::size_t getNpar() const override { return 1; }
121 
123  void offsetParams(Eigen::VectorXd const &delta) override { _value -= delta[0]; };
124 
126  Eigen::VectorXd getParameters() const override {
127  Eigen::VectorXd parameters(1);
128  parameters[0] = _value;
129  return parameters;
130  }
131 
132 protected:
133  double getValue() const { return _value; }
134 
135 private:
137  double _value;
138 };
139 
147 public:
148  explicit FluxTransformSpatiallyInvariant(double value = 1)
150 
152  double transform(double x, double y, double value) const override { return value * getValue(); }
153 
155  double transformError(double x, double y, double value, double valueErr) const override {
156  return getValue() * valueErr;
157  }
158 
161  return std::make_shared<FluxTransformSpatiallyInvariant>(getValue());
162  }
163 
165  void computeParameterDerivatives(double x, double y, double value,
166  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
167  // the derivative of a spatially constant transform w.r.t. that value is just the value.
168  derivatives[0] = value;
169  }
170 };
171 
179 public:
180  explicit MagnitudeTransformSpatiallyInvariant(double value = 0)
182 
184  double transform(double x, double y, double mag) const override { return mag + getValue(); }
185 
187  double transformError(double x, double y, double value, double valueErr) const override {
188  return valueErr;
189  }
190 
193  return std::make_shared<MagnitudeTransformSpatiallyInvariant>(getValue());
194  }
195 
197  void computeParameterDerivatives(double x, double y, double value,
198  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
199  // the derivative of a spatially constant transform w.r.t. that value is 1.
200  derivatives[0] = 1;
201  }
202 };
203 
222 public:
230  PhotometryTransformChebyshev(size_t order, geom::Box2D const &bbox, bool identity);
231 
241  PhotometryTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox);
242 
244  double transformError(double x, double y, double value, double valueErr) const override { return 0; }
245 
247  void print(std::ostream &out) const override { out << "PhotometryTransformChebyshev: " << _coefficients; }
248 
250  std::size_t getNpar() const override { return _nParameters; }
251 
253  void offsetParams(Eigen::VectorXd const &delta) override;
254 
256  ndarray::Array<double, 2, 2> getCoefficients() const { return ndarray::copy(_coefficients); }
257 
259  Eigen::VectorXd getParameters() const override;
260 
261  ndarray::Size getOrder() const { return _order; }
262 
263  geom::Box2D getBBox() const { return _bbox; }
264 
266  double mean(geom::Box2D const &bbox) const;
268  double mean() const;
269 
270  // Compute the integral of this function over a bounding-box (default to our bbox).
271  double integrate(geom::Box2D const &bbox) const;
273  double integrate() const;
274 
275 protected:
279  double computeChebyshev(double x, double y) const;
280 
285  void computeChebyshevDerivatives(double x, double y, Eigen::Ref<Eigen::VectorXd> derivatives) const;
286 
287 private:
288  geom::Box2D _bbox; // the domain of this function
289  geom::AffineTransform _toChebyshevRange; // maps points from the bbox to [-1,1]x[-1,1]
290 
291  ndarray::Array<double, 2, 2> _coefficients; // shape=(order+1, order+1)
292  ndarray::Size _order;
293  ndarray::Size _nParameters;
294 
296  double oneIntegral(double x, double y) const;
297 };
298 
303 public:
305  : PhotometryTransformChebyshev(order, bbox, true) {}
306 
307  FluxTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox)
309 
311  double transform(double x, double y, double value) const override {
312  return value * computeChebyshev(x, y);
313  }
314 
316  void computeParameterDerivatives(double x, double y, double value,
317  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
318  computeChebyshevDerivatives(x, y, derivatives);
319  derivatives *= value;
320  }
321 
324  return std::make_shared<FluxTransformChebyshev>(getCoefficients(), getBBox());
325  }
326 };
327 
332 public:
334  : PhotometryTransformChebyshev(order, bbox, false) {}
335 
336  MagnitudeTransformChebyshev(ndarray::Array<double, 2, 2> const &coefficients, geom::Box2D const &bbox)
338 
340  double transform(double x, double y, double value) const override {
341  return value + computeChebyshev(x, y);
342  }
343 
345  void computeParameterDerivatives(double x, double y, double value,
346  Eigen::Ref<Eigen::VectorXd> derivatives) const override {
347  // The derivatives here are independent of value
348  computeChebyshevDerivatives(x, y, derivatives);
349  }
350 
353  return std::make_shared<FluxTransformChebyshev>(getCoefficients(), getBBox());
354  }
355 };
356 
357 } // namespace jointcal
358 } // namespace lsst
359 
360 #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:49
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)
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:36
double x
coordinate
Definition: Point.h:41
A base class for image defects.
T setprecision(T... args)