LSSTApplications  16.0-11-g09ed895+2,16.0-11-g12e47bd,16.0-11-g9bb73b2+6,16.0-12-g5c924a4+6,16.0-14-g9a974b3+1,16.0-15-g1417920+1,16.0-15-gdd5ca33+1,16.0-16-gf0259e2,16.0-17-g31abd91+7,16.0-17-g7d7456e+7,16.0-17-ga3d2e9f+13,16.0-18-ga4d4bcb+1,16.0-18-gd06566c+1,16.0-2-g0febb12+21,16.0-2-g9d5294e+69,16.0-2-ga8830df+6,16.0-20-g21842373+7,16.0-24-g3eae5ec,16.0-28-gfc9ea6c+4,16.0-29-ge8801f9,16.0-3-ge00e371+34,16.0-4-g18f3627+13,16.0-4-g5f3a788+20,16.0-4-ga3eb747+10,16.0-4-gabf74b7+29,16.0-4-gb13d127+6,16.0-49-g42e581f7+6,16.0-5-g27fb78a+7,16.0-5-g6a53317+34,16.0-5-gb3f8a4b+87,16.0-6-g9321be7+4,16.0-6-gcbc7b31+42,16.0-6-gf49912c+29,16.0-7-gd2eeba5+51,16.0-71-ge89f8615e,16.0-8-g21fd5fe+29,16.0-8-g3a9f023+20,16.0-8-g4734f7a+1,16.0-8-g5858431+3,16.0-9-gf5c1f43+8,master-gd73dc1d098+1,w.2019.01
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.
Definition: cameraGeom.dox:3
Basic LSST definitions.
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
size_t operator()(argument_type const &obj) const noexcept
Definition: Calib.h:244