lsst.afw  13.0-73-gb2a4e38
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
calib.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
25 
26 #include <memory>
27 #include <vector>
28 
29 #include "numpy/arrayobject.h"
30 #include "ndarray/pybind11.h"
31 
32 #include "lsst/daf/base/PropertySet.h"
35 #include "lsst/afw/image/Calib.h"
36 
37 namespace py = pybind11;
38 using namespace pybind11::literals;
39 
40 namespace lsst {
41 namespace afw {
42 namespace image {
43 namespace {
44 
45 using PyCalib = py::class_<Calib, std::shared_ptr<Calib>, table::io::PersistableFacade<Calib>,
46  table::io::Persistable>;
47 
48 PYBIND11_PLUGIN(calib) {
49  py::module mod("calib");
50 
51  if (_import_array() < 0) {
52  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
53  return nullptr;
54  };
55 
56  /* Module level */
57  mod.def("abMagFromFlux", &abMagFromFlux, "flux"_a);
58  mod.def("abMagErrFromFluxErr", &abMagErrFromFluxErr, "fluxErr"_a, "flux"_a);
59  mod.def("fluxFromABMag", &fluxFromABMag, "mag"_a);
60  mod.def("fluxErrFromABMagErr", &fluxErrFromABMagErr, "magErr"_a, "mag"_a);
61  mod.def("stripCalibKeywords", &detail::stripCalibKeywords, "metadata"_a);
62 
63  table::io::python::declarePersistableFacade<Calib>(mod, "Calib");
64 
65  PyCalib cls(mod, "Calib");
66 
67  /* Constructors */
68  cls.def(py::init<>());
69  cls.def(py::init<double>(), "fluxMag0"_a);
70  cls.def(py::init<std::vector<std::shared_ptr<const Calib>> const &>(), "calibs"_a);
71  cls.def(py::init<std::shared_ptr<const daf::base::PropertySet>>(), "metadata"_a);
72 
73  /* Operators */
74  cls.def("__eq__", &Calib::operator==, py::is_operator());
75  cls.def("__ne__", &Calib::operator!=, py::is_operator());
76  cls.def("__imul__", &Calib::operator*=);
77  cls.def("__itruediv__", &Calib::operator/=);
78  cls.def("__idiv__", &Calib::operator/=);
79 
80  /* Members */
81  cls.def("setFluxMag0", (void (Calib::*)(double, double)) & Calib::setFluxMag0, "fluxMag0"_a,
82  "fluxMag0Sigma"_a = 0.0);
83  cls.def("setFluxMag0", (void (Calib::*)(std::pair<double, double>)) & Calib::setFluxMag0,
84  "fluxMag0AndSigma"_a);
85  cls.def("getFluxMag0", &Calib::getFluxMag0);
86  cls.def("getFlux", (double (Calib::*)(double const) const) & Calib::getFlux, "mag"_a);
87  cls.def("getFlux",
88  (std::pair<double, double> (Calib::*)(double const, double const) const) & Calib::getFlux,
89  "mag"_a, "magErr"_a);
90  cls.def("getFlux", (ndarray::Array<double, 1> (Calib::*)(ndarray::Array<double const, 1> const &) const) &
91  Calib::getFlux,
92  "mag"_a);
93  cls.def("getFlux",
94  (std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> (Calib::*)(
95  ndarray::Array<double const, 1> const &, ndarray::Array<double const, 1> const &) const) &
96  Calib::getFlux,
97  "mag"_a, "magErr"_a);
98  cls.def("getMagnitude", (double (Calib::*)(double const) const) & Calib::getMagnitude, "flux"_a);
99  cls.def("getMagnitude",
100  (std::pair<double, double> (Calib::*)(double const, double const) const) & Calib::getMagnitude,
101  "flux"_a, "fluxErr"_a);
102  cls.def("getMagnitude",
103  (ndarray::Array<double, 1> (Calib::*)(ndarray::Array<double const, 1> const &) const) &
104  Calib::getMagnitude,
105  "flux"_a);
106  cls.def("getMagnitude",
107  (std::pair<ndarray::Array<double, 1>, ndarray::Array<double, 1>> (Calib::*)(
108  ndarray::Array<double const, 1> const &, ndarray::Array<double const, 1> const &) const) &
109  Calib::getMagnitude,
110  "flux"_a, "fluxMag"_a);
111  cls.def_static("setThrowOnNegativeFlux", Calib::setThrowOnNegativeFlux, "raiseException"_a);
112  cls.def_static("getThrowOnNegativeFlux", Calib::getThrowOnNegativeFlux);
113  cls.def("isPersistable", &Calib::isPersistable);
114 
115  return mod.ptr();
116 }
117 }
118 }
119 }
120 } // namespace lsst::afw::image::<anonymous>
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
double abMagFromFlux(double flux)
Compute AB magnitude from flux in Janskys.
Definition: Calib.h:57
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
double fluxFromABMag(double mag)
Compute flux in Janskys from AB magnitude.
Definition: Calib.h:65
double const _a
Definition: RandomImage.cc:77
int stripCalibKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Calib-related keywords from the metadata.
Definition: Calib.cc:96
afw::table::Key< afw::table::Array< ImagePixelT > > image