LSST Applications g013ef56533+d2224463a4,g199a45376c+0ba108daf9,g19c4beb06c+9f335b2115,g1fd858c14a+2459ca3e43,g210f2d0738+2d3d333a78,g262e1987ae+abbb004f04,g2825c19fe3+eedc38578d,g29ae962dfc+0cb55f06ef,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+19c3a54948,g47891489e3+501a489530,g4cdb532a89+a047e97985,g511e8cfd20+ce1f47b6d6,g53246c7159+8c5ae1fdc5,g54cd7ddccb+890c8e1e5d,g5fd55ab2c7+951cc3f256,g64539dfbff+2d3d333a78,g67b6fd64d1+501a489530,g67fd3c3899+2d3d333a78,g74acd417e5+0ea5dee12c,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+501a489530,g8d7436a09f+5ea4c44d25,g8ea07a8fe4+81eaaadc04,g90f42f885a+34c0557caf,g9486f8a5af+165c016931,g97be763408+d5e351dcc8,gbf99507273+8c5ae1fdc5,gc2a301910b+2d3d333a78,gca7fc764a6+501a489530,gce8aa8abaa+8c5ae1fdc5,gd7ef33dd92+501a489530,gdab6d2f7ff+0ea5dee12c,ge410e46f29+501a489530,geaed405ab2+e3b4b2a692,gf9a733ac38+8c5ae1fdc5,w.2025.41
LSST Data Management Base Package
Loading...
Searching...
No Matches
gaussian.cc
Go to the documentation of this file.
1/*
2 * This file is part of gauss2d.
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#include <pybind11/operators.h>
28#include <pybind11/stl.h>
29
31
32#include "pybind11.h"
33
34#define PYBIND11_DETAILED_ERROR_MESSAGES
35
36namespace py = pybind11;
37using namespace pybind11::literals;
38
39namespace gauss2d = lsst::gauss2d;
40
41void bind_gaussian(py::module &m) {
42 m.doc() = "Gauss2D Gaussian Python bindings";
43
44 m.attr("M_HWHM_SIGMA") = py::float_(gauss2d::M_HWHM_SIGMA);
45 m.attr("M_SIGMA_HWHM") = py::float_(gauss2d::M_SIGMA_HWHM);
46
47 auto _g = py::classh<gauss2d::GaussianIntegral>(m, "GaussianIntegral");
48 py::classh<gauss2d::GaussianIntegralValue, gauss2d::GaussianIntegral>(m, "GaussianIntegralValue")
49 .def(py::init<double>(), "value"_a = 1)
50 .def_property("value", &gauss2d::GaussianIntegralValue::get_value,
52 .def(py::self == py::self)
53 .def(py::self != py::self)
54 .def("__repr__",
55 [](const gauss2d::GaussianIntegralValue &self) {
56 return self.repr(true, self.PY_NAMESPACE_SEPARATOR);
57 })
59
60 py::classh<gauss2d::Gaussian>(m, "Gaussian")
63 "centroid"_a = nullptr, "ellipse"_a = nullptr, "integral"_a = nullptr)
64 .def_property_readonly("centroid", &gauss2d::Gaussian::get_centroid)
65 .def_property_readonly("ellipse", &gauss2d::Gaussian::get_ellipse)
66 .def_property_readonly("integral", &gauss2d::Gaussian::get_integral)
67 .def_property("const_normal", &gauss2d::Gaussian::get_const_normal,
69 .def_property("integral_value", &gauss2d::Gaussian::get_integral_value,
71 .def(py::self == py::self)
72 .def(py::self != py::self)
73 .def("__repr__",
74 [](const gauss2d::Gaussian &self) { return self.repr(true, self.PY_NAMESPACE_SEPARATOR); })
75 .def("__str__", &gauss2d::Gaussian::str);
76 py::classh<gauss2d::Gaussians>(m, "Gaussians")
77 .def(py::init<std::optional<const gauss2d::Gaussians::Data>>(), "gaussians"_a)
78 .def("at", &gauss2d::Gaussians::at, py::return_value_policy::copy)
79 .def_property_readonly("size", &gauss2d::Gaussians::size)
80 .def("__getitem__", &gauss2d::Gaussians::at_ptr, py::return_value_policy::copy)
81 .def("__len__", &gauss2d::Gaussians::size)
82 .def("__repr__",
83 [](const gauss2d::Gaussians &self) { return self.repr(true, self.PY_NAMESPACE_SEPARATOR); })
84 .def("__str__", &gauss2d::Gaussians::str);
85 py::classh<gauss2d::ConvolvedGaussian>(m, "ConvolvedGaussian")
87 "source"_a = nullptr, "kernel"_a = nullptr)
88 .def_property_readonly("kernel", &gauss2d::ConvolvedGaussian::get_kernel)
89 .def_property_readonly("source", &gauss2d::ConvolvedGaussian::get_source)
90 .def(py::self == py::self)
91 .def(py::self != py::self)
92 .def("__repr__",
93 [](const gauss2d::ConvolvedGaussian &self) {
94 return self.repr(true, self.PY_NAMESPACE_SEPARATOR);
95 })
96 .def("__str__", &gauss2d::ConvolvedGaussian::str);
97 py::classh<gauss2d::ConvolvedGaussians>(m, "ConvolvedGaussians")
98 .def(py::init<std::optional<const gauss2d::ConvolvedGaussians::Data>>(), "convolvedbgaussians"_a)
99 .def("at", &gauss2d::ConvolvedGaussians::at_ptr, py::return_value_policy::copy)
100 .def_property_readonly("size", &gauss2d::ConvolvedGaussians::size)
101 .def("__getitem__", &gauss2d::ConvolvedGaussians::at_ptr, py::return_value_policy::copy)
102 .def("__len__", &gauss2d::ConvolvedGaussians::size)
103 .def("__repr__",
104 [](const gauss2d::ConvolvedGaussians &self) {
105 return self.repr(true, self.PY_NAMESPACE_SEPARATOR);
106 })
107 .def("__str__", &gauss2d::ConvolvedGaussians::str);
108}
A convolution of a Gaussian source and kernel.
Definition gaussian.h:220
const Gaussian & get_source() const
Definition gaussian.cc:222
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:239
const Gaussian & get_kernel() const
Definition gaussian.cc:223
A collection of ConvolvedGaussian objects.
Definition gaussian.h:249
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:282
std::shared_ptr< ConvolvedGaussian > at_ptr(size_t i) const
Definition gaussian.cc:252
A 2D Gaussian with a Centroid, Ellipse, and integral.
Definition gaussian.h:99
Ellipse & get_ellipse()
Get the ellipse object.
Definition gaussian.cc:58
void set_const_normal(double const_normal)
Definition gaussian.cc:69
GaussianIntegral & get_integral()
Get the integral object.
Definition gaussian.cc:59
double get_integral_value() const
Get the integral value.
Definition gaussian.cc:55
void set_integral_value(double integral)
Definition gaussian.cc:72
double get_const_normal() const
Get the multiplicative factor for Gaussian function evaluations: integral/(2*area)
Definition gaussian.cc:54
Centroid & get_centroid()
Get the centroid object.
Definition gaussian.cc:57
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:91
A GaussianIntegral storing a float value.
Definition gaussian.h:72
double get_value() const override
Definition gaussian.h:79
void set_value(double value) override
Definition gaussian.h:80
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:43
std::string repr(bool name_keywords=false, std::string_view namespace_separator=Object::CC_NAMESPACE_SEPARATOR) const override
Return a full, callable string representation of this.
Definition gaussian.cc:39
An array of Gaussian objects.
Definition gaussian.h:175
Gaussian & at(size_t i) const
Definition gaussian.cc:148
std::shared_ptr< Gaussian > at_ptr(size_t i) const
Definition gaussian.cc:150
size_t size() const
Definition gaussian.cc:162
std::string str() const override
Return a brief, human-readable string representation of this.
Definition gaussian.cc:171
static constexpr std::string_view PY_NAMESPACE_SEPARATOR
Definition object.h:47
const double M_SIGMA_HWHM
Definition ellipse.h:39
const double M_HWHM_SIGMA
Definition ellipse.h:38
void bind_gaussian(py::module &m)
Definition gaussian.cc:41