LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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 
94  lsst::daf::base::DateTime getMidTime(std::shared_ptr<const lsst::afw::cameraGeom::Detector>,
95  lsst::afw::geom::Point2I const&) const;
96 
97  void setExptime(double exptime);
98  double getExptime() const;
99 
100  void setFluxMag0(double fluxMag0, double fluxMag0Sigma=0.0);
101  void setFluxMag0(std::pair<double, double> fluxMag0AndSigma);
102  std::pair<double, double> getFluxMag0() const;
103 
104  double getFlux(double const mag) const;
105 
106  std::pair<double, double> getFlux(double const mag, double const magErr) const;
107 
108  ndarray::Array<double,1> getFlux(ndarray::Array<double const,1> const & mag) const;
109 
110  std::pair< ndarray::Array<double,1>, ndarray::Array<double,1> > getFlux(
111  ndarray::Array<double const,1> const & mag,
112  ndarray::Array<double const,1> const & magErr
113  ) const;
114 
115  double getMagnitude(double const flux) const;
116 
117  std::pair<double, double> getMagnitude(double const flux, double const fluxErr) const;
118 
119  ndarray::Array<double,1> getMagnitude(ndarray::Array<double const,1> const & flux) const;
120 
121  std::pair< ndarray::Array<double,1>,ndarray::Array<double,1> > getMagnitude(
122  ndarray::Array<double const,1> const & flux,
123  ndarray::Array<double const,1> const & fluxErr
124  ) const;
125 
126  static void setThrowOnNegativeFlux(bool raiseException);
127  static bool getThrowOnNegativeFlux();
128  /*
129  * Compare two Calibs
130  */
131  bool operator==(Calib const& rhs) const;
132  bool operator!=(Calib const& rhs) const { return !(*this == rhs); }
133 
134  void operator*=(double const scale);
135  void operator/=(double const scale) { (*this) *= 1.0/scale; }
136 
137  bool isPersistable() const { return true; }
138 
139 protected:
140 
141  virtual std::string getPersistenceName() const;
142 
143  virtual void write(OutputArchiveHandle & handle) const;
144 
145 private:
147  double _exptime;
148  double _fluxMag0;
150  static bool _throwOnNegativeFlux;
151 };
152 
153 namespace detail {
155 }
156 
157 }}} // lsst::afw::image
158 
159 #endif // LSST_AFW_IMAGE_CALIB_H
A coordinate class intended to represent absolute positions.
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:58
table::Key< double > fluxMag0Sigma
Definition: Calib.cc:493
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
#define CONST_PTR(...)
Definition: base.h:47
void operator*=(double const scale)
Definition: Calib.cc:563
double abMagFromFlux(double flux)
Compute AB magnitude from flux in Janskys.
Definition: Calib.h:59
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
Definition: Calib.cc:203
def log
Definition: log.py:83
table::Key< std::int64_t > midTime
Definition: Calib.cc:490
void setExptime(double exptime)
Definition: Calib.cc:247
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: Calib.cc:549
static void setThrowOnNegativeFlux(bool raiseException)
Definition: Calib.cc:144
double getExptime() const
Definition: Calib.cc:255
std::pair< double, double > getFluxMag0() const
Definition: Calib.cc:280
static bool _throwOnNegativeFlux
Definition: Calib.h:150
Interface for DateTime class.
int stripCalibKeywords(boost::shared_ptr< lsst::daf::base::PropertySet > metadata)
Definition: Calib.cc:165
double getFlux(double const mag) const
Definition: Calib.cc:335
void operator/=(double const scale)
Definition: Calib.h:135
Class for storing generic metadata.
Definition: PropertySet.h:82
std::shared_ptr< Calib const > ConstPtr
Definition: Calib.h:85
#define PTR(...)
Definition: base.h:41
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Calib.cc:551
std::shared_ptr< Calib > Ptr
Definition: Calib.h:84
void setFluxMag0(double fluxMag0, double fluxMag0Sigma=0.0)
Definition: Calib.cc:263
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:112
static bool getThrowOnNegativeFlux()
Definition: Calib.cc:154
table::Key< double > fluxMag0
Definition: Calib.cc:492
bool operator!=(Calib const &rhs) const
Definition: Calib.h:132
lsst::daf::base::DateTime getMidTime() const
Definition: Calib.cc:225
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:180
lsst::daf::base::DateTime _midTime
Definition: Calib.h:146
double getMagnitude(double const flux) const
Definition: Calib.cc:397
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Calib.h:137
void setMidTime(lsst::daf::base::DateTime const &midTime)
Definition: Calib.cc:216