lsst.afw  13.0-92-g8ecf155+1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
photoCalib.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 
28 #include "numpy/arrayobject.h"
29 #include "ndarray/pybind11.h"
30 
31 #include "lsst/daf/base/PropertySet.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 void declareMeasurement(py::module &mod) {
46  py::class_<Measurement, std::shared_ptr<Measurement>> cls(mod, "Measurement");
47 
48  cls.def(py::init<double, double>(), "value"_a, "err"_a);
49  cls.def_readonly("value", &Measurement::value);
50  cls.def_readonly("err", &Measurement::err);
51 }
52 
53 PYBIND11_PLUGIN(photoCalib) {
54  py::module mod("photoCalib");
55  py::module::import("lsst.afw.table.io");
56 
57  if (_import_array() < 0) {
58  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
59  return nullptr;
60  };
61 
62  table::io::python::declarePersistableFacade<PhotoCalib>(mod, "PhotoCalib");
63 
64  declareMeasurement(mod);
65 
66  py::class_<PhotoCalib, std::shared_ptr<PhotoCalib>, table::io::PersistableFacade<PhotoCalib>,
67  table::io::Persistable>
68  cls(mod, "PhotoCalib");
69 
70  /* Constructors */
71  cls.def(py::init<>());
72  cls.def(py::init<double, double, afw::geom::Box2I>(), "instFluxMag0"_a, "instFluxMag0Err"_a = 0.0,
73  "bbox"_a = afw::geom::Box2I());
74  cls.def(py::init<std::shared_ptr<afw::math::BoundedField>, double>(), "zeroPoint"_a,
75  "instFluxMag0Err"_a = 0.0);
76  cls.def(py::init<double, double, std::shared_ptr<afw::math::BoundedField>, bool>(), "instFluxMag0"_a,
77  "instFluxMag0Err"_a, "zeroPoint"_a, "isConstant"_a);
78 
79  /* Members - maggies */
80  cls.def("instFluxToMaggies", (double (PhotoCalib::*)(double, afw::geom::Point<double, 2> const &) const) &
81  PhotoCalib::instFluxToMaggies,
82  "instFlux"_a, "point"_a);
83  cls.def("instFluxToMaggies", (double (PhotoCalib::*)(double) const) & PhotoCalib::instFluxToMaggies,
84  "instFlux"_a);
85 
86  cls.def("instFluxToMaggies",
87  (Measurement (PhotoCalib::*)(double, double, afw::geom::Point<double, 2> const &) const) &
88  PhotoCalib::instFluxToMaggies,
89  "instFlux"_a, "instFluxErr"_a, "point"_a);
90  cls.def("instFluxToMaggies",
91  (Measurement (PhotoCalib::*)(double, double) const) & PhotoCalib::instFluxToMaggies, "instFlux"_a,
92  "instFluxErr"_a);
93 
94  cls.def("instFluxToMaggies",
95  (Measurement (PhotoCalib::*)(afw::table::SourceRecord const &, std::string const &) const) &
96  PhotoCalib::instFluxToMaggies,
97  "sourceRecord"_a, "instFluxField"_a);
98 
99  cls.def("instFluxToMaggies", (ndarray::Array<double, 2, 2> (PhotoCalib::*)(
100  afw::table::SourceCatalog const &, std::string const &) const) &
101  PhotoCalib::instFluxToMaggies,
102  "sourceCatalog"_a, "instFluxField"_a);
103 
104  cls.def("instFluxToMaggies", (void (PhotoCalib::*)(afw::table::SourceCatalog &, std::string const &,
105  std::string const &) const) &
106  PhotoCalib::instFluxToMaggies,
107  "sourceCatalog"_a, "instFluxField"_a, "outField"_a);
108 
109  /* Members - magnitudes */
110  cls.def("instFluxToMagnitude",
111  (double (PhotoCalib::*)(double, afw::geom::Point<double, 2> const &) const) &
112  PhotoCalib::instFluxToMagnitude,
113  "instFlux"_a, "point"_a);
114  cls.def("instFluxToMagnitude", (double (PhotoCalib::*)(double) const) & PhotoCalib::instFluxToMagnitude,
115  "instFlux"_a);
116 
117  cls.def("instFluxToMagnitude",
118  (Measurement (PhotoCalib::*)(double, double, afw::geom::Point<double, 2> const &) const) &
119  PhotoCalib::instFluxToMagnitude,
120  "instFlux"_a, "instFluxErr"_a, "point"_a);
121  cls.def("instFluxToMagnitude",
122  (Measurement (PhotoCalib::*)(double, double) const) & PhotoCalib::instFluxToMagnitude,
123  "instFlux"_a, "instFluxErr"_a);
124 
125  cls.def("instFluxToMagnitude",
126  (Measurement (PhotoCalib::*)(afw::table::SourceRecord const &, std::string const &) const) &
127  PhotoCalib::instFluxToMagnitude,
128  "sourceRecord"_a, "instFluxField"_a);
129 
130  cls.def("instFluxToMagnitude", (ndarray::Array<double, 2, 2> (PhotoCalib::*)(
131  afw::table::SourceCatalog const &, std::string const &) const) &
132  PhotoCalib::instFluxToMagnitude,
133  "sourceCatalog"_a, "instFluxField"_a);
134 
135  cls.def("instFluxToMagnitude", (void (PhotoCalib::*)(afw::table::SourceCatalog &, std::string const &,
136  std::string const &) const) &
137  PhotoCalib::instFluxToMagnitude,
138  "sourceCatalog"_a, "instFluxField"_a, "outField"_a);
139 
140  /* utilities */
141  cls.def("getInstFluxMag0", &PhotoCalib::getInstFluxMag0);
142  cls.def("getInstFluxMag0Err", &PhotoCalib::getInstFluxMag0Err);
143 
144  cls.def("magnitudeToInstFlux", (double (PhotoCalib::*)(double) const) & PhotoCalib::magnitudeToInstFlux,
145  "magnitude"_a);
146 
147  cls.def("computeScaledZeroPoint", &PhotoCalib::computeScaledZeroPoint);
148  cls.def("computeScalingTo", &PhotoCalib::computeScalingTo);
149 
150  /* Operators */
151  cls.def("__eq__", &PhotoCalib::operator==, py::is_operator());
152  cls.def("__ne__", &PhotoCalib::operator!=, py::is_operator());
153 
154  cls.def("__str__", [](PhotoCalib const &self) {
155  std::ostringstream os;
156  os << self;
157  return os.str();
158  });
159  cls.def("__repr__", [](PhotoCalib const &self) {
160  std::ostringstream os;
161  os << "PhotoCalib(" << self << ")";
162  return os.str();
163  });
164 
165  return mod.ptr();
166 }
167 }
168 }
169 }
170 } // namespace lsst::afw::image::<anonymous>
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
double const _a
Definition: RandomImage.cc:77
SortedCatalogT< SourceRecord > SourceCatalog
Definition: fwd.h:85
afw::table::Key< afw::table::Array< ImagePixelT > > image
Implementation of the Photometric Calibration class.