LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
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"
44 #include "lsst/utils/Magnitude.h"
45 
46 namespace lsst {
47 namespace afw {
48 namespace image {
49 
51 struct Measurement {
52  Measurement(double value, double error) : value(value), error(error) {}
53  double const value;
54  double const error;
55 };
56 
57 std::ostream &operator<<(std::ostream &os, Measurement const &measurement);
58 
69 inline void assertNonNegative(double value, std::string const &name) {
70  if (value < 0) {
72  (boost::format("%s must be positive: %.3g") % name % value).str());
73  }
74 }
75 
114 class PhotoCalib final : public table::io::PersistableFacade<PhotoCalib>, public typehandling::Storable {
115 public:
116  // Allow move, but no copy
117  PhotoCalib(PhotoCalib const &) = default;
118  PhotoCalib(PhotoCalib &&) = default;
119  PhotoCalib &operator=(PhotoCalib const &) = delete;
121 
122  ~PhotoCalib() override = default;
123 
128 
137  explicit PhotoCalib(double calibrationMean, double calibrationErr = 0,
139  : _calibrationMean(calibrationMean), _calibrationErr(calibrationErr), _isConstant(true) {
140  assertNonNegative(_calibrationMean, "Calibration mean");
141  assertNonNegative(_calibrationErr, "Calibration error");
142  ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(1, 1));
143  coeffs[0][0] = calibrationMean;
144  _calibration = std::make_shared<afw::math::ChebyshevBoundedField>(
146  }
147 
155  : _calibration(calibration),
156  _calibrationMean(computeCalibrationMean(calibration)),
157  _calibrationErr(calibrationErr),
158  _isConstant(false) {
159  assertNonNegative(_calibrationMean, "Calibration (computed via BoundedField.mean()) mean");
160  assertNonNegative(_calibrationErr, "Calibration error");
161  }
162 
173  : _calibration(calibration),
174  _calibrationMean(calibrationMean),
175  _calibrationErr(calibrationErr),
176  _isConstant(isConstant) {
177  assertNonNegative(_calibrationMean, "Calibration mean");
178  assertNonNegative(_calibrationErr, "Calibration error");
179  }
180 
191  double instFluxToNanojansky(double instFlux, lsst::geom::Point<double, 2> const &point) const;
192 
194  double instFluxToNanojansky(double instFlux) const;
195 
207  Measurement instFluxToNanojansky(double instFlux, double instFluxErr,
208  lsst::geom::Point<double, 2> const &point) const;
209 
211  Measurement instFluxToNanojansky(double instFlux, double instFluxErr) const;
212 
226  std::string const &instFluxField) const;
227 
240  ndarray::Array<double, 2, 2> instFluxToNanojansky(afw::table::SourceCatalog const &sourceCatalog,
241  std::string const &instFluxField) const;
242 
256  void instFluxToNanojansky(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
257  std::string const &outField) const;
258 
269  double instFluxToMagnitude(double instFlux, lsst::geom::Point<double, 2> const &point) const;
270 
272  double instFluxToMagnitude(double instFlux) const;
273 
285  Measurement instFluxToMagnitude(double instFlux, double instFluxErr,
286  lsst::geom::Point<double, 2> const &point) const;
287 
289  Measurement instFluxToMagnitude(double instFlux, double instFluxErr) const;
290 
304  std::string const &instFluxField) const;
305 
318  ndarray::Array<double, 2, 2> instFluxToMagnitude(afw::table::SourceCatalog const &sourceCatalog,
319  std::string const &instFluxField) const;
320 
337  void instFluxToMagnitude(afw::table::SourceCatalog &sourceCatalog, std::string const &instFluxField,
338  std::string const &outField) const;
339 
351  bool includeScaleUncertainty = true) const;
352 
370  std::vector<std::string> const &instFluxFields) const;
371 
374 
387  double magnitudeToInstFlux(double magnitude, lsst::geom::Point<double, 2> const &point) const;
388 
390  double magnitudeToInstFlux(double magnitude) const;
391 
404  double getCalibrationMean() const { return _calibrationMean; }
405 
418  double getCalibrationErr() const { return _calibrationErr; }
419 
432  double getInstFluxAtZeroMagnitude() const { return utils::referenceFlux / _calibrationMean; }
433 
450  double getLocalCalibration(lsst::geom::Point<double, 2> const &point) const { return evaluate(point); }
451 
466 
489 
491  bool operator==(PhotoCalib const &rhs) const;
492 
494  bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
495 
496  bool isPersistable() const noexcept override { return true; }
497 
500 
502  std::string toString() const override;
503 
509  bool equals(typehandling::Storable const &other) const noexcept override;
510  // PhotoCalib equality comparable but intentionally not hashable
511 
512 protected:
513  std::string getPersistenceName() const override;
514 
515  void write(OutputArchiveHandle &handle) const override;
516 
517 private:
519 
520  // The "mean" calibration, defined as the geometric mean of _calibration evaluated over _calibration's
521  // bbox. Computed on instantiation as a convinience. Also, the actual calibration for a spatially-constant
522  // calibration.
523  double _calibrationMean;
524 
525  // The standard deviation of this PhotoCalib.
526  double _calibrationErr;
527 
528  // Is this spatially-constant? Used to short-circuit getting centroids.
529  bool _isConstant;
530 
536  double evaluate(lsst::geom::Point<double, 2> const &point) const;
540  ndarray::Array<double, 1> evaluateArray(ndarray::Array<double, 1> const &xx,
541  ndarray::Array<double, 1> const &yy) const;
545  ndarray::Array<double, 1> evaluateCatalog(afw::table::SourceCatalog const &sourceCatalog) const;
546 
548  double computeCalibrationMean(std::shared_ptr<afw::math::BoundedField> calibration) const;
549 
551  void instFluxToNanojanskyArray(afw::table::SourceCatalog const &sourceCatalog,
552  std::string const &instFluxField,
553  ndarray::Array<double, 2, 2> result) const;
554  void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
555  std::string const &instFluxField,
556  ndarray::Array<double, 2, 2> result) const;
557 };
558 
571 
585 std::shared_ptr<PhotoCalib> makePhotoCalibFromCalibZeroPoint(double instFluxMag0, double instFluxMag0Err);
586 
587 } // namespace image
588 } // namespace afw
589 } // namespace lsst
590 
591 #endif // LSST_AFW_IMAGE_PHOTOCALIB_H
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
lsst::utils::referenceFlux
const double referenceFlux
The Oke & Gunn (1983) AB magnitude reference flux, in nJy (often approximated as 3631....
Definition: Magnitude.h:46
lsst::afw::image::Measurement::error
double const error
Definition: PhotoCalib.h:54
std::string
STL class.
std::shared_ptr
STL class.
Persistable.h
Magnitude.h
Utilities for converting between flux and magnitude in C++.
lsst::afw::image::makePhotoCalibFromMetadata
std::shared_ptr< PhotoCalib > makePhotoCalibFromMetadata(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
Definition: PhotoCalib.cc:596
lsst::afw::table::SourceRecord
Record class that contains measurements made on a single exposure.
Definition: Source.h:80
lsst::afw::image::PhotoCalib::PhotoCalib
PhotoCalib(std::shared_ptr< afw::math::BoundedField > calibration, double calibrationErr=0)
Create a spatially-varying calibration.
Definition: PhotoCalib.h:154
Box.h
lsst::afw::image::PhotoCalib::PhotoCalib
PhotoCalib(PhotoCalib &&)=default
MaskedImage.h
std::vector< std::string >
calibrationErr
table::Key< double > calibrationErr
Definition: PhotoCalib.cc:371
lsst::afw::image::PhotoCalib::PhotoCalib
PhotoCalib()
Create a empty, zeroed calibration.
Definition: PhotoCalib.h:127
calibrationMean
table::Key< double > calibrationMean
Definition: PhotoCalib.cc:370
lsst::afw
Definition: imageAlgorithm.dox:1
isConstant
table::Key< table::Flag > isConstant
Definition: PhotoCalib.cc:372
lsst::afw::image::PhotoCalib::instFluxToMagnitude
double instFluxToMagnitude(double instFlux, lsst::geom::Point< double, 2 > const &point) const
Convert instFlux in ADU to AB magnitude.
Definition: PhotoCalib.cc:159
lsst::afw::image::PhotoCalib::getLocalCalibration
double getLocalCalibration(lsst::geom::Point< double, 2 > const &point) const
Get the local calibration at a point.
Definition: PhotoCalib.h:450
strip
bool strip
Definition: fits.cc:911
lsst::afw::image::operator<<
std::ostream & operator<<(std::ostream &os, Measurement const &measurement)
Definition: PhotoCalib.cc:48
lsst::afw::image::PhotoCalib::getCalibrationMean
double getCalibrationMean() const
Get the mean photometric calibration.
Definition: PhotoCalib.h:404
lsst.pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
lsst::afw::image::makePhotoCalibFromCalibZeroPoint
std::shared_ptr< PhotoCalib > makePhotoCalibFromCalibZeroPoint(double instFluxMag0, double instFluxMag0Err)
Construct a PhotoCalib from the deprecated Calib-style instFluxMag0/instFluxMag0Err values.
Definition: PhotoCalib.cc:614
lsst::afw::image::PhotoCalib::getInstFluxAtZeroMagnitude
double getInstFluxAtZeroMagnitude() const
Get the magnitude zero point (the instrumental flux corresponding to 0 magnitude).
Definition: PhotoCalib.h:432
lsst::afw::typehandling::Storable
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::afw::image::PhotoCalib::calibrateCatalog
afw::table::SourceCatalog calibrateCatalog(afw::table::SourceCatalog const &catalog, std::vector< std::string > const &instFluxFields) const
Return a flux calibrated catalog, with new _flux, _fluxErr, _mag, and _magErr fields.
Definition: PhotoCalib.cc:283
lsst::afw::image::PhotoCalib::operator==
bool operator==(PhotoCalib const &rhs) const
Two PhotoCalibs are equal if their component bounded fields and calibrationErr are equal.
Definition: PhotoCalib.cc:230
lsst::afw::image::PhotoCalib::operator=
PhotoCalib & operator=(PhotoCalib const &)=delete
lsst::afw::math::ChebyshevBoundedField
A BoundedField based on 2-d Chebyshev polynomials of the first kind.
Definition: ChebyshevBoundedField.h:77
PropertyList.h
lsst::afw::image::PhotoCalib::PhotoCalib
PhotoCalib(PhotoCalib const &)=default
lsst::afw::image::PhotoCalib::computeScalingTo
std::shared_ptr< afw::math::BoundedField > computeScalingTo(std::shared_ptr< PhotoCalib > other) const
Calculates the scaling between this PhotoCalib and another PhotoCalib.
Definition: PhotoCalib.cc:226
Point.h
lsst::afw::image::PhotoCalib::cloneStorable
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new PhotoCalib that is a copy of this one.
Definition: PhotoCalib.cc:239
lsst::afw::image::MaskedImage
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
lsst::afw::image::PhotoCalib::instFluxToNanojansky
double instFluxToNanojansky(double instFlux, lsst::geom::Point< double, 2 > const &point) const
Convert instFlux in ADU to nJy at a point in the BoundedField.
Definition: PhotoCalib.cc:105
lsst::afw::image::PhotoCalib::isPersistable
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: PhotoCalib.h:496
lsst::afw::image::PhotoCalib::operator=
PhotoCalib & operator=(PhotoCalib &&)=delete
std::ostream
STL class.
lsst::afw::table._source.SourceCatalog
Definition: _source.py:32
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::image::PhotoCalib::write
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: PhotoCalib.cc:512
lsst::afw::image::PhotoCalib
The photometric calibration of an exposure.
Definition: PhotoCalib.h:114
Storable.h
result
py::object result
Definition: _schema.cc:429
Source.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::image::PhotoCalib::toString
std::string toString() const override
Create a string representation of this object.
Definition: PhotoCalib.cc:243
lsst::afw::image::PhotoCalib::PhotoCalib
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:171
os
std::ostream * os
Definition: Schema.cc:746
lsst::afw::image::Measurement::value
double const value
Definition: PhotoCalib.h:53
lsst::afw::image::PhotoCalib::equals
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
Definition: PhotoCalib.cc:253
lsst.pex::exceptions::InvalidParameterError
Reports invalid arguments.
Definition: Runtime.h:66
lsst::afw::image::PhotoCalib::operator!=
bool operator!=(PhotoCalib const &rhs) const
Two PhotoCalibs are equal if their component bounded fields and calibrationErr are equal.
Definition: PhotoCalib.h:494
lsst::afw::image::Measurement
A value and its error.
Definition: PhotoCalib.h:51
lsst::geom::Point< double, 2 >
lsst::afw::table::io::PersistableFacade
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
ChebyshevBoundedField.h
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
lsst::afw::image::assertNonNegative
void assertNonNegative(double value, std::string const &name)
Raise lsst::pex::exceptions::InvalidParameterError if value is not >=0.
Definition: PhotoCalib.h:69
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst::afw::image::PhotoCalib::PhotoCalib
PhotoCalib(double calibrationMean, double calibrationErr=0, lsst::geom::Box2I const &bbox=lsst::geom::Box2I())
Create a non-spatially-varying calibration.
Definition: PhotoCalib.h:137
lsst::afw::image::Measurement::Measurement
Measurement(double value, double error)
Definition: PhotoCalib.h:52
lsst::afw::image::PhotoCalib::computeScaledCalibration
std::shared_ptr< afw::math::BoundedField > computeScaledCalibration() const
Calculates the spatially-variable calibration, normalized by the mean in the valid domain.
Definition: PhotoCalib.cc:222
lsst::afw::image::PhotoCalib::calibrateImage
MaskedImage< float > calibrateImage(MaskedImage< float > const &maskedImage, bool includeScaleUncertainty=true) const
Return a flux calibrated image, with pixel values in nJy.
Definition: PhotoCalib.cc:261
lsst::afw::image::PhotoCalib::~PhotoCalib
~PhotoCalib() override=default
Exception.h
lsst::afw::image::PhotoCalib::getCalibrationErr
double getCalibrationErr() const
Get the mean photometric calibration error.
Definition: PhotoCalib.h:418
lsst::afw::image::PhotoCalib::magnitudeToInstFlux
double magnitudeToInstFlux(double magnitude, lsst::geom::Point< double, 2 > const &point) const
Convert AB magnitude to instFlux (ADU).
Definition: PhotoCalib.cc:218
BoundedField.h
lsst::afw::table::io::Persistable::OutputArchiveHandle
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
bbox
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
lsst::afw::image::PhotoCalib::getPersistenceName
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: PhotoCalib.cc:510