lsst.afw  13.0-91-g2a3e2ee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/afw/geom/Point.h"
40 
41 namespace lsst {
42 namespace daf {
43 namespace base {
44 class PropertySet;
45 }
46 }
47 
48 namespace afw {
49 namespace cameraGeom {
50 class Detector;
51 }
52 namespace image {
53 
54 static double const JanskysPerABFlux = 3631.0;
55 
57 inline double abMagFromFlux(double flux) { return -2.5 * std::log10(flux / JanskysPerABFlux); }
58 
60 inline double abMagErrFromFluxErr(double fluxErr, double flux) {
61  return std::abs(fluxErr / (-0.4 * flux * std::log(10)));
62 }
63 
65 inline double fluxFromABMag(double mag) { return std::pow(10.0, -0.4 * mag) * JanskysPerABFlux; }
66 
68 inline double fluxErrFromABMagErr(double magErr, double mag) {
69  return std::abs(-0.4 * magErr * fluxFromABMag(mag) * std::log(10.0));
70 }
71 
77 public:
81  explicit Calib();
85  explicit Calib(double fluxMag0);
93  explicit Calib(std::vector<std::shared_ptr<Calib const>> const& calibs);
97  explicit Calib(std::shared_ptr<lsst::daf::base::PropertySet const>);
98 
105  void setFluxMag0(double fluxMag0, double fluxMag0Sigma = 0.0);
109  void setFluxMag0(std::pair<double, double> fluxMag0AndSigma);
113  std::pair<double, double> getFluxMag0() const;
114 
120  double getFlux(double const mag) const;
121 
130  std::pair<double, double> getFlux(double const mag, double const magErr) const;
131 
132  ndarray::Array<double, 1> getFlux(ndarray::Array<double const, 1> const& mag) const;
133 
134  std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> getFlux(
135  ndarray::Array<double const, 1> const& mag, ndarray::Array<double const, 1> const& magErr) const;
136 
142  double getMagnitude(double const flux) const;
143 
150  std::pair<double, double> getMagnitude(double const flux, double const fluxErr) const;
151 
152  ndarray::Array<double, 1> getMagnitude(ndarray::Array<double const, 1> const& flux) const;
153 
154  std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> getMagnitude(
155  ndarray::Array<double const, 1> const& flux,
156  ndarray::Array<double const, 1> const& fluxErr) const;
157 
163  static void setThrowOnNegativeFlux(bool raiseException);
167  static bool getThrowOnNegativeFlux();
173  bool operator==(Calib const& rhs) const;
174  bool operator!=(Calib const& rhs) const { return !(*this == rhs); }
175 
176  Calib& operator*=(double const scale);
177  Calib& operator/=(double const scale) {
178  (*this) *= 1.0 / scale;
179  return *this;
180  }
181 
182  bool isPersistable() const { return true; }
183 
184 protected:
185  virtual std::string getPersistenceName() const;
186 
187  virtual void write(OutputArchiveHandle& handle) const;
188 
189 private:
190  double _fluxMag0;
191  double _fluxMag0Sigma;
195  static bool _throwOnNegativeFlux;
196 };
197 
198 namespace detail {
205 int stripCalibKeywords(std::shared_ptr<lsst::daf::base::PropertySet> metadata);
206 }
207 }
208 }
209 } // lsst::afw::image
210 
211 #endif // LSST_AFW_IMAGE_CALIB_H
Calib & operator/=(double const scale)
Definition: Calib.h:177
double abMagErrFromFluxErr(double fluxErr, double flux)
Compute AB magnitude error from flux and flux error in Janskys.
Definition: Calib.h:60
double fluxErrFromABMagErr(double magErr, double mag)
Compute flux error in Janskys from AB magnitude error and AB magnitude.
Definition: Calib.h:68
table::Key< double > fluxMag0Sigma
Definition: Calib.cc:309
double abMagFromFlux(double flux)
Compute AB magnitude from flux in Janskys.
Definition: Calib.h:57
Describe an exposure&#39;s calibration.
Definition: Calib.h:76
Calib & operator*=(double const scale)
Definition: Calib.cc:376
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:73
double fluxFromABMag(double mag)
Compute flux in Janskys from AB magnitude.
Definition: Calib.h:65
bool operator==(Calib const &rhs) const
Are two Calibs identical?
Definition: Calib.cc:115
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: Calib.cc:364
static void setThrowOnNegativeFlux(bool raiseException)
Set whether Calib should throw an exception when asked to convert a flux to a magnitude.
Definition: Calib.cc:91
std::pair< double, double > getFluxMag0() const
Return the flux, and error in flux, of a zero-magnitude object.
Definition: Calib.cc:128
int stripCalibKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Calib-related keywords from the metadata.
Definition: Calib.cc:96
double getFlux(double const mag) const
Return a flux (in ADUs) given a magnitude.
Definition: Calib.cc:172
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:55
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Calib.cc:366
afw::table::Key< afw::table::Array< ImagePixelT > > image
void setFluxMag0(double fluxMag0, double fluxMag0Sigma=0.0)
Set the flux of a zero-magnitude object.
Definition: Calib.cc:119
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:107
static bool getThrowOnNegativeFlux()
Tell me whether Calib will throw an exception if asked to convert a flux to a magnitude.
Definition: Calib.cc:93
table::Key< double > fluxMag0
Definition: Calib.cc:308
bool operator!=(Calib const &rhs) const
Definition: Calib.h:174
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:173
double getMagnitude(double const flux) const
Return a magnitude given a flux.
Definition: Calib.cc:220
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Calib.h:182