LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+b203dec576,g18429d2f64+358861cd2c,g199a45376c+0ba108daf9,g1fd858c14a+dd066899e3,g262e1987ae+ebfced1d55,g29ae962dfc+72fd90588e,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+b668f15bc5,g4595892280+3897dae354,g47891489e3+abcf9c3559,g4d44eb3520+fb4ddce128,g53246c7159+8c5ae1fdc5,g67b6fd64d1+abcf9c3559,g67fd3c3899+1f72b5a9f7,g74acd417e5+cb6b47f07b,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+abcf9c3559,g8d7436a09f+bcf525d20c,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+6054cc57f1,g97be763408+06f794da49,g9dd6db0277+1f72b5a9f7,ga681d05dcb+7e36ad54cd,gabf8522325+735880ea63,gac2eed3f23+abcf9c3559,gb89ab40317+abcf9c3559,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+1f72b5a9f7,gdab6d2f7ff+cb6b47f07b,gdc713202bf+1f72b5a9f7,gdfd2d52018+8225f2b331,ge365c994fd+375fc21c71,ge410e46f29+abcf9c3559,geaed405ab2+562b3308c0,gf9a733ac38+8c5ae1fdc5,w.2025.35
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