LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
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 
32 #include "boost/format.hpp"
33 
36 #include "lsst/geom/Point.h"
37 #include "lsst/geom/Box.h"
38 #include "lsst/afw/table/Source.h"
43 #include "lsst/utils/Magnitude.h"
44 
45 namespace lsst {
46 namespace afw {
47 namespace image {
48 
50 struct Measurement {
51  Measurement(double value, double error) : value(value), error(error) {}
52  double const value;
53  double const error;
54 };
55 
66 inline void assertNonNegative(double value, std::string const &name) {
67  if (value < 0) {
69  (boost::format("%s must be positive: %.3g") % name % value).str());
70  }
71 }
72 
112 public:
113  // no move or copy
114  PhotoCalib(PhotoCalib const &) = delete;
115  PhotoCalib(PhotoCalib &&) = delete;
116  PhotoCalib &operator=(PhotoCalib const &) = delete;
117  PhotoCalib &operator=(PhotoCalib &&) = delete;
118 
119  ~PhotoCalib() override = default;
120 
125 
134  explicit PhotoCalib(double calibrationMean, double calibrationErr = 0,
136  : _calibrationMean(calibrationMean), _calibrationErr(calibrationErr), _isConstant(true) {
137  assertNonNegative(_calibrationMean, "Calibration mean");
138  assertNonNegative(_calibrationErr, "Calibration error");
139  ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(1, 1));
140  coeffs[0][0] = calibrationMean;
141  _calibration = std::make_shared<afw::math::ChebyshevBoundedField>(
143  }
144 
152  : _calibration(calibration),
153  _calibrationMean(computeCalibrationMean(calibration)),
154  _calibrationErr(calibrationErr),
155  _isConstant(false) {
156  assertNonNegative(_calibrationMean, "Calibration (computed via BoundedField.mean()) mean");
157  assertNonNegative(_calibrationErr, "Calibration error");
158  }
159 
168  PhotoCalib(double calibrationMean, double calibrationErr,
170  : _calibration(calibration),
171  _calibrationMean(calibrationMean),
172  _calibrationErr(calibrationErr),
173  _isConstant(isConstant) {
174  assertNonNegative(_calibrationMean, "Calibration mean");
175  assertNonNegative(_calibrationErr, "Calibration error");
176  }
177 
188  double instFluxToNanojansky(double instFlux, lsst::geom::Point<double, 2> const &point) const;
189 
191  double instFluxToNanojansky(double instFlux) const;
192 
204  Measurement instFluxToNanojansky(double instFlux, double instFluxErr,
205  lsst::geom::Point<double, 2> const &point) const;
206 
208  Measurement instFluxToNanojansky(double instFlux, double instFluxErr) const;
209 
221  Measurement instFluxToNanojansky(const afw::table::SourceRecord &sourceRecord,
222  std::string const &instFluxField) const;
223 
235  ndarray::Array<double, 2, 2> instFluxToNanojansky(afw::table::SourceCatalog const &sourceCatalog,
236  std::string const &instFluxField) const;
237 
252  void instFluxToNanojansky(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
253  std::string const &outField) const;
254 
265  double instFluxToMagnitude(double instFlux, lsst::geom::Point<double, 2> const &point) const;
266 
268  double instFluxToMagnitude(double instFlux) const;
269 
281  Measurement instFluxToMagnitude(double instFlux, double instFluxErr,
282  lsst::geom::Point<double, 2> const &point) const;
283 
285  Measurement instFluxToMagnitude(double instFlux, double instFluxErr) const;
286 
298  Measurement instFluxToMagnitude(afw::table::SourceRecord const &sourceRecord,
299  std::string const &instFluxField) const;
300 
312  ndarray::Array<double, 2, 2> instFluxToMagnitude(afw::table::SourceCatalog const &sourceCatalog,
313  std::string const &instFluxField) const;
314 
332  void instFluxToMagnitude(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
333  std::string const &outField) const;
334 
345  MaskedImage<float> calibrateImage(MaskedImage<float> const &maskedImage,
346  bool includeScaleUncertainty = true) const;
347 
360  double magnitudeToInstFlux(double magnitude, lsst::geom::Point<double, 2> const &point) const;
362  double magnitudeToInstFlux(double magnitude) const;
363 
376  double getCalibrationMean() const { return _calibrationMean; }
377 
390  double getCalibrationErr() const { return _calibrationErr; }
391 
404  double getInstFluxAtZeroMagnitude() const { return utils::referenceFlux / _calibrationMean; }
405 
419  std::shared_ptr<afw::math::BoundedField> computeScaledCalibration() const;
420 
443 
445  bool operator==(PhotoCalib const &rhs) const;
446 
448  bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
449 
450  bool isPersistable() const noexcept override { return true; }
451 
453 
454 protected:
455  std::string getPersistenceName() const override;
456 
457  void write(OutputArchiveHandle &handle) const override;
458 
459 private:
461 
462  // The "mean" calibration, defined as the geometric mean of _calibration evaluated over _calibration's
463  // bbox. Computed on instantiation as a convinience. Also, the actual calibration for a spatially-constant
464  // calibration.
465  double _calibrationMean;
466 
467  // The standard deviation of this PhotoCalib.
468  double _calibrationErr;
469 
470  // Is this spatially-constant? Used to short-circuit getting centroids.
471  bool _isConstant;
472 
478  double evaluate(lsst::geom::Point<double, 2> const &point) const;
479 
481  double computeCalibrationMean(std::shared_ptr<afw::math::BoundedField> calibration) const;
482 
484  void instFluxToNanojanskyArray(afw::table::SourceCatalog const &sourceCatalog,
485  std::string const &instFluxField,
486  ndarray::Array<double, 2, 2> result) const;
487  void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
488  std::string const &instFluxField,
489  ndarray::Array<double, 2, 2> result) const;
490 };
491 
504 
505 } // namespace image
506 } // namespace afw
507 } // namespace lsst
508 
509 #endif // LSST_AFW_IMAGE_PHOTOCALIB_H
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: PhotoCalib.h:450
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:168
double getCalibrationMean() const
Get the mean photometric calibration.
Definition: PhotoCalib.h:376
An object passed to Persistable::write to allow it to persist itself.
The photometric calibration of an exposure.
Definition: PhotoCalib.h:111
py::object result
Definition: schema.cc:284
bool operator!=(PhotoCalib const &rhs) const
Two PhotoCalibs are equal if their component bounded fields and calibrationErr are equal...
Definition: PhotoCalib.h:448
A value and its error.
Definition: PhotoCalib.h:50
std::shared_ptr< PhotoCalib > makePhotoCalib(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
Definition: PhotoCalib.cc:397
PhotoCalib(double calibrationMean, double calibrationErr=0, lsst::geom::Box2I const &bbox=lsst::geom::Box2I())
Create a non-spatially-varying calibration.
Definition: PhotoCalib.h:134
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
std::ostream & operator<<(std::ostream &os, VisitInfo const &visitInfo)
Definition: VisitInfo.cc:448
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:151
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
Utilities for converting between flux and magnitude in C++.
table::Key< double > calibrationMean
Definition: PhotoCalib.cc:268
PhotoCalib()
Create a empty, zeroed calibration.
Definition: PhotoCalib.h:124
table::Box2IKey bbox
Definition: Detector.cc:166
Measurement(double value, double error)
Definition: PhotoCalib.h:51
double getCalibrationErr() const
Get the mean photometric calibration error.
Definition: PhotoCalib.h:390
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
A BoundedField based on 2-d Chebyshev polynomials of the first kind.
Class for storing generic metadata.
Definition: PropertySet.h:68
Reports invalid arguments.
Definition: Runtime.h:66
ItemVariant const * other
Definition: Schema.cc:56
Record class that contains measurements made on a single exposure.
Definition: Source.h:82
table::Key< table::Flag > isConstant
Definition: PhotoCalib.cc:270
void assertNonNegative(double value, std::string const &name)
Raise lsst::pex::exceptions::InvalidParameterError if value is not >=0.
Definition: PhotoCalib.h:66
const double referenceFlux
The Oke & Gunn (1983) AB magnitude reference flux, in nJy (often approximated as 3631.0).
Definition: Magnitude.h:46
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
An integer coordinate rectangle.
Definition: Box.h:54
STL class.
bool strip
Definition: fits.cc:831
double getInstFluxAtZeroMagnitude() const
Get the magnitude zero point (the instrumental flux corresponding to 0 magnitude).
Definition: PhotoCalib.h:404
table::Key< double > calibrationErr
Definition: PhotoCalib.cc:269
std::ostream * os
Definition: Schema.cc:746