LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
LSST Data Management Base Package
Loading...
Searching...
No Matches
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
31
32#include "boost/format.hpp"
33
36#include "lsst/geom/Point.h"
37#include "lsst/geom/Box.h"
45
46namespace lsst {
47namespace afw {
48namespace image {
49
52 Measurement(double value, double error) : value(value), error(error) {}
53 double const value;
54 double const error;
55};
56
57std::ostream &operator<<(std::ostream &os, Measurement const &measurement);
58
69inline 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
114class PhotoCalib final : public table::io::PersistableFacade<PhotoCalib>, public typehandling::Storable {
115public:
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,
138 lsst::geom::Box2I const &bbox = lsst::geom::Box2I())
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;
146 }
147
154 PhotoCalib(std::shared_ptr<afw::math::BoundedField> calibration, double calibrationErr = 0)
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
171 PhotoCalib(double calibrationMean, double calibrationErr,
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
341
352 MaskedImage<float> calibrateImage(MaskedImage<float> const &maskedImage) const;
353 // TODO[DM-49400]: remove the overload below.
354 [[deprecated(
355 "The includeScaleUncertainty option is deprecated and does nothing. Will be removed after v29."
356 )]]
358 bool includeScaleUncertainty) const;
360
362
375 // TODO[DM-49400]: remove the overload below.
376 [[deprecated(
377 "The includeScaleUncertainty option is deprecated and does nothing. Will be removed after v29."
378 )]]
380 bool includeScaleUncertainty) const;
382
400 std::vector<std::string> const &instFluxFields) const;
401
404
417 double magnitudeToInstFlux(double magnitude, lsst::geom::Point<double, 2> const &point) const;
418
420 double magnitudeToInstFlux(double magnitude) const;
421
434 double nanojanskyToInstFlux(double nanojansky, lsst::geom::Point<double, 2> const &point) const;
435
437 double nanojanskyToInstFlux(double nanojansky) const;
438
451 double getCalibrationMean() const { return _calibrationMean; }
452
465 double getCalibrationErr() const { return _calibrationErr; }
466
472 bool isConstant() const { return _isConstant; }
473
486 double getInstFluxAtZeroMagnitude() const { return cpputils::referenceFlux / _calibrationMean; }
487
504 double getLocalCalibration(lsst::geom::Point<double, 2> const &point) const { return evaluate(point); }
505
520
543
545 bool operator==(PhotoCalib const &rhs) const;
546
548 bool operator!=(PhotoCalib const &rhs) const { return !(*this == rhs); }
549
550 bool isPersistable() const noexcept override { return true; }
551
554
556 std::string toString() const override;
557
563 bool equals(typehandling::Storable const &other) const noexcept override;
564 // PhotoCalib equality comparable but intentionally not hashable
565
566protected:
567 std::string getPersistenceName() const override;
568
569 void write(OutputArchiveHandle &handle) const override;
570
571private:
573
574 // The "mean" calibration, defined as the geometric mean of _calibration evaluated over _calibration's
575 // bbox. Computed on instantiation as a convinience. Also, the actual calibration for a spatially-constant
576 // calibration.
577 double _calibrationMean;
578
579 // The standard deviation of this PhotoCalib.
580 double _calibrationErr;
581
582 // Is this spatially-constant? Used to short-circuit getting centroids.
583 bool _isConstant;
584
590 double evaluate(lsst::geom::Point<double, 2> const &point) const;
594 ndarray::Array<double, 1> evaluateArray(ndarray::Array<double, 1> const &xx,
595 ndarray::Array<double, 1> const &yy) const;
599 ndarray::Array<double, 1> evaluateCatalog(afw::table::SourceCatalog const &sourceCatalog) const;
600
602 double computeCalibrationMean(std::shared_ptr<afw::math::BoundedField> calibration) const;
603
605 void instFluxToNanojanskyArray(afw::table::SourceCatalog const &sourceCatalog,
606 std::string const &instFluxField,
607 ndarray::Array<double, 2, 2> result) const;
608 void instFluxToMagnitudeArray(afw::table::SourceCatalog const &sourceCatalog,
609 std::string const &instFluxField,
610 ndarray::Array<double, 2, 2> result) const;
611};
612
625
639std::shared_ptr<PhotoCalib> makePhotoCalibFromCalibZeroPoint(double instFluxMag0, double instFluxMag0Err);
640
641} // namespace image
642} // namespace afw
643} // namespace lsst
644
645#endif // LSST_AFW_IMAGE_PHOTOCALIB_H
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Utilities for converting between flux and magnitude in C++.
A class to manipulate images, masks, and variance as a single object.
Definition MaskedImage.h:74
The photometric calibration of an exposure.
Definition PhotoCalib.h:114
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
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.
bool operator==(PhotoCalib const &rhs) const
Two PhotoCalibs are equal if their component bounded fields and calibrationErr are equal.
double getCalibrationMean() const
Get the mean photometric calibration.
Definition PhotoCalib.h:451
PhotoCalib(PhotoCalib &&)=default
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:84
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
PhotoCalib()
Create a empty, zeroed calibration.
Definition PhotoCalib.h:127
PhotoCalib(PhotoCalib const &)=default
double instFluxToMagnitude(double instFlux, lsst::geom::Point< double, 2 > const &point) const
Convert instFlux in ADU to AB magnitude.
PhotoCalib(double calibrationMean, double calibrationErr=0, lsst::geom::Box2I const &bbox=lsst::geom::Box2I())
Create a non-spatially-varying calibration.
Definition PhotoCalib.h:137
std::string toString() const override
Create a string representation of this object.
bool operator!=(PhotoCalib const &rhs) const
Two PhotoCalibs are equal if their component bounded fields and calibrationErr are equal.
Definition PhotoCalib.h:548
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
PhotoCalib(std::shared_ptr< afw::math::BoundedField > calibration, double calibrationErr=0)
Create a spatially-varying calibration.
Definition PhotoCalib.h:154
MaskedImage< float > uncalibrateImage(MaskedImage< float > const &maskedImage) const
Return a un-calibrated image, with pixel values in ADU (or whatever the original input to this photoC...
PhotoCalib & operator=(PhotoCalib const &)=delete
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new PhotoCalib that is a copy of this one.
double getLocalCalibration(lsst::geom::Point< double, 2 > const &point) const
Get the local calibration at a point.
Definition PhotoCalib.h:504
double nanojanskyToInstFlux(double nanojansky, lsst::geom::Point< double, 2 > const &point) const
Convert nanojansky to instFlux (ADU).
std::shared_ptr< afw::math::BoundedField > computeScalingTo(std::shared_ptr< PhotoCalib > other) const
Calculates the scaling between this PhotoCalib and another PhotoCalib.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition PhotoCalib.h:550
double getCalibrationErr() const
Get the mean photometric calibration error.
Definition PhotoCalib.h:465
bool isConstant() const
Is this photoCalib spatially constant?
Definition PhotoCalib.h:472
~PhotoCalib() override=default
std::shared_ptr< afw::math::BoundedField > computeScaledCalibration() const
Calculates the spatially-variable calibration, normalized by the mean in the valid domain.
PhotoCalib & operator=(PhotoCalib &&)=delete
MaskedImage< float > calibrateImage(MaskedImage< float > const &maskedImage) const
Return a flux calibrated image, with pixel values in nJy.
double magnitudeToInstFlux(double magnitude, lsst::geom::Point< double, 2 > const &point) const
Convert AB magnitude to instFlux (ADU).
double getInstFluxAtZeroMagnitude() const
Get the magnitude zero point (the instrumental flux corresponding to 0 magnitude).
Definition PhotoCalib.h:486
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:78
A CRTP facade class for subclasses of Persistable.
io::OutputArchiveHandle OutputArchiveHandle
Interface supporting iteration over heterogenous containers.
Definition Storable.h:58
Class for storing generic metadata.
Definition PropertySet.h:67
An integer coordinate rectangle.
Definition Box.h:55
A coordinate class intended to represent absolute positions.
Definition Point.h:169
Reports invalid arguments.
Definition Runtime.h:66
T make_shared(T... args)
std::shared_ptr< PhotoCalib > makePhotoCalibFromCalibZeroPoint(double instFluxMag0, double instFluxMag0Err)
Construct a PhotoCalib from the deprecated Calib-style instFluxMag0/instFluxMag0Err values.
std::shared_ptr< PhotoCalib > makePhotoCalibFromMetadata(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
std::ostream & operator<<(std::ostream &os, Measurement const &measurement)
Definition PhotoCalib.cc:48
void assertNonNegative(double value, std::string const &name)
Raise lsst::pex::exceptions::InvalidParameterError if value is not >=0.
Definition PhotoCalib.h:69
const double referenceFlux
The Oke & Gunn (1983) AB magnitude reference flux, in nJy (often approximated as 3631....
Definition Magnitude.h:46
A value and its error.
Definition PhotoCalib.h:51
Measurement(double value, double error)
Definition PhotoCalib.h:52