LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+4b710797af,21.0.0-1-gfc31b0f+3b24369756,21.0.0-10-g2408eff+50e97f2f47,21.0.0-10-g560fb7b+0803ad37c5,21.0.0-10-g5daeb2b+f9b8dc6d5a,21.0.0-10-g8d1d15d+77a6b82ebf,21.0.0-10-gcf60f90+c961be884d,21.0.0-11-g25eff31+7692554667,21.0.0-17-g6590b197+a14a01c114,21.0.0-2-g103fe59+b79afc2051,21.0.0-2-g1367e85+1003a3501c,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+1003a3501c,21.0.0-2-g7f82c8f+c2a1919b98,21.0.0-2-g8f08a60+fd0b970de5,21.0.0-2-ga326454+c2a1919b98,21.0.0-2-gde069b7+ca45a81b40,21.0.0-2-gecfae73+afcaaec585,21.0.0-2-gfc62afb+1003a3501c,21.0.0-21-g5d80ea29e+5e3c9a3766,21.0.0-3-g357aad2+c67f36f878,21.0.0-3-g4be5c26+1003a3501c,21.0.0-3-g65f322c+02b1f88459,21.0.0-3-g7d9da8d+3b24369756,21.0.0-3-ge02ed75+a423c2ae7a,21.0.0-4-g591bb35+a423c2ae7a,21.0.0-4-g65b4814+0803ad37c5,21.0.0-4-g88306b8+199c7497e5,21.0.0-4-gccdca77+a631590478,21.0.0-4-ge8a399c+b923ff878e,21.0.0-5-gd00fb1e+d8b1e95daa,21.0.0-53-ge728e5d5+3cb64fea8e,21.0.0-6-g2d4f3f3+04719a4bac,21.0.0-7-g04766d7+8d320c19d5,21.0.0-7-g98eecf7+205433fbda,21.0.0-9-g39e06b5+a423c2ae7a,master-gac4afde19b+a423c2ae7a,w.2021.11
LSST Data Management Base Package
photoCalib.cc
Go to the documentation of this file.
1 /*
2  * This file is part of afw.
3  *
4  * Developed for the LSST Data Management System.
5  * This product includes software developed by the LSST Project
6  * (https://www.lsst.org).
7  * See the COPYRIGHT file at the top-level directory of this distribution
8  * for details of code ownership.
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 GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #include "pybind11/pybind11.h"
25 #include "pybind11/stl.h"
26 #include "lsst/utils/python.h"
27 
28 #include <memory>
29 
30 #include "ndarray/pybind11.h"
31 
32 #include "lsst/utils/python.h"
33 
37 #include "lsst/afw/table/io/python.h" // for addPersistableMethods
40 
41 namespace py = pybind11;
42 using namespace pybind11::literals;
43 
44 namespace lsst {
45 namespace afw {
46 namespace image {
47 namespace {
48 
49 void wrapMeasurement(lsst::utils::python::WrapperCollection &wrappers) {
50  wrappers.wrapType(py::class_<Measurement, std::shared_ptr<Measurement>>(wrappers.module, "Measurement"),
51  [](auto &mod, auto &cls) {
52  cls.def(py::init<double, double>(), "value"_a, "error"_a);
53  cls.def_readonly("value", &Measurement::value);
54  cls.def_readonly("error", &Measurement::error);
55 
56  utils::python::addOutputOp(cls, "__str__");
57  cls.def("__repr__", [](Measurement const &self) {
58  std::ostringstream os;
59  os << "Measurement(" << self << ")";
60  return os.str();
61  });
62  });
63 }
64 
65 void wrapPhotoCalib(lsst::utils::python::WrapperCollection &wrappers) {
66  wrappers.wrapType(
67  py::class_<PhotoCalib, std::shared_ptr<PhotoCalib>, typehandling::Storable>(wrappers.module,
68  "PhotoCalib"),
69  [](auto &mod, auto &cls) {
70  /* Constructors */
71  cls.def(py::init<>());
72  cls.def(py::init<double, double, lsst::geom::Box2I>(), "calibrationMean"_a,
73  "calibrationErr"_a = 0.0, "bbox"_a = lsst::geom::Box2I());
74  cls.def(py::init<std::shared_ptr<afw::math::BoundedField>, double>(), "calibration"_a,
75  "calibrationErr"_a = 0.0);
76  cls.def(py::init<double, double, std::shared_ptr<afw::math::BoundedField>, bool>(),
77  "calibrationMean"_a, "calibrationErr"_a, "calibration"_a, "isConstant"_a);
78 
79  table::io::python::addPersistableMethods<PhotoCalib>(cls);
80 
81  /* Members - nanojansky */
82  cls.def("instFluxToNanojansky",
83  (double (PhotoCalib::*)(double, lsst::geom::Point<double, 2> const &) const) &
84  PhotoCalib::instFluxToNanojansky,
85  "instFlux"_a, "point"_a);
86  cls.def("instFluxToNanojansky",
87  (double (PhotoCalib::*)(double) const) & PhotoCalib::instFluxToNanojansky,
88  "instFlux"_a);
89 
90  cls.def("instFluxToNanojansky",
91  (Measurement(PhotoCalib::*)(double, double, lsst::geom::Point<double, 2> const &)
92  const) &
93  PhotoCalib::instFluxToNanojansky,
94  "instFlux"_a, "instFluxErr"_a, "point"_a);
95  cls.def("instFluxToNanojansky",
96  (Measurement(PhotoCalib::*)(double, double) const) & PhotoCalib::instFluxToNanojansky,
97  "instFlux"_a, "instFluxErr"_a);
98 
99  cls.def("instFluxToNanojansky",
100  (Measurement(PhotoCalib::*)(afw::table::SourceRecord const &, std::string const &)
101  const) &
102  PhotoCalib::instFluxToNanojansky,
103  "sourceRecord"_a, "instFluxField"_a);
104 
105  cls.def("instFluxToNanojansky",
106  (ndarray::Array<double, 2, 2>(PhotoCalib::*)(afw::table::SourceCatalog const &,
107  std::string const &) const) &
108  PhotoCalib::instFluxToNanojansky,
109  "sourceCatalog"_a, "instFluxField"_a);
110 
111  cls.def("instFluxToNanojansky",
112  (void (PhotoCalib::*)(afw::table::SourceCatalog &, std::string const &,
113  std::string const &) const) &
114  PhotoCalib::instFluxToNanojansky,
115  "sourceCatalog"_a, "instFluxField"_a, "outField"_a);
116 
117  /* Members - magnitudes */
118  cls.def("instFluxToMagnitude",
119  (double (PhotoCalib::*)(double, lsst::geom::Point<double, 2> const &) const) &
120  PhotoCalib::instFluxToMagnitude,
121  "instFlux"_a, "point"_a);
122  cls.def("instFluxToMagnitude",
123  (double (PhotoCalib::*)(double) const) & PhotoCalib::instFluxToMagnitude,
124  "instFlux"_a);
125 
126  cls.def("instFluxToMagnitude",
127  (Measurement(PhotoCalib::*)(double, double, lsst::geom::Point<double, 2> const &)
128  const) &
129  PhotoCalib::instFluxToMagnitude,
130  "instFlux"_a, "instFluxErr"_a, "point"_a);
131  cls.def("instFluxToMagnitude",
132  (Measurement(PhotoCalib::*)(double, double) const) & PhotoCalib::instFluxToMagnitude,
133  "instFlux"_a, "instFluxErr"_a);
134 
135  cls.def("instFluxToMagnitude",
136  (Measurement(PhotoCalib::*)(afw::table::SourceRecord const &, std::string const &)
137  const) &
138  PhotoCalib::instFluxToMagnitude,
139  "sourceRecord"_a, "instFluxField"_a);
140 
141  cls.def("instFluxToMagnitude",
142  (ndarray::Array<double, 2, 2>(PhotoCalib::*)(afw::table::SourceCatalog const &,
143  std::string const &) const) &
144  PhotoCalib::instFluxToMagnitude,
145  "sourceCatalog"_a, "instFluxField"_a);
146 
147  cls.def("instFluxToMagnitude",
148  (void (PhotoCalib::*)(afw::table::SourceCatalog &, std::string const &,
149  std::string const &) const) &
150  PhotoCalib::instFluxToMagnitude,
151  "sourceCatalog"_a, "instFluxField"_a, "outField"_a);
152 
153  /* from magnitude. */
154  cls.def("magnitudeToInstFlux",
155  py::overload_cast<double, lsst::geom::Point<double, 2> const &>(
156  &PhotoCalib::magnitudeToInstFlux, py::const_),
157  "instFlux"_a, "point"_a);
158  cls.def("magnitudeToInstFlux",
159  py::overload_cast<double>(&PhotoCalib::magnitudeToInstFlux, py::const_),
160  "instFlux"_a);
161 
162  /* utilities */
163  cls.def("getCalibrationMean", &PhotoCalib::getCalibrationMean);
164  cls.def("getCalibrationErr", &PhotoCalib::getCalibrationErr);
165  cls.def("getInstFluxAtZeroMagnitude", &PhotoCalib::getInstFluxAtZeroMagnitude);
166  cls.def("getLocalCalibration", &PhotoCalib::getLocalCalibration, "point"_a);
167 
168  cls.def("computeScaledCalibration", &PhotoCalib::computeScaledCalibration);
169  cls.def("computeScalingTo", &PhotoCalib::computeScalingTo);
170 
171  cls.def("calibrateImage", &PhotoCalib::calibrateImage, "maskedImage"_a,
172  "includeScaleUncertainty"_a = true);
173 
174  cls.def("calibrateCatalog",
175  py::overload_cast<afw::table::SourceCatalog const &,
176  std::vector<std::string> const &>(&PhotoCalib::calibrateCatalog,
177  py::const_),
178  "maskedImage"_a, "fluxFields"_a);
179  cls.def("calibrateCatalog",
180  py::overload_cast<afw::table::SourceCatalog const &>(&PhotoCalib::calibrateCatalog,
181  py::const_),
182  "maskedImage"_a);
183 
184  /* Operators */
185  cls.def("__eq__", &PhotoCalib::operator==, py::is_operator());
186  cls.def("__ne__", &PhotoCalib::operator!=, py::is_operator());
187  utils::python::addOutputOp(cls, "__str__");
188  cls.def("__repr__", [](PhotoCalib const &self) {
189  std::ostringstream os;
190  os << "PhotoCalib(" << self << ")";
191  return os.str();
192  });
193  });
194 }
195 
196 void wrapCalib(lsst::utils::python::WrapperCollection &wrappers) {
197  wrappers.wrap([](auto &mod) {
198  /* Utility functions */
199  mod.def("makePhotoCalibFromMetadata",
200  py::overload_cast<daf::base::PropertySet &, bool>(makePhotoCalibFromMetadata), "metadata"_a,
201  "strip"_a = false);
202  mod.def("makePhotoCalibFromCalibZeroPoint",
203  py::overload_cast<double, double>(makePhotoCalibFromCalibZeroPoint), "instFluxMag0"_a,
204  "instFluxMag0Err"_a = false);
205  });
206 }
207 
209  lsst::utils::python::WrapperCollection wrappers(mod, "lsst.afw.image.photoCalib");
210  wrappers.addInheritanceDependency("lsst.afw.typehandling");
211  wrapMeasurement(wrappers);
212  wrapPhotoCalib(wrappers);
213  wrapCalib(wrappers);
214  wrappers.finish();
215 }
216 } // namespace
217 } // namespace image
218 } // namespace afw
219 } // namespace lsst
Implementation of the Photometric Calibration class.
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition: python.h:242
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition: python.h:448
void finish()
Invoke all deferred wrapper-declaring callables.
Definition: python.h:435
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
Definition: python.h:391
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
Definition: python.h:343
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
Definition: python.h:369
PYBIND11_MODULE(imageUtils, mod)
Definition: imageUtils.cc:33
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
std::shared_ptr< PhotoCalib > makePhotoCalibFromCalibZeroPoint(double instFluxMag0, double instFluxMag0Err)
Construct a PhotoCalib from the deprecated Calib-style instFluxMag0/instFluxMag0Err values.
Definition: PhotoCalib.cc:614
std::shared_ptr< PhotoCalib > makePhotoCalibFromMetadata(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
Definition: PhotoCalib.cc:596
A base class for image defects.
Key< int > photoCalib
Definition: Exposure.cc:67