lsst.afw  14.0-52-g19103d347
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 
82 public:
83  // no move or copy
84  PhotoCalib(PhotoCalib const &) = delete;
85  PhotoCalib(PhotoCalib &&) = delete;
86  PhotoCalib &operator=(PhotoCalib const &) = delete;
87  PhotoCalib &operator=(PhotoCalib &&) = delete;
88 
89  virtual ~PhotoCalib() = default;
90 
95 
104  explicit PhotoCalib(double calibrationMean, double calibrationErr = 0,
106  : _calibrationMean(calibrationMean), _calibrationErr(calibrationErr), _isConstant(true) {
107  ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(1, 1));
108  coeffs[0][0] = calibrationMean;
109  _calibration = std::make_shared<afw::math::ChebyshevBoundedField>(
111  }
112 
120  : _calibration(calibration),
121  _calibrationMean(computeCalibrationMean(calibration)),
122  _calibrationErr(calibrationErr),
123  _isConstant(false) {}
124 
133  PhotoCalib(double calibrationMean, double calibrationErr,
135  : _calibration(calibration),
136  _calibrationMean(calibrationMean),
137  _calibrationErr(calibrationErr),
138  _isConstant(isConstant) {}
139 
150  double instFluxToMaggies(double instFlux, afw::geom::Point<double, 2> const &point) const;
151 
153  double instFluxToMaggies(double instFlux) const;
154 
166  Measurement instFluxToMaggies(double instFlux, double instFluxErr,
167  afw::geom::Point<double, 2> const &point) const;
168 
170  Measurement instFluxToMaggies(double instFlux, double instFluxErr) const;
171 
184  Measurement instFluxToMaggies(const afw::table::SourceRecord &sourceRecord,
185  std::string const &instFluxField) const;
186 
199  ndarray::Array<double, 2, 2> instFluxToMaggies(afw::table::SourceCatalog const &sourceCatalog,
200  std::string const &instFluxField) const;
201 
217  void instFluxToMaggies(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
218  std::string const &outField) const;
219 
230  double instFluxToMagnitude(double instFlux, afw::geom::Point<double, 2> const &point) const;
231 
233  double instFluxToMagnitude(double instFlux) const;
234 
246  Measurement instFluxToMagnitude(double instFlux, double instFluxErr,
247  afw::geom::Point<double, 2> const &point) const;
248 
250  Measurement instFluxToMagnitude(double instFlux, double instFluxErr) const;
251 
264  Measurement instFluxToMagnitude(afw::table::SourceRecord const &sourceRecord,
265  std::string const &instFluxField) const;
266 
279  ndarray::Array<double, 2, 2> instFluxToMagnitude(afw::table::SourceCatalog const &sourceCatalog,
280  std::string const &instFluxField) const;
281 
300  void instFluxToMagnitude(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
301  std::string const &outField) const;
302 
310  double magnitudeToInstFlux(double magnitude) const;
311 
325  double getCalibrationMean() const { return _calibrationMean; }
326 
339  double getCalibrationErr() const { return _calibrationErr; }
340 
353  double getInstFluxMag0() const { return 1.0 / _calibrationMean; }
354 
368  std::shared_ptr<afw::math::BoundedField> computeScaledCalibration() const;
369 
392 
394  bool operator==(PhotoCalib const &rhs) const;
395 
397  bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
398 
399  bool isPersistable() const { return true; }
400 
402 
403 protected:
404  virtual std::string getPersistenceName() const;
405 
406  virtual void write(OutputArchiveHandle &handle) const;
407 
408 private:
410 
411  // The "mean" calibration, defined as the geometric mean of _calibration evaluated over _calibration's
412  // bbox. Computed on instantiation as a convinience. Also, the actual calibration for a spatially-constant
413  // calibration.
414  double _calibrationMean;
415 
416  // The standard deviation of this PhotoCalib.
417  double _calibrationErr;
418 
419  // Is this spatially-constant? Used to short-circuit getting centroids.
420  bool _isConstant;
421 
423  double computeCalibrationMean(std::shared_ptr<afw::math::BoundedField> calibration) const;
424 
426  void instFluxToMaggiesArray(afw::table::SourceCatalog const &sourceCatalog,
427  std::string const &instFluxField, ndarray::Array<double, 2, 2> result) const;
428  void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
429  std::string const &instFluxField,
430  ndarray::Array<double, 2, 2> result) const;
431 };
432 } // namespace image
433 } // namespace afw
434 } // namespace lsst
435 
436 #endif // LSST_AFW_IMAGE_PHOTOCALIB_H
table::Key< double > calibrationErr
Definition: PhotoCalib.cc:215
PhotoCalib(double calibrationMean, double calibrationErr, std::shared_ptr< afw::math::BoundedField > calibration, bool isConstant)
Create a calibration with a pre-computed mean.
Definition: PhotoCalib.h:133
double getCalibrationMean() const
Get the mean photometric calibration (equal to 1 / getInstFluxMag0()).
Definition: PhotoCalib.h:325
An object passed to Persistable::write to allow it to persist itself.
The photometric calibration of an exposure.
Definition: PhotoCalib.h:81
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 calibrationErr are equal...
Definition: PhotoCalib.h:397
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
table::Key< double > calibrationMean
Definition: PhotoCalib.cc:214
An integer coordinate rectangle.
Definition: Box.h:55
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
Measurement(double value, double err)
Definition: PhotoCalib.h:45
std::ostream & operator<<(std::ostream &os, VisitInfo const &visitInfo)
Definition: VisitInfo.cc:430
A base class for image defects.
PhotoCalib(double calibrationMean, double calibrationErr=0, afw::geom::Box2I const &bbox=afw::geom::Box2I())
Create a non-spatially-varying calibration.
Definition: PhotoCalib.h:104
PhotoCalib(std::shared_ptr< afw::math::BoundedField > calibration, double calibrationErr=0)
Create a spatially-varying calibration.
Definition: PhotoCalib.h:119
PhotoCalib()
Create a empty, zeroed calibration.
Definition: PhotoCalib.h:94
double getCalibrationErr() const
Get the mean photometric calibration error.
Definition: PhotoCalib.h:339
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: PhotoCalib.h:399
A BoundedField based on 2-d Chebyshev polynomials of the first kind.
table::Box2IKey bbox
Record class that contains measurements made on a single exposure.
Definition: Source.h:80
double getInstFluxMag0() const
Get the magnitude zero point (equal to 1 / mean(calibration)).
Definition: PhotoCalib.h:353
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
STL class.