lsst.afw  14.0-22-gc76603d1b
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/afw/geom/Point.h"
41 
42 namespace lsst {
43 namespace daf {
44 namespace base {
45 class PropertySet;
46 }
47 }
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) { return std::pow(10.0, -0.4 * mag) * JanskysPerABFlux; }
67 
69 inline double fluxErrFromABMagErr(double magErr, double mag) {
70  return std::abs(-0.4 * magErr * fluxFromABMag(mag) * std::log(10.0));
71 }
72 
73 
75 template <typename T>
76 ndarray::Array<T, 1> abMagFromFlux(ndarray::Array<T const, 1> const& flux);
77 
79 template <typename T>
80 ndarray::Array<T, 1> abMagErrFromFluxErr(ndarray::Array<T const, 1> const& fluxErr,
81  ndarray::Array<T const, 1> const& flux);
82 
84 template <typename T>
85 ndarray::Array<T, 1> fluxFromABMag(ndarray::Array<T const, 1> const& mag);
86 
88 template <typename T>
89 ndarray::Array<T, 1> fluxErrFromABMagErr(ndarray::Array<T const, 1> const& magErr,
90  ndarray::Array<T const, 1> const& mag);
91 
97 public:
101  explicit Calib();
105  explicit Calib(double fluxMag0);
113  explicit Calib(std::vector<std::shared_ptr<Calib const>> const& calibs);
118 
125  void setFluxMag0(double fluxMag0, double fluxMag0Sigma = 0.0);
129  void setFluxMag0(std::pair<double, double> fluxMag0AndSigma);
133  std::pair<double, double> getFluxMag0() const;
134 
140  double getFlux(double const mag) const;
141 
150  std::pair<double, double> getFlux(double const mag, double const magErr) const;
151 
152  ndarray::Array<double, 1> getFlux(ndarray::Array<double const, 1> const& mag) const;
153 
154  std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> getFlux(
155  ndarray::Array<double const, 1> const& mag, ndarray::Array<double const, 1> const& magErr) const;
156 
162  double getMagnitude(double const flux) const;
163 
170  std::pair<double, double> getMagnitude(double const flux, double const fluxErr) const;
171 
172  ndarray::Array<double, 1> getMagnitude(ndarray::Array<double const, 1> const& flux) const;
173 
174  std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> getMagnitude(
175  ndarray::Array<double const, 1> const& flux,
176  ndarray::Array<double const, 1> const& fluxErr) const;
177 
183  static void setThrowOnNegativeFlux(bool raiseException);
187  static bool getThrowOnNegativeFlux();
193  bool operator==(Calib const& rhs) const;
194  bool operator!=(Calib const& rhs) const { return !(*this == rhs); }
195 
196  Calib& operator*=(double const scale);
197  Calib& operator/=(double const scale) {
198  (*this) *= 1.0 / scale;
199  return *this;
200  }
201 
202  bool isPersistable() const { return true; }
203 
204 protected:
205  virtual std::string getPersistenceName() const;
206 
207  virtual void write(OutputArchiveHandle& handle) const;
208 
209 private:
210  double _fluxMag0;
211  double _fluxMag0Sigma;
215  static bool _throwOnNegativeFlux;
216 };
217 
218 namespace detail {
226 }
227 }
228 }
229 } // lsst::afw::image
230 
231 #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:76
table::Key< double > fluxMag0Sigma
Definition: Calib.cc:363
Calib & operator/=(double const scale)
Definition: Calib.h:197
An object passed to Persistable::write to allow it to persist itself.
T log(T... args)
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:117
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
T log10(T... args)
Describe an exposure&#39;s calibration.
Definition: Calib.h:96
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Calib.h:202
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:73
void operator*=(ExtentBase< int, N > &lhs, double rhs)
Definition: Extent.h:386
A base class for image defects.
bool operator!=(Calib const &rhs) const
Definition: Calib.h:194
int stripCalibKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Calib-related keywords from the metadata.
Definition: Calib.cc:150
STL class.
ndarray::Array< T, 1 > abMagFromFlux(ndarray::Array< T const, 1 > const &flux)
Compute AB magnitude from flux in Janskys.
Definition: Calib.cc:50
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:60
table::Key< double > fluxMag0
Definition: Calib.cc:362
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:86
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:173