LSSTApplications  16.0-11-g09ed895+2,16.0-11-g12e47bd,16.0-11-g9bb73b2+6,16.0-12-g5c924a4+6,16.0-14-g9a974b3+1,16.0-15-g1417920+1,16.0-15-gdd5ca33+1,16.0-16-gf0259e2,16.0-17-g31abd91+7,16.0-17-g7d7456e+7,16.0-17-ga3d2e9f+13,16.0-18-ga4d4bcb+1,16.0-18-gd06566c+1,16.0-2-g0febb12+21,16.0-2-g9d5294e+69,16.0-2-ga8830df+6,16.0-20-g21842373+7,16.0-24-g3eae5ec,16.0-28-gfc9ea6c+4,16.0-29-ge8801f9,16.0-3-ge00e371+34,16.0-4-g18f3627+13,16.0-4-g5f3a788+20,16.0-4-ga3eb747+10,16.0-4-gabf74b7+29,16.0-4-gb13d127+6,16.0-49-g42e581f7+6,16.0-5-g27fb78a+7,16.0-5-g6a53317+34,16.0-5-gb3f8a4b+87,16.0-6-g9321be7+4,16.0-6-gcbc7b31+42,16.0-6-gf49912c+29,16.0-7-gd2eeba5+51,16.0-71-ge89f8615e,16.0-8-g21fd5fe+29,16.0-8-g3a9f023+20,16.0-8-g4734f7a+1,16.0-8-g5858431+3,16.0-9-gf5c1f43+8,master-gd73dc1d098+1,w.2019.01
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"
42 #include "lsst/utils/Magnitude.h"
43 
44 namespace lsst {
45 namespace afw {
46 namespace image {
47 
49 struct Measurement {
50  Measurement(double value, double error) : value(value), error(error) {}
51  double const value;
52  double const error;
53 };
54 
65 inline void assertNonNegative(double value, std::string const &name) {
66  if (value < 0) {
68  (boost::format("%s must be positive: %.3g") % name % value).str());
69  }
70 }
71 
111 public:
112  // no move or copy
113  PhotoCalib(PhotoCalib const &) = delete;
114  PhotoCalib(PhotoCalib &&) = delete;
115  PhotoCalib &operator=(PhotoCalib const &) = delete;
116  PhotoCalib &operator=(PhotoCalib &&) = delete;
117 
118  ~PhotoCalib() override = default;
119 
124 
133  explicit PhotoCalib(double calibrationMean, double calibrationErr = 0,
135  : _calibrationMean(calibrationMean), _calibrationErr(calibrationErr), _isConstant(true) {
136  assertNonNegative(_calibrationMean, "Calibration mean");
137  assertNonNegative(_calibrationErr, "Calibration error");
138  ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(1, 1));
139  coeffs[0][0] = calibrationMean;
140  _calibration = std::make_shared<afw::math::ChebyshevBoundedField>(
142  }
143 
151  : _calibration(calibration),
152  _calibrationMean(computeCalibrationMean(calibration)),
153  _calibrationErr(calibrationErr),
154  _isConstant(false) {
155  assertNonNegative(_calibrationMean, "Calibration (computed via BoundedField.mean()) mean");
156  assertNonNegative(_calibrationErr, "Calibration error");
157  }
158 
167  PhotoCalib(double calibrationMean, double calibrationErr,
169  : _calibration(calibration),
170  _calibrationMean(calibrationMean),
171  _calibrationErr(calibrationErr),
172  _isConstant(isConstant) {
173  assertNonNegative(_calibrationMean, "Calibration mean");
174  assertNonNegative(_calibrationErr, "Calibration error");
175  }
176 
187  double instFluxToNanojansky(double instFlux, lsst::geom::Point<double, 2> const &point) const;
188 
190  double instFluxToNanojansky(double instFlux) const;
191 
203  Measurement instFluxToNanojansky(double instFlux, double instFluxErr,
204  lsst::geom::Point<double, 2> const &point) const;
205 
207  Measurement instFluxToNanojansky(double instFlux, double instFluxErr) const;
208 
220  Measurement instFluxToNanojansky(const afw::table::SourceRecord &sourceRecord,
221  std::string const &instFluxField) const;
222 
234  ndarray::Array<double, 2, 2> instFluxToNanojansky(afw::table::SourceCatalog const &sourceCatalog,
235  std::string const &instFluxField) const;
236 
251  void instFluxToNanojansky(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
252  std::string const &outField) const;
253 
264  double instFluxToMagnitude(double instFlux, lsst::geom::Point<double, 2> const &point) const;
265 
267  double instFluxToMagnitude(double instFlux) const;
268 
280  Measurement instFluxToMagnitude(double instFlux, double instFluxErr,
281  lsst::geom::Point<double, 2> const &point) const;
282 
284  Measurement instFluxToMagnitude(double instFlux, double instFluxErr) const;
285 
297  Measurement instFluxToMagnitude(afw::table::SourceRecord const &sourceRecord,
298  std::string const &instFluxField) const;
299 
311  ndarray::Array<double, 2, 2> instFluxToMagnitude(afw::table::SourceCatalog const &sourceCatalog,
312  std::string const &instFluxField) const;
313 
331  void instFluxToMagnitude(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
332  std::string const &outField) const;
333 
344  MaskedImage<float> calibrateImage(MaskedImage<float> const &maskedImage,
345  bool includeScaleUncertainty = true) const;
346 
359  double magnitudeToInstFlux(double magnitude, lsst::geom::Point<double, 2> const &point) const;
361  double magnitudeToInstFlux(double magnitude) const;
362 
375  double getCalibrationMean() const { return _calibrationMean; }
376 
389  double getCalibrationErr() const { return _calibrationErr; }
390 
403  double getInstFluxAtZeroMagnitude() const { return utils::referenceFlux / _calibrationMean; }
404 
418  std::shared_ptr<afw::math::BoundedField> computeScaledCalibration() const;
419 
442 
444  bool operator==(PhotoCalib const &rhs) const;
445 
447  bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
448 
449  bool isPersistable() const noexcept override { return true; }
450 
452 
453 protected:
454  std::string getPersistenceName() const override;
455 
456  void write(OutputArchiveHandle &handle) const override;
457 
458 private:
460 
461  // The "mean" calibration, defined as the geometric mean of _calibration evaluated over _calibration's
462  // bbox. Computed on instantiation as a convinience. Also, the actual calibration for a spatially-constant
463  // calibration.
464  double _calibrationMean;
465 
466  // The standard deviation of this PhotoCalib.
467  double _calibrationErr;
468 
469  // Is this spatially-constant? Used to short-circuit getting centroids.
470  bool _isConstant;
471 
477  double evaluate(lsst::geom::Point<double, 2> const &point) const;
478 
480  double computeCalibrationMean(std::shared_ptr<afw::math::BoundedField> calibration) const;
481 
483  void instFluxToNanojanskyArray(afw::table::SourceCatalog const &sourceCatalog,
484  std::string const &instFluxField,
485  ndarray::Array<double, 2, 2> result) const;
486  void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
487  std::string const &instFluxField,
488  ndarray::Array<double, 2, 2> result) const;
489 };
490 
491 } // namespace image
492 } // namespace afw
493 } // namespace lsst
494 
495 #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:449
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:167
double getCalibrationMean() const
Get the mean photometric calibration.
Definition: PhotoCalib.h:375
An object passed to Persistable::write to allow it to persist itself.
The photometric calibration of an exposure.
Definition: PhotoCalib.h:110
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:447
A value and its error.
Definition: PhotoCalib.h:49
PhotoCalib(double calibrationMean, double calibrationErr=0, lsst::geom::Box2I const &bbox=lsst::geom::Box2I())
Create a non-spatially-varying calibration.
Definition: PhotoCalib.h:133
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.
Definition: cameraGeom.dox:3
PhotoCalib(std::shared_ptr< afw::math::BoundedField > calibration, double calibrationErr=0)
Create a spatially-varying calibration.
Definition: PhotoCalib.h:150
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:129
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:123
table::Box2IKey bbox
Definition: Detector.cc:166
Measurement(double value, double error)
Definition: PhotoCalib.h:50
double getCalibrationErr() const
Get the mean photometric calibration error.
Definition: PhotoCalib.h:389
#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.
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:65
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.
double getInstFluxAtZeroMagnitude() const
Get the magnitude zero point (the instrumental flux corresponding to 0 magnitude).
Definition: PhotoCalib.h:403
table::Key< double > calibrationErr
Definition: PhotoCalib.cc:269
std::ostream * os
Definition: Schema.cc:746