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
_psf.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 <memory>
25
26#include <pybind11/pybind11.h>
27
28#include "lsst/utils/python.h"
30
31#include "lsst/geom/Point.h"
33#include "lsst/afw/table/io/python.h" // for addPersistableMethods
37
38namespace py = pybind11;
39using namespace pybind11::literals;
40
41using lsst::utils::python::PySharedPtr;
42
43namespace lsst {
44namespace afw {
45namespace detection {
46
47
48void wrapPsf(utils::python::WrapperCollection& wrappers) {
49 wrappers.addInheritanceDependency("lsst.afw.typehandling");
50 wrappers.addSignatureDependency("lsst.afw.geom.ellipses");
51 wrappers.addSignatureDependency("lsst.afw.image");
52 wrappers.addSignatureDependency("lsst.afw.fits");
53
54 auto clsPsf = wrappers.wrapType(
55 py::class_<Psf, PySharedPtr<Psf>, typehandling::Storable, PsfTrampoline<>>(
56 wrappers.module, "Psf"
57 ),
58 [](auto& mod, auto& cls) {
59 table::io::python::addPersistableMethods<Psf>(cls);
60 cls.def(py::init<bool, size_t>(), "isFixed"_a=false, "capacity"_a=100); // Constructor for pure-Python subclasses
61 cls.def("clone", &Psf::clone);
62 cls.def("resized", &Psf::resized, "width"_a, "height"_a);
63
64 // Position-required overloads. Can (likely) remove overload_cast<> once deprecation period for
65 // default position argument ends.
66 cls.def("computeImage",
67 py::overload_cast<lsst::geom::Point2D, image::Color, Psf::ImageOwnerEnum>(&Psf::computeImage, py::const_),
68 "position"_a,
69 "color"_a = image::Color(),
70 "owner"_a = Psf::ImageOwnerEnum::COPY
71 );
72 cls.def("computeKernelImage",
73 py::overload_cast<lsst::geom::Point2D, image::Color, Psf::ImageOwnerEnum>(&Psf::computeKernelImage, py::const_),
74 "position"_a,
75 "color"_a = image::Color(),
76 "owner"_a = Psf::ImageOwnerEnum::COPY
77 );
78 cls.def("computePeak",
79 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computePeak, py::const_),
80 "position"_a,
81 "color"_a = image::Color()
82 );
83 cls.def("computeApertureFlux",
84 py::overload_cast<double, lsst::geom::Point2D, image::Color>(&Psf::computeApertureFlux, py::const_),
85 "radius"_a,
86 "position"_a,
87 "color"_a = image::Color()
88 );
89 cls.def("computeShape",
90 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeShape, py::const_),
91 "position"_a,
92 "color"_a = image::Color()
93 );
94 cls.def("computeBBox",
95 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeBBox, py::const_),
96 "position"_a,
97 "color"_a = image::Color()
98 );
99 cls.def("computeImageBBox",
100 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeImageBBox, py::const_),
101 "position"_a,
102 "color"_a = image::Color()
103 );
104 cls.def("computeKernelBBox",
105 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::computeKernelBBox, py::const_),
106 "position"_a,
107 "color"_a = image::Color()
108 );
109 cls.def("getLocalKernel",
110 py::overload_cast<lsst::geom::Point2D, image::Color>(&Psf::getLocalKernel, py::const_),
111 "position"_a,
112 "color"_a = image::Color()
113 );
114
115 // Deprecated default position argument overloads.
116 cls.def("computeImage",
117 [](const Psf& psf) {
118 py::gil_scoped_acquire gil;
119 auto warnings = py::module::import("warnings");
120 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
121 warnings.attr("warn")(
122 "Default position argument overload is deprecated and will be "
123 "removed in version 24.0. Please explicitly specify a position.",
124 "category"_a=FutureWarning
125 );
126 return psf.computeImage();
127 }
128 );
129 cls.def("computeKernelImage",
130 [](const Psf& psf) {
131 py::gil_scoped_acquire gil;
132 auto warnings = py::module::import("warnings");
133 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
134 warnings.attr("warn")(
135 "Default position argument overload is deprecated and will be "
136 "removed in version 24.0. Please explicitly specify a position.",
137 "category"_a=FutureWarning
138 );
139 return psf.computeKernelImage();
140 }
141 );
142 cls.def("computePeak",
143 [](const Psf& psf) {
144 py::gil_scoped_acquire gil;
145 auto warnings = py::module::import("warnings");
146 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
147 warnings.attr("warn")(
148 "Default position argument overload is deprecated and will be "
149 "removed in version 24.0. Please explicitly specify a position.",
150 "category"_a=FutureWarning
151 );
152 return psf.computePeak();
153 }
154 );
155 cls.def("computeApertureFlux",
156 [](const Psf& psf, double radius) {
157 py::gil_scoped_acquire gil;
158 auto warnings = py::module::import("warnings");
159 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
160 warnings.attr("warn")(
161 "Default position argument overload is deprecated and will be "
162 "removed in version 24.0. Please explicitly specify a position.",
163 "category"_a=FutureWarning
164 );
165 return psf.computeApertureFlux(radius);
166 },
167 "radius"_a
168 );
169 cls.def("computeShape",
170 [](const Psf& psf) {
171 py::gil_scoped_acquire gil;
172 auto warnings = py::module::import("warnings");
173 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
174 warnings.attr("warn")(
175 "Default position argument overload is deprecated and will be "
176 "removed in version 24.0. Please explicitly specify a position.",
177 "category"_a=FutureWarning
178 );
179 return psf.computeShape();
180 }
181 );
182 cls.def("computeBBox",
183 [](const Psf& psf) {
184 py::gil_scoped_acquire gil;
185 auto warnings = py::module::import("warnings");
186 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
187 warnings.attr("warn")(
188 "Default position argument overload is deprecated and will be "
189 "removed in version 24.0. Please explicitly specify a position.",
190 "category"_a=FutureWarning
191 );
192 return psf.computeBBox();
193 }
194 );
195 cls.def("computeImageBBox",
196 [](const Psf& psf) {
197 py::gil_scoped_acquire gil;
198 auto warnings = py::module::import("warnings");
199 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
200 warnings.attr("warn")(
201 "Default position argument overload is deprecated and will be "
202 "removed in version 24.0. Please explicitly specify a position.",
203 "category"_a=FutureWarning
204 );
205 return psf.computeImageBBox();
206 }
207 );
208 cls.def("computeKernelBBox",
209 [](const Psf& psf) {
210 py::gil_scoped_acquire gil;
211 auto warnings = py::module::import("warnings");
212 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
213 warnings.attr("warn")(
214 "Default position argument overload is deprecated and will be "
215 "removed in version 24.0. Please explicitly specify a position.",
216 "category"_a=FutureWarning
217 );
218 return psf.computeKernelBBox();
219 }
220 );
221 cls.def("getLocalKernel",
222 [](const Psf& psf) {
223 py::gil_scoped_acquire gil;
224 auto warnings = py::module::import("warnings");
225 auto FutureWarning = py::handle(PyEval_GetBuiltins())["FutureWarning"];
226 warnings.attr("warn")(
227 "Default position argument overload is deprecated and will be "
228 "removed in version 24.0. Please explicitly specify a position.",
229 "category"_a=FutureWarning
230 );
231 return psf.getLocalKernel();
232 }
233 );
234 // End deprecated default position argument overloads.
235
236 cls.def("getAverageColor", &Psf::getAverageColor);
237 cls.def("getAveragePosition", &Psf::getAveragePosition);
238 cls.def_static("recenterKernelImage", &Psf::recenterKernelImage, "im"_a, "position"_a,
239 "warpAlgorithm"_a = "lanczos5", "warpBuffer"_a = 5);
240 cls.def("getCacheCapacity", &Psf::getCacheCapacity);
241 cls.def("setCacheCapacity", &Psf::setCacheCapacity);
242 }
243 );
244
245 wrappers.wrapType(py::enum_<Psf::ImageOwnerEnum>(clsPsf, "ImageOwnerEnum"), [](auto& mod, auto& enm) {
246 enm.value("COPY", Psf::ImageOwnerEnum::COPY);
247 enm.value("INTERNAL", Psf::ImageOwnerEnum::INTERNAL);
248 enm.export_values();
249 });
250}
251
252} // namespace detection
253} // namespace afw
254} // namespace lsst
A polymorphic base class for representing an image's Point Spread Function.
Definition: Psf.h:76
static std::shared_ptr< Image > recenterKernelImage(std::shared_ptr< Image > im, lsst::geom::Point2D const &position, std::string const &warpAlgorithm="lanczos5", unsigned int warpBuffer=5)
Helper function for Psf::doComputeImage(): converts a kernel image (centered at (0,...
Definition: Psf.cc:85
std::size_t getCacheCapacity() const
Return the capacity of the caches.
Definition: Psf.cc:223
image::Color getAverageColor() const
Return the average Color of the stars used to construct the Psf.
Definition: Psf.h:274
@ COPY
The image will be copied before returning; caller will own it.
Definition: Psf.h:87
@ INTERNAL
An internal image will be returned without copying.
Definition: Psf.h:88
void setCacheCapacity(std::size_t capacity)
Set the capacity of the caches.
Definition: Psf.cc:225
virtual lsst::geom::Point2D getAveragePosition() const
Return the average position of the stars used to construct the Psf.
Definition: Psf.cc:221
"Trampoline" for Psf to let it be used as a base class in Python.
Definition: python.h:50
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
void wrapPsf(WrapperCollection &)
Key< int > psf
Definition: Exposure.cc:65