lsst.afw  16.0-51-gb4b4a8566+2
Calib.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 //
26 /*
27  * Classes to support calibration (e.g. photometric zero points, exposure times)
28  */
29 #ifndef LSST_AFW_IMAGE_CALIB_H
30 #define LSST_AFW_IMAGE_CALIB_H
31 
32 #include <cmath>
33 #include <utility>
34 #include <memory>
35 #include "ndarray_fwd.h"
36 #include "lsst/base.h"
37 #include "lsst/daf/base/DateTime.h"
38 #include "lsst/pex/exceptions.h"
39 #include "lsst/geom/Point.h"
41 
42 namespace lsst {
43 namespace daf {
44 namespace base {
45 class PropertySet;
46 }
47 } // namespace daf
48 
49 namespace afw {
50 namespace cameraGeom {
51 class Detector;
52 }
53 namespace image {
54 
55 static double const JanskysPerABFlux = 3631.0;
56 
58 inline double abMagFromFlux(double flux) { return -2.5 * std::log10(flux / JanskysPerABFlux); }
59 
61 inline double abMagErrFromFluxErr(double fluxErr, double flux) {
62  return std::abs(fluxErr / (-0.4 * flux * std::log(10)));
63 }
64 
66 inline double fluxFromABMag(double mag) noexcept { return std::pow(10.0, -0.4 * mag) * JanskysPerABFlux; }
67 
69 inline double fluxErrFromABMagErr(double magErr, double mag) noexcept {
70  return std::abs(-0.4 * magErr * fluxFromABMag(mag) * std::log(10.0));
71 }
72 
74 template <typename T>
75 ndarray::Array<T, 1> abMagFromFlux(ndarray::Array<T const, 1> const& flux);
76 
78 template <typename T>
79 ndarray::Array<T, 1> abMagErrFromFluxErr(ndarray::Array<T const, 1> const& fluxErr,
80  ndarray::Array<T const, 1> const& flux);
81 
83 template <typename T>
84 ndarray::Array<T, 1> fluxFromABMag(ndarray::Array<T const, 1> const& mag);
85 
87 template <typename T>
88 ndarray::Array<T, 1> fluxErrFromABMagErr(ndarray::Array<T const, 1> const& magErr,
89  ndarray::Array<T const, 1> const& mag);
90 
96 public:
100  explicit Calib() noexcept;
104  explicit Calib(double fluxMag0);
112  explicit Calib(std::vector<std::shared_ptr<Calib const>> const& calibs);
117 
118  Calib(Calib const&) noexcept;
119  Calib(Calib&&) noexcept;
120  Calib& operator=(Calib const&) noexcept;
121  Calib& operator=(Calib&&) noexcept;
122  ~Calib() noexcept override;
123 
130  void setFluxMag0(double fluxMag0, double fluxMag0Err = 0.0);
134  void setFluxMag0(std::pair<double, double> fluxMag0AndErr);
138  std::pair<double, double> getFluxMag0() const;
139 
145  double getFlux(double const mag) const;
146 
155  std::pair<double, double> getFlux(double const mag, double const magErr) const;
156 
157  ndarray::Array<double, 1> getFlux(ndarray::Array<double const, 1> const& mag) const;
158 
159  std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> getFlux(
160  ndarray::Array<double const, 1> const& mag, ndarray::Array<double const, 1> const& magErr) const;
161 
167  double getMagnitude(double const flux) const;
168 
175  std::pair<double, double> getMagnitude(double const flux, double const fluxErr) const;
176 
177  ndarray::Array<double, 1> getMagnitude(ndarray::Array<double const, 1> const& flux) const;
178 
179  std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> getMagnitude(
180  ndarray::Array<double const, 1> const& flux,
181  ndarray::Array<double const, 1> const& fluxErr) const;
182 
188  static void setThrowOnNegativeFlux(bool raiseException) noexcept;
192  static bool getThrowOnNegativeFlux() noexcept;
198  bool operator==(Calib const& rhs) const noexcept;
199  bool operator!=(Calib const& rhs) const noexcept { return !(*this == rhs); }
200 
201  Calib& operator*=(double const scale);
202  Calib& operator/=(double const scale) {
203  (*this) *= 1.0 / scale;
204  return *this;
205  }
206 
207  bool isPersistable() const noexcept override { return true; }
208 
209 protected:
210  std::string getPersistenceName() const override;
211 
212  void write(OutputArchiveHandle& handle) const override;
213 
214 private:
215  double _fluxMag0;
216  double _fluxMag0Err;
220  static bool _throwOnNegativeFlux;
221 };
222 
223 namespace detail {
231 } // namespace detail
232 } // namespace image
233 } // namespace afw
234 } // namespace lsst
235 
236 #endif // LSST_AFW_IMAGE_CALIB_H
ndarray::Array< T, 1 > fluxFromABMag(ndarray::Array< T const, 1 > const &mag)
Compute flux in Janskys from AB magnitude.
Definition: Calib.cc:81
Calib & operator/=(double const scale)
Definition: Calib.h:202
An object passed to Persistable::write to allow it to persist itself.
T log(T... args)
void operator*=(ExtentBase< int, N > &lhs, double rhs) noexcept
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:114
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
bool operator!=(Calib const &rhs) const noexcept
Definition: Calib.h:199
T log10(T... args)
Describe an exposure&#39;s calibration.
Definition: Calib.h:95
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: Calib.h:207
A base class for image defects.
int stripCalibKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Calib-related keywords from the metadata.
Definition: Calib.cc:160
STL class.
table::Key< double > fluxMag0Err
Definition: Calib.cc:373
ndarray::Array< T, 1 > abMagFromFlux(ndarray::Array< T const, 1 > const &flux)
Compute AB magnitude from flux in Janskys.
Definition: Calib.cc:55
T pow(T... args)
ndarray::Array< T, 1 > abMagErrFromFluxErr(ndarray::Array< T const, 1 > const &fluxErr, ndarray::Array< T const, 1 > const &flux)
Compute AB magnitude error from flux and flux error in Janskys.
Definition: Calib.cc:65
table::Key< double > fluxMag0
Definition: Calib.cc:372
ndarray::Array< T, 1 > fluxErrFromABMagErr(ndarray::Array< T const, 1 > const &magErr, ndarray::Array< T const, 1 > const &mag)
Compute flux error in Janskys from AB magnitude error and AB magnitude.
Definition: Calib.cc:91
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176