LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
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