lsst.afw  13.0-100-ge0459d59f+2
PhotoCalib.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2017 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #ifndef LSST_AFW_IMAGE_PHOTOCALIB_H
24 #define LSST_AFW_IMAGE_PHOTOCALIB_H
25 
34 #include "lsst/afw/geom/Point.h"
35 #include "lsst/afw/geom/Box.h"
36 #include "lsst/afw/table/Source.h"
38 
39 namespace lsst {
40 namespace afw {
41 namespace image {
42 
44 struct Measurement {
45  Measurement(double value, double err) : value(value), err(err) {}
46  double const value;
47  double const err;
48 };
49 
83 public:
84  // no move or copy
85  PhotoCalib(PhotoCalib const &) = delete;
86  PhotoCalib(PhotoCalib &&) = delete;
87  PhotoCalib &operator=(PhotoCalib const &) = delete;
88  PhotoCalib &operator=(PhotoCalib &&) = delete;
89 
94 
103  explicit PhotoCalib(double instFluxMag0, double instFluxMag0Err = 0,
104  afw::geom::Box2I const &bbox = afw::geom::Box2I())
105  : _instFluxMag0(instFluxMag0), _instFluxMag0Err(instFluxMag0Err), _isConstant(true) {
106  ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(1, 1));
107  coeffs[0][0] = instFluxMag0;
108  _zeroPoint = std::make_shared<afw::math::ChebyshevBoundedField>(
109  afw::math::ChebyshevBoundedField(bbox, coeffs));
110  }
111 
118  PhotoCalib(std::shared_ptr<afw::math::BoundedField> zeroPoint, double instFluxMag0Err = 0)
119  : _zeroPoint(zeroPoint),
120  _instFluxMag0(computeInstFluxMag0(zeroPoint)),
121  _instFluxMag0Err(instFluxMag0Err),
122  _isConstant(false) {}
123 
132  PhotoCalib(double instFluxMag0, double instFluxMag0Err,
133  std::shared_ptr<afw::math::BoundedField> zeroPoint, bool isConstant)
134  : _zeroPoint(zeroPoint),
135  _instFluxMag0(instFluxMag0),
136  _instFluxMag0Err(instFluxMag0Err),
137  _isConstant(isConstant) {}
138 
149  double instFluxToMaggies(double instFlux, afw::geom::Point<double, 2> const &point) const;
150 
152  double instFluxToMaggies(double instFlux) const;
153 
165  Measurement instFluxToMaggies(double instFlux, double instFluxErr,
166  afw::geom::Point<double, 2> const &point) const;
167 
169  Measurement instFluxToMaggies(double instFlux, double instFluxErr) const;
170 
183  Measurement instFluxToMaggies(const afw::table::SourceRecord &sourceRecord,
184  std::string const &instFluxField) const;
185 
198  ndarray::Array<double, 2, 2> instFluxToMaggies(afw::table::SourceCatalog const &sourceCatalog,
199  std::string const &instFluxField) const;
200 
216  void instFluxToMaggies(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
217  std::string const &outField) const;
218 
229  double instFluxToMagnitude(double instFlux, afw::geom::Point<double, 2> const &point) const;
230 
232  double instFluxToMagnitude(double instFlux) const;
233 
245  Measurement instFluxToMagnitude(double instFlux, double instFluxErr,
246  afw::geom::Point<double, 2> const &point) const;
247 
249  Measurement instFluxToMagnitude(double instFlux, double instFluxErr) const;
250 
263  Measurement instFluxToMagnitude(afw::table::SourceRecord const &sourceRecord,
264  std::string const &instFluxField) const;
265 
278  ndarray::Array<double, 2, 2> instFluxToMagnitude(afw::table::SourceCatalog const &sourceCatalog,
279  std::string const &instFluxField) const;
280 
297  void instFluxToMagnitude(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
298  std::string const &outField) const;
299 
307  double magnitudeToInstFlux(double magnitude) const;
308 
319  double getInstFluxMag0() const { return _instFluxMag0; }
320 
331  double getInstFluxMag0Err() const { return _instFluxMag0Err; }
332 
343  std::shared_ptr<afw::math::BoundedField> computeScaledZeroPoint() const;
344 
364  std::shared_ptr<afw::math::BoundedField> computeScalingTo(std::shared_ptr<PhotoCalib> other) const;
365 
367  bool operator==(PhotoCalib const &rhs) const;
368 
370  bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
371 
372  bool isPersistable() const { return true; }
373 
374  friend std::ostream &operator<<(std::ostream &os, PhotoCalib const &photoCalib);
375 
376 protected:
377  virtual std::string getPersistenceName() const;
378 
379  virtual void write(OutputArchiveHandle &handle) const;
380 
381 private:
382  std::shared_ptr<afw::math::BoundedField> _zeroPoint;
383 
384  // The "mean" zero point, defined as the geometric mean of _zeroPoint evaluated over _zeroPoint's bbox.
385  // Computed on instantiation as a convinience.
386  // Also, the actual zeroPoint for a spatially-constant calibration.
387  double _instFluxMag0;
388 
389  // The standard deviation of this PhotoCalib.
390  double _instFluxMag0Err;
391 
392  // Is this spatially-constant? Used to short-circuit getting centroids.
393  bool _isConstant;
394 
396  double computeInstFluxMag0(std::shared_ptr<afw::math::BoundedField> zeroPoint) const;
397 
399  void instFluxToMaggiesArray(afw::table::SourceCatalog const &sourceCatalog,
400  std::string const &instFluxField, ndarray::Array<double, 2, 2> result) const;
401  void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
402  std::string const &instFluxField,
403  ndarray::Array<double, 2, 2> result) const;
404 };
405 }
406 }
407 }
408 
409 #endif // LSST_AFW_IMAGE_PHOTOCALIB_H
double getInstFluxMag0Err() const
Get the mean instFlux/magnitude zero point error.
Definition: PhotoCalib.h:331
An object passed to Persistable::write to allow it to persist itself.
PhotoCalib(double instFluxMag0, double instFluxMag0Err, std::shared_ptr< afw::math::BoundedField > zeroPoint, bool isConstant)
Create a calibration with a pre-computed mean.
Definition: PhotoCalib.h:132
The photometric calibration of an exposure.
Definition: PhotoCalib.h:82
table::Key< table::Flag > isConstant
Definition: PhotoCalib.cc:216
bool operator!=(PhotoCalib const &rhs) const
Two PhotoCalibs are equal if their component bounded fields and instFluxMag0Err are equal...
Definition: PhotoCalib.h:370
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
A value and its error.
Definition: PhotoCalib.h:44
An integer coordinate rectangle.
Definition: Box.h:55
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:73
Measurement(double value, double err)
Definition: PhotoCalib.h:45
A base class for image defects.
Definition: cameraGeom.dox:3
PhotoCalib()
Create a empty, zeroed calibration.
Definition: PhotoCalib.h:93
PhotoCalib(double instFluxMag0, double instFluxMag0Err=0, afw::geom::Box2I const &bbox=afw::geom::Box2I())
Create a non-spatially-varying calibration.
Definition: PhotoCalib.h:103
PhotoCalib(std::shared_ptr< afw::math::BoundedField > zeroPoint, double instFluxMag0Err=0)
Create a spatially-varying calibration.
Definition: PhotoCalib.h:118
std::ostream & operator<<(std::ostream &os, PhotoCalib const &photoCalib)
Definition: PhotoCalib.cc:199
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: PhotoCalib.h:372
table::Key< double > instFluxMag0Err
Definition: PhotoCalib.cc:215
A BoundedField based on 2-d Chebyshev polynomials of the first kind.
Record class that contains measurements made on a single exposure.
Definition: Source.h:80
double getInstFluxMag0() const
Get the mean instFlux/magnitude zero point.
Definition: PhotoCalib.h:319
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:173
table::Key< double > instFluxMag0
Definition: PhotoCalib.cc:214