LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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 //
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 
202  std::size_t hash_value() const noexcept;
203 
204  Calib& operator*=(double const scale);
205  Calib& operator/=(double const scale) {
206  (*this) *= 1.0 / scale;
207  return *this;
208  }
209 
210  bool isPersistable() const noexcept override { return true; }
211 
212 protected:
213  std::string getPersistenceName() const override;
214 
215  void write(OutputArchiveHandle& handle) const override;
216 
217 private:
218  double _fluxMag0;
219  double _fluxMag0Err;
223  static bool _throwOnNegativeFlux;
224 };
225 
226 namespace detail {
234 } // namespace detail
235 } // namespace image
236 } // namespace afw
237 } // namespace lsst
238 
239 namespace std {
240 template <>
241 struct hash<lsst::afw::image::Calib> {
244  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
245 };
246 } // namespace std
247 
248 #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:82
Angle abs(Angle const &a)
Definition: Angle.h:106
Calib & operator/=(double const scale)
Definition: Calib.h:205
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:109
STL namespace.
bool operator!=(Calib const &rhs) const noexcept
Definition: Calib.h:199
std::size_t hash_value(Extent< T, N > const &extent) noexcept
Definition: Extent.cc:127
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:210
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:161
Interface for DateTime class.
STL class.
Image< LhsPixelT > & operator*=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Multiply lhs by Image rhs (i.e. pixel-by-pixel multiplication) where types are different.
Definition: Image.cc:692
ndarray::Array< T, 1 > abMagFromFlux(ndarray::Array< T const, 1 > const &flux)
Compute AB magnitude from flux in Janskys.
Definition: Calib.cc:56
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:66
table::Key< double > fluxMag0
Definition: Calib.cc:378
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:92
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
table::Key< double > fluxMag0Err
Definition: Calib.cc:379
Basic LSST definitions.
size_t operator()(argument_type const &obj) const noexcept
Definition: Calib.h:244