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
_background.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>
25#include <pybind11/stl.h>
26
27#include "ndarray/pybind11.h"
28
32
33namespace py = pybind11;
34
35using namespace py::literals;
36
37namespace lsst {
38namespace afw {
39namespace math {
40
41namespace {
42template <typename ImageT>
43void declareMakeBackground(lsst::cpputils::python::WrapperCollection &wrappers) {
44 wrappers.wrap([](auto &mod) { mod.def("makeBackground", makeBackground<ImageT>, "img"_a, "bgCtrl"_a); });
45}
46
47template <typename PixelT, typename PyClass>
48void declareGetImage(PyClass &cls, std::string const &suffix) {
49 cls.def(("getImage" + suffix).c_str(),
50 (std::shared_ptr<lsst::afw::image::Image<PixelT>>(Background::*)(Interpolate::Style const,
51 UndersampleStyle const) const) &
53 "interpStyle"_a, "undersampleStyle"_a = THROW_EXCEPTION);
54 cls.def(("getImage" + suffix).c_str(),
55 (std::shared_ptr<lsst::afw::image::Image<PixelT>>(Background::*)(std::string const &,
56 std::string const &) const) &
58 "interpStyle"_a, "undersampleStyle"_a = "THROW_EXCEPTION");
59 cls.def(("getImage" + suffix).c_str(),
60 (std::shared_ptr<lsst::afw::image::Image<PixelT>>(Background::*)(
61 lsst::geom::Box2I const &, Interpolate::Style const, UndersampleStyle const) const) &
63 "bbox"_a, "interpStyle"_a, "undersampleStyle"_a = THROW_EXCEPTION);
64 cls.def(("getImage" + suffix).c_str(),
65 (std::shared_ptr<lsst::afw::image::Image<PixelT>>(Background::*)(
66 lsst::geom::Box2I const &, std::string const &, std::string const &) const) &
68 "bbox"_a, "interpStyle"_a, "undersampleStyle"_a = "THROW_EXCEPTION");
69 cls.def(("getImage" + suffix).c_str(),
70 (std::shared_ptr<lsst::afw::image::Image<PixelT>>(Background::*)() const) &
72}
73} // namespace
74
76 /* Member types and enums */
77 wrappers.wrapType(py::enum_<UndersampleStyle>(wrappers.module, "UndersampleStyle"),
78 [](auto &mod, auto &enm) {
79 enm.value("THROW_EXCEPTION", UndersampleStyle::THROW_EXCEPTION);
80 enm.value("REDUCE_INTERP_ORDER", UndersampleStyle::REDUCE_INTERP_ORDER);
81 enm.value("INCREASE_NXNYSAMPLE", UndersampleStyle::INCREASE_NXNYSAMPLE);
82 enm.export_values();
83 });
84
85 using PyBackgroundControl = py::classh<BackgroundControl>;
86 wrappers.wrapType(PyBackgroundControl(wrappers.module, "BackgroundControl"), [](auto &mod, auto &cls) {
87 /* Constructors */
88 cls.def(py::init<int const, int const, StatisticsControl const, Property const,
89 ApproximateControl const>(),
90 "nxSample"_a, "nySample"_a, "sctrl"_a = StatisticsControl(), "prop"_a = MEANCLIP,
91 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
92 cls.def(py::init<int const, int const, StatisticsControl const, std::string const &,
93 ApproximateControl const>(),
94 "nxSample"_a, "nySample"_a, "sctrl"_a, "prop"_a,
95 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
96 cls.def(py::init<Interpolate::Style const, int const, int const, UndersampleStyle const,
97 StatisticsControl const, Property const, ApproximateControl const>(),
98 "style"_a, "nxSample"_a = 10, "nySample"_a = 10, "undersampleStyle"_a = THROW_EXCEPTION,
99 "sctrl"_a = StatisticsControl(), "prop"_a = MEANCLIP,
100 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
101 cls.def(py::init<std::string const &, int const, int const, std::string const &,
102 StatisticsControl const, std::string const &, ApproximateControl const>(),
103 "style"_a, "nxSample"_a = 10, "nySample"_a = 10, "undersampleStyle"_a = "THROW_EXCEPTION",
104 "sctrl"_a = StatisticsControl(), "prop"_a = "MEANCLIP",
105 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
106
107 /* Members */
108 cls.def("setNxSample", &BackgroundControl::setNxSample);
109 cls.def("setNySample", &BackgroundControl::setNySample);
110 cls.def("setInterpStyle",
111 (void (BackgroundControl::*)(Interpolate::Style const)) & BackgroundControl::setInterpStyle);
112 cls.def("setInterpStyle",
113 (void (BackgroundControl::*)(std::string const &)) & BackgroundControl::setInterpStyle);
114 cls.def("setUndersampleStyle", (void (BackgroundControl::*)(UndersampleStyle const)) &
115 BackgroundControl::setUndersampleStyle);
116 cls.def("setUndersampleStyle",
117 (void (BackgroundControl::*)(std::string const &)) & BackgroundControl::setUndersampleStyle);
118 cls.def("getNxSample", &BackgroundControl::getNxSample);
119 cls.def("getNySample", &BackgroundControl::getNySample);
120 cls.def("getInterpStyle", &BackgroundControl::getInterpStyle);
121 cls.def("getUndersampleStyle", &BackgroundControl::getUndersampleStyle);
122 cls.def("getStatisticsControl", (std::shared_ptr<StatisticsControl>(BackgroundControl::*)()) &
123 BackgroundControl::getStatisticsControl);
124 cls.def("getStatisticsProperty", &BackgroundControl::getStatisticsProperty);
125 cls.def("setStatisticsProperty",
126 (void (BackgroundControl::*)(Property)) & BackgroundControl::setStatisticsProperty);
127 cls.def("setStatisticsProperty",
128 (void (BackgroundControl::*)(std::string)) & BackgroundControl::setStatisticsProperty);
129 cls.def("setApproximateControl", &BackgroundControl::setApproximateControl);
130 cls.def("getApproximateControl", (std::shared_ptr<ApproximateControl>(BackgroundControl::*)()) &
131 BackgroundControl::getApproximateControl);
132 });
133 using PyBackground = py::classh<Background>;
134 wrappers.wrapType(PyBackground(wrappers.module, "Background"), [](auto &mod, auto &cls) {
135 /* Members */
136 declareGetImage<float>(cls, "F");
137
138 cls.def("getAsUsedInterpStyle", &Background::getAsUsedInterpStyle);
139 cls.def("getAsUsedUndersampleStyle", &Background::getAsUsedUndersampleStyle);
140 cls.def("getApproximate", &Background::getApproximate, "actrl"_a,
141 "undersampleStyle"_a = THROW_EXCEPTION);
142 cls.def("getBackgroundControl",
143 (std::shared_ptr<BackgroundControl>(Background::*)()) & Background::getBackgroundControl);
144 });
145
146 using PyBackgroundMI = py::classh<BackgroundMI, Background>;
147 wrappers.wrapType(PyBackgroundMI(wrappers.module, "BackgroundMI"), [](auto &mod, auto &cls) {
148 /* Constructors */
149 cls.def(py::init<lsst::geom::Box2I const,
150 image::MaskedImage<typename Background::InternalPixelT> const &>(),
151 "imageDimensions"_a, "statsImage"_a);
152
153 /* Operators */
154 cls.def("__iadd__", &BackgroundMI::operator+=);
155 cls.def("__isub__", &BackgroundMI::operator-=);
156
157 /* Members */
158 cls.def("getStatsImage", &BackgroundMI::getStatsImage);
159 cls.def("getImageBBox", &BackgroundMI::getImageBBox);
160 cls.def("getBinCentersX", &BackgroundMI::getBinCentersX);
161 cls.def("getBinCentersY", &BackgroundMI::getBinCentersY);
162
163 // Yes, really only float
164 });
165}
167 // FIXME: review when lsst.afw.image is converted to python wrappers
168 wrappers.addInheritanceDependency("lsst.afw.image");
169 declareBackground(wrappers);
170 declareMakeBackground<image::Image<float>>(wrappers);
171 declareMakeBackground<image::MaskedImage<float>>(wrappers);
172 wrappers.wrap(
173 [](auto &mod) { mod.def("stringToUndersampleStyle", stringToUndersampleStyle, "style"_a); });
174}
175} // namespace math
176} // namespace afw
177} // namespace lsst
A virtual base class to evaluate image background levels.
Definition Background.h:236
std::shared_ptr< lsst::afw::image::Image< PixelT > > getImage(Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle=THROW_EXCEPTION) const
Method to interpolate and return the background for entire image.
Definition Background.h:284
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
Definition python.h:369
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
Definition python.h:343
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
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
std::shared_ptr< Background > makeBackground(ImageT const &img, BackgroundControl const &bgCtrl)
A convenience function that uses function overloading to make the correct type of Background.
Definition Background.h:533
void declareBackground(lsst::cpputils::python::WrapperCollection &wrappers)
void wrapBackground(lsst::cpputils::python::WrapperCollection &wrappers)
UndersampleStyle stringToUndersampleStyle(std::string const &style)
Conversion function to switch a string to an UndersampleStyle.
py::classh< PixelAreaBoundedField, BoundedField > PyClass