lsst.afw  14.0-25-g0e8fc950e+5
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 
93 
102  explicit PhotoCalib(double calibrationMean, double calibrationErr = 0,
103  afw::geom::Box2I const &bbox = afw::geom::Box2I())
104  : _calibrationMean(calibrationMean), _calibrationErr(calibrationErr), _isConstant(true) {
105  ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(1, 1));
106  coeffs[0][0] = calibrationMean;
107  _calibration = std::make_shared<afw::math::ChebyshevBoundedField>(
108  afw::math::ChebyshevBoundedField(bbox, coeffs));
109  }
110 
118  : _calibration(calibration),
119  _calibrationMean(computeCalibrationMean(calibration)),
120  _calibrationErr(calibrationErr),
121  _isConstant(false) {}
122 
131  PhotoCalib(double calibrationMean, double calibrationErr,
133  : _calibration(calibration),
134  _calibrationMean(calibrationMean),
135  _calibrationErr(calibrationErr),
136  _isConstant(isConstant) {}
137 
148  double instFluxToMaggies(double instFlux, afw::geom::Point<double, 2> const &point) const;
149 
151  double instFluxToMaggies(double instFlux) const;
152 
164  Measurement instFluxToMaggies(double instFlux, double instFluxErr,
165  afw::geom::Point<double, 2> const &point) const;
166 
168  Measurement instFluxToMaggies(double instFlux, double instFluxErr) const;
169 
182  Measurement instFluxToMaggies(const afw::table::SourceRecord &sourceRecord,
183  std::string const &instFluxField) const;
184 
197  ndarray::Array<double, 2, 2> instFluxToMaggies(afw::table::SourceCatalog const &sourceCatalog,
198  std::string const &instFluxField) const;
199 
215  void instFluxToMaggies(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
216  std::string const &outField) const;
217 
228  double instFluxToMagnitude(double instFlux, afw::geom::Point<double, 2> const &point) const;
229 
231  double instFluxToMagnitude(double instFlux) const;
232 
244  Measurement instFluxToMagnitude(double instFlux, double instFluxErr,
245  afw::geom::Point<double, 2> const &point) const;
246 
248  Measurement instFluxToMagnitude(double instFlux, double instFluxErr) const;
249 
262  Measurement instFluxToMagnitude(afw::table::SourceRecord const &sourceRecord,
263  std::string const &instFluxField) const;
264 
277  ndarray::Array<double, 2, 2> instFluxToMagnitude(afw::table::SourceCatalog const &sourceCatalog,
278  std::string const &instFluxField) const;
279 
298  void instFluxToMagnitude(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
299  std::string const &outField) const;
300 
308  double magnitudeToInstFlux(double magnitude) const;
309 
323  double getCalibrationMean() const { return _calibrationMean; }
324 
337  double getCalibrationErr() const { return _calibrationErr; }
338 
351  double getInstFluxMag0() const { return 1.0 / _calibrationMean; }
352 
366  std::shared_ptr<afw::math::BoundedField> computeScaledCalibration() const;
367 
390 
392  bool operator==(PhotoCalib const &rhs) const;
393 
395  bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
396 
397  bool isPersistable() const { return true; }
398 
400 
401 protected:
402  virtual std::string getPersistenceName() const;
403 
404  virtual void write(OutputArchiveHandle &handle) const;
405 
406 private:
408 
409  // The "mean" calibration, defined as the geometric mean of _calibration evaluated over _calibration's
410  // bbox. Computed on instantiation as a convinience. Also, the actual calibration for a spatially-constant
411  // calibration.
412  double _calibrationMean;
413 
414  // The standard deviation of this PhotoCalib.
415  double _calibrationErr;
416 
417  // Is this spatially-constant? Used to short-circuit getting centroids.
418  bool _isConstant;
419 
421  double computeCalibrationMean(std::shared_ptr<afw::math::BoundedField> calibration) const;
422 
424  void instFluxToMaggiesArray(afw::table::SourceCatalog const &sourceCatalog,
425  std::string const &instFluxField, ndarray::Array<double, 2, 2> result) const;
426  void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
427  std::string const &instFluxField,
428  ndarray::Array<double, 2, 2> result) const;
429 };
430 } // namespace image
431 } // namespace afw
432 } // namespace lsst
433 
434 #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:131
double getCalibrationMean() const
Get the mean photometric calibration (equal to 1 / getInstFluxMag0()).
Definition: PhotoCalib.h:323
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:395
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:73
Measurement(double value, double err)
Definition: PhotoCalib.h:45
std::ostream & operator<<(std::ostream &os, VisitInfo const &visitInfo)
Definition: VisitInfo.cc:417
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:102
PhotoCalib(std::shared_ptr< afw::math::BoundedField > calibration, double calibrationErr=0)
Create a spatially-varying calibration.
Definition: PhotoCalib.h:117
PhotoCalib()
Create a empty, zeroed calibration.
Definition: PhotoCalib.h:92
double getCalibrationErr() const
Get the mean photometric calibration error.
Definition: PhotoCalib.h:337
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: PhotoCalib.h:397
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 magnitude zero point (equal to 1 / mean(calibration)).
Definition: PhotoCalib.h:351
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:173
STL class.