LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
_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
41namespace py = pybind11;
42using namespace pybind11::literals;
43
44namespace lsst {
45namespace afw {
46namespace image {
47namespace {
48
49void declareMeasurement(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
65void declarePhotoCalib(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_property_readonly("_isConstant", &PhotoCalib::isConstant);
166 cls.def("getInstFluxAtZeroMagnitude", &PhotoCalib::getInstFluxAtZeroMagnitude);
167 cls.def("getLocalCalibration", &PhotoCalib::getLocalCalibration, "point"_a);
168
169 cls.def("computeScaledCalibration", &PhotoCalib::computeScaledCalibration);
170 cls.def("computeScalingTo", &PhotoCalib::computeScalingTo);
171
172 cls.def("calibrateImage", &PhotoCalib::calibrateImage, "maskedImage"_a,
173 "includeScaleUncertainty"_a = true);
174
175 cls.def("calibrateCatalog",
176 py::overload_cast<afw::table::SourceCatalog const &,
177 std::vector<std::string> const &>(&PhotoCalib::calibrateCatalog,
178 py::const_),
179 "maskedImage"_a, "fluxFields"_a);
180 cls.def("calibrateCatalog",
181 py::overload_cast<afw::table::SourceCatalog const &>(&PhotoCalib::calibrateCatalog,
182 py::const_),
183 "maskedImage"_a);
184
185 /* Operators */
186 cls.def("__eq__", &PhotoCalib::operator==, py::is_operator());
187 cls.def("__ne__", &PhotoCalib::operator!=, py::is_operator());
188 utils::python::addOutputOp(cls, "__str__");
189 cls.def("__repr__", [](PhotoCalib const &self) {
190 std::ostringstream os;
191 os << "PhotoCalib(" << self << ")";
192 return os.str();
193 });
194 });
195}
196
197void declareCalib(lsst::utils::python::WrapperCollection &wrappers) {
198 wrappers.wrap([](auto &mod) {
199 /* Utility functions */
200 mod.def("makePhotoCalibFromMetadata",
201 py::overload_cast<daf::base::PropertySet &, bool>(makePhotoCalibFromMetadata), "metadata"_a,
202 "strip"_a = false);
203 mod.def("makePhotoCalibFromCalibZeroPoint",
204 py::overload_cast<double, double>(makePhotoCalibFromCalibZeroPoint), "instFluxMag0"_a,
205 "instFluxMag0Err"_a = false);
206 });
207}
208} // namespace
209void wrapPhotoCalib(lsst::utils::python::WrapperCollection &wrappers) {
210 wrappers.addInheritanceDependency("lsst.afw.typehandling");
211 declareMeasurement(wrappers);
212 declarePhotoCalib(wrappers);
213 declareCalib(wrappers);
214}
215} // namespace image
216} // namespace afw
217} // namespace lsst
Implementation of the Photometric Calibration class.
void wrapPhotoCalib(lsst::utils::python::WrapperCollection &)
Definition: _photoCalib.cc:209