LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
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 //
31 #ifndef LSST_AFW_IMAGE_CALIB_H
32 #define LSST_AFW_IMAGE_CALIB_H
33 
34 #include <cmath>
35 #include <utility>
36 #include <memory>
37 #include "ndarray_fwd.h"
38 #include "lsst/base.h"
39 #include "lsst/daf/base/DateTime.h"
40 #include "lsst/afw/geom/Point.h"
42 
43 namespace lsst {
44 namespace daf {
45  namespace base {
46  class PropertySet;
47  }
48 }
49 
50 namespace afw {
51 namespace cameraGeom {
52  class Detector;
53 }
54 namespace image {
55 
56 static double const JanskysPerABFlux = 3631.0;
57 
59 inline double abMagFromFlux(double flux) {
60  return -2.5*std::log10(flux/JanskysPerABFlux);
61 }
62 
64 inline double abMagErrFromFluxErr(double fluxErr, double flux) {
65  return std::abs(fluxErr/(-0.4*flux*std::log(10)));
66 }
67 
69 inline double fluxFromABMag(double mag) {
70  return std::pow(10.0, -0.4*mag)*JanskysPerABFlux;
71 }
72 
74 inline double fluxErrFromABMagErr(double magErr, double mag) {
75  return std::abs(-0.4*magErr*fluxFromABMag(mag)*std::log(10.0));
76 }
77 
83 public :
84  typedef std::shared_ptr<Calib> Ptr;
85  typedef std::shared_ptr<Calib const> ConstPtr;
86 
87  explicit Calib();
88  explicit Calib(double fluxMag0);
89  explicit Calib(std::vector<CONST_PTR(Calib)> const& calibs);
91 
92  void setFluxMag0(double fluxMag0, double fluxMag0Sigma=0.0);
93  void setFluxMag0(std::pair<double, double> fluxMag0AndSigma);
94  std::pair<double, double> getFluxMag0() const;
95 
96  double getFlux(double const mag) const;
97 
98  std::pair<double, double> getFlux(double const mag, double const magErr) const;
99 
100  ndarray::Array<double,1> getFlux(ndarray::Array<double const,1> const & mag) const;
101 
102  std::pair< ndarray::Array<double,1>, ndarray::Array<double,1> > getFlux(
103  ndarray::Array<double const,1> const & mag,
104  ndarray::Array<double const,1> const & magErr
105  ) const;
106 
107  double getMagnitude(double const flux) const;
108 
109  std::pair<double, double> getMagnitude(double const flux, double const fluxErr) const;
110 
111  ndarray::Array<double,1> getMagnitude(ndarray::Array<double const,1> const & flux) const;
112 
113  std::pair< ndarray::Array<double,1>,ndarray::Array<double,1> > getMagnitude(
114  ndarray::Array<double const,1> const & flux,
115  ndarray::Array<double const,1> const & fluxErr
116  ) const;
117 
118  static void setThrowOnNegativeFlux(bool raiseException);
119  static bool getThrowOnNegativeFlux();
120  /*
121  * Compare two Calibs
122  */
123  bool operator==(Calib const& rhs) const;
124  bool operator!=(Calib const& rhs) const { return !(*this == rhs); }
125 
126  void operator*=(double const scale);
127  void operator/=(double const scale) { (*this) *= 1.0/scale; }
128 
129  bool isPersistable() const { return true; }
130 
131 protected:
132 
133  virtual std::string getPersistenceName() const;
134 
135  virtual void write(OutputArchiveHandle & handle) const;
136 
137 private:
138  double _fluxMag0;
140  static bool _throwOnNegativeFlux;
141 };
142 
143 namespace detail {
145 }
146 
147 }}} // lsst::afw::image
148 
149 #endif // LSST_AFW_IMAGE_CALIB_H
A coordinate class intended to represent absolute positions.
table::Key< double > fluxMag0Sigma
Definition: Calib.cc:405
double abMagErrFromFluxErr(double fluxErr, double flux)
Compute AB magnitude error from flux and flux error in Janskys.
Definition: Calib.h:64
double fluxErrFromABMagErr(double magErr, double mag)
Compute flux error in Janskys from AB magnitude error and AB magnitude.
Definition: Calib.h:74
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:112
void operator*=(double const scale)
Definition: Calib.cc:480
double abMagFromFlux(double flux)
Compute AB magnitude from flux in Janskys.
Definition: Calib.h:59
Describe an exposure&#39;s calibration.
Definition: Calib.h:82
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:72
double fluxFromABMag(double mag)
Compute flux in Janskys from AB magnitude.
Definition: Calib.h:69
bool operator==(Calib const &rhs) const
Are two Calibs identical?
Definition: Calib.cc:162
def log
Definition: log.py:83
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: Calib.cc:468
static void setThrowOnNegativeFlux(bool raiseException)
Set whether Calib should throw an exception when asked to convert a flux to a magnitude.
Definition: Calib.cc:115
std::pair< double, double > getFluxMag0() const
Return the flux, and error in flux, of a zero-magnitude object.
Definition: Calib.cc:188
static bool _throwOnNegativeFlux
Control whether we throw an exception when faced with a negative flux.
Definition: Calib.h:140
Interface for DateTime class.
int stripCalibKeywords(boost::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Calib-related keywords from the metadata.
Definition: Calib.cc:136
double getFlux(double const mag) const
Return a flux (in ADUs) given a magnitude.
Definition: Calib.cc:244
void operator/=(double const scale)
Definition: Calib.h:127
#define PTR(...)
Definition: base.h:41
Class for storing generic metadata.
Definition: PropertySet.h:82
std::shared_ptr< Calib const > ConstPtr
Definition: Calib.h:85
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Calib.cc:470
std::shared_ptr< Calib > Ptr
Definition: Calib.h:84
void setFluxMag0(double fluxMag0, double fluxMag0Sigma=0.0)
Set the flux of a zero-magnitude object.
Definition: Calib.cc:171
static bool getThrowOnNegativeFlux()
Tell me whether Calib will throw an exception if asked to convert a flux to a magnitude.
Definition: Calib.cc:125
table::Key< double > fluxMag0
Definition: Calib.cc:404
bool operator!=(Calib const &rhs) const
Definition: Calib.h:124
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
Basic LSST definitions.
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:180
double getMagnitude(double const flux) const
Return a magnitude given a flux.
Definition: Calib.cc:306
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Calib.h:129