LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
_boundedField.cc
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 * Copyright 2008-2016 AURA/LSST.
4 *
5 * This product includes software developed by the
6 * LSST Project (http://www.lsst.org/).
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the LSST License Statement and
19 * the GNU General Public License along with this program. If not,
20 * see <https://www.lsstcorp.org/LegalNotices/>.
21 */
22
23#include <pybind11/pybind11.h>
24#include <pybind11/stl.h>
26
27#include <memory>
28
29#include "ndarray/pybind11.h"
30
32#include "lsst/geom/Point.h"
34#include "lsst/afw/table/io/python.h" // for addPersistableMethods
35
36namespace py = pybind11;
37
38using namespace lsst::afw::math;
39using namespace py::literals;
40
41namespace lsst {
42namespace afw {
43namespace math {
44namespace {
45
46using PyClass = py::class_<BoundedField, std::shared_ptr<BoundedField>>;
47
48template <typename PixelT>
49void declareTemplates(PyClass &cls) {
50 cls.def("fillImage", &BoundedField::fillImage<PixelT>, "image"_a, "overlapOnly"_a = false, "xStep"_a = 1,
51 "yStep"_a = 1);
52 cls.def("addToImage", &BoundedField::addToImage<PixelT>, "image"_a, "scaleBy"_a = 1.0,
53 "overlapOnly"_a = false, "xStep"_a = 1, "yStep"_a = 1);
54 cls.def("multiplyImage", &BoundedField::multiplyImage<PixelT>, "image"_a, "overlapOnly"_a = false,
55 "xStep"_a = 1, "yStep"_a = 1);
56 cls.def("divideImage", &BoundedField::divideImage<PixelT>, "image"_a, "overlapOnly"_a = false,
57 "xStep"_a = 1, "yStep"_a = 1);
58}
59} // namespace
61 wrappers.wrapType(PyClass(wrappers.module, "BoundedField"), [](auto &mod, auto &cls) {
62 table::io::python::addPersistableMethods<BoundedField>(cls);
63
64 cls.def(
65 "__rmul__", [](BoundedField &bf, double const scale) { return bf * scale; },
66 py::is_operator());
67 cls.def("__mul__", &BoundedField::operator*, py::is_operator());
68 cls.def("__truediv__", &BoundedField::operator/, py::is_operator());
69 cls.def("__eq__", &BoundedField::operator==, py::is_operator());
70 cls.def("__ne__", &BoundedField::operator!=, py::is_operator());
71
72 cls.def("evaluate", (double (BoundedField::*)(double, double) const) & BoundedField::evaluate);
73 cls.def("evaluate", (ndarray::Array<double, 1, 1>(BoundedField::*)(
74 ndarray::Array<double const, 1> const &,
75 ndarray::Array<double const, 1> const &) const) &
77 cls.def("evaluate",
78 (double (BoundedField::*)(lsst::geom::Point2D const &) const) & BoundedField::evaluate);
79 cls.def("integrate", &BoundedField::integrate);
80 cls.def("mean", &BoundedField::mean);
81 cls.def("getBBox", &BoundedField::getBBox);
82
83 // Pybind11 resolves overloads by picking the first one that might work
84 declareTemplates<double>(cls);
85 declareTemplates<float>(cls);
86
87 cpputils::python::addOutputOp(cls, "__str__");
88 cls.def("__repr__", [](BoundedField const &self) {
90 os << "BoundedField(" << self << ")";
91 return os.str();
92 });
93 });
94}
96 wrappers.addSignatureDependency("lsst.afw.table.io");
97 declareBoundedField(wrappers);
98}
99} // namespace math
100} // namespace afw
101} // namespace lsst
std::ostream * os
Definition Schema.cc:557
An abstract base class for 2-d functions defined on an integer bounding boxes.
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
virtual double integrate() const
Compute the integral of this function over its bounding-box.
virtual double mean() const
Compute the mean of this function over its bounding-box.
virtual double evaluate(lsst::geom::Point2D const &position) const =0
Evaluate the field at the given point.
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
Definition python.h:357
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
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
void wrapBoundedField(lsst::cpputils::python::WrapperCollection &wrappers)
void declareBoundedField(lsst::cpputils::python::WrapperCollection &wrappers)
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition python.h:87