lsst.afw  16.0-56-g615901931+1
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/geom/Point.h"
35 #include "lsst/geom/Box.h"
36 #include "lsst/afw/table/Source.h"
39 
40 namespace lsst {
41 namespace afw {
42 namespace image {
43 
45 struct Measurement {
46  Measurement(double value, double err) : value(value), err(err) {}
47  double const value;
48  double const err;
49 };
50 
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 
90  ~PhotoCalib() override = default;
91 
96 
105  explicit PhotoCalib(double calibrationMean, double calibrationErr = 0,
107  : _calibrationMean(calibrationMean), _calibrationErr(calibrationErr), _isConstant(true) {
108  ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(1, 1));
109  coeffs[0][0] = calibrationMean;
110  _calibration = std::make_shared<afw::math::ChebyshevBoundedField>(
112  }
113 
121  : _calibration(calibration),
122  _calibrationMean(computeCalibrationMean(calibration)),
123  _calibrationErr(calibrationErr),
124  _isConstant(false) {}
125 
134  PhotoCalib(double calibrationMean, double calibrationErr,
136  : _calibration(calibration),
137  _calibrationMean(calibrationMean),
138  _calibrationErr(calibrationErr),
139  _isConstant(isConstant) {}
140 
151  double instFluxToMaggies(double instFlux, lsst::geom::Point<double, 2> const &point) const;
152 
154  double instFluxToMaggies(double instFlux) const;
155 
167  Measurement instFluxToMaggies(double instFlux, double instFluxErr,
168  lsst::geom::Point<double, 2> const &point) const;
169 
171  Measurement instFluxToMaggies(double instFlux, double instFluxErr) const;
172 
185  Measurement instFluxToMaggies(const afw::table::SourceRecord &sourceRecord,
186  std::string const &instFluxField) const;
187 
200  ndarray::Array<double, 2, 2> instFluxToMaggies(afw::table::SourceCatalog const &sourceCatalog,
201  std::string const &instFluxField) const;
202 
218  void instFluxToMaggies(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
219  std::string const &outField) const;
220 
231  double instFluxToMagnitude(double instFlux, lsst::geom::Point<double, 2> const &point) const;
232 
234  double instFluxToMagnitude(double instFlux) const;
235 
247  Measurement instFluxToMagnitude(double instFlux, double instFluxErr,
248  lsst::geom::Point<double, 2> const &point) const;
249 
251  Measurement instFluxToMagnitude(double instFlux, double instFluxErr) const;
252 
265  Measurement instFluxToMagnitude(afw::table::SourceRecord const &sourceRecord,
266  std::string const &instFluxField) const;
267 
280  ndarray::Array<double, 2, 2> instFluxToMagnitude(afw::table::SourceCatalog const &sourceCatalog,
281  std::string const &instFluxField) const;
282 
301  void instFluxToMagnitude(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
302  std::string const &outField) const;
303 
313  MaskedImage<float> calibrateImage(MaskedImage<float> const &maskedImage) const;
314 
322  double magnitudeToInstFlux(double magnitude) const;
323 
337  double getCalibrationMean() const { return _calibrationMean; }
338 
351  double getCalibrationErr() const { return _calibrationErr; }
352 
365  double getInstFluxMag0() const { return 1.0 / _calibrationMean; }
366 
380  std::shared_ptr<afw::math::BoundedField> computeScaledCalibration() const;
381 
404 
406  bool operator==(PhotoCalib const &rhs) const;
407 
409  bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
410 
411  bool isPersistable() const noexcept override { return true; }
412 
414 
415 protected:
416  std::string getPersistenceName() const override;
417 
418  void write(OutputArchiveHandle &handle) const override;
419 
420 private:
422 
423  // The "mean" calibration, defined as the geometric mean of _calibration evaluated over _calibration's
424  // bbox. Computed on instantiation as a convinience. Also, the actual calibration for a spatially-constant
425  // calibration.
426  double _calibrationMean;
427 
428  // The standard deviation of this PhotoCalib.
429  double _calibrationErr;
430 
431  // Is this spatially-constant? Used to short-circuit getting centroids.
432  bool _isConstant;
433 
439  double evaluate(lsst::geom::Point<double, 2> const &point) const;
440 
442  double computeCalibrationMean(std::shared_ptr<afw::math::BoundedField> calibration) const;
443 
445  void instFluxToMaggiesArray(afw::table::SourceCatalog const &sourceCatalog,
446  std::string const &instFluxField, ndarray::Array<double, 2, 2> result) const;
447  void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
448  std::string const &instFluxField,
449  ndarray::Array<double, 2, 2> result) const;
450 };
451 
452 } // namespace image
453 } // namespace afw
454 } // namespace lsst
455 
456 #endif // LSST_AFW_IMAGE_PHOTOCALIB_H
table::Key< double > calibrationErr
Definition: PhotoCalib.cc:247
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: PhotoCalib.h:411
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:134
double getCalibrationMean() const
Get the mean photometric calibration (equal to 1 / getInstFluxMag0()).
Definition: PhotoCalib.h:337
An object passed to Persistable::write to allow it to persist itself.
The photometric calibration of an exposure.
Definition: PhotoCalib.h:82
table::Key< table::Flag > isConstant
Definition: PhotoCalib.cc:248
table::Box2IKey bbox
Definition: Detector.cc:166
bool operator!=(PhotoCalib const &rhs) const
Two PhotoCalibs are equal if their component bounded fields and calibrationErr are equal...
Definition: PhotoCalib.h:409
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
A value and its error.
Definition: PhotoCalib.h:45
ItemVariant const * other
Definition: Schema.cc:55
table::Key< double > calibrationMean
Definition: PhotoCalib.cc:246
PhotoCalib(double calibrationMean, double calibrationErr=0, lsst::geom::Box2I const &bbox=lsst::geom::Box2I())
Create a non-spatially-varying calibration.
Definition: PhotoCalib.h:105
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:46
std::ostream & operator<<(std::ostream &os, VisitInfo const &visitInfo)
Definition: VisitInfo.cc:440
A base class for image defects.
PhotoCalib(std::shared_ptr< afw::math::BoundedField > calibration, double calibrationErr=0)
Create a spatially-varying calibration.
Definition: PhotoCalib.h:120
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
PhotoCalib()
Create a empty, zeroed calibration.
Definition: PhotoCalib.h:95
std::unique_ptr< SchemaItem< U > > result
Definition: Schema.cc:194
double getCalibrationErr() const
Get the mean photometric calibration error.
Definition: PhotoCalib.h:351
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:82
std::ostream * os
Definition: Schema.cc:737
double getInstFluxMag0() const
Get the magnitude zero point (equal to 1 / mean(calibration)).
Definition: PhotoCalib.h:365
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
STL class.