23 #include <pybind11/pybind11.h>
25 #include <pybind11/stl.h>
33 using namespace py::literals;
40 template <
typename ImageT>
42 wrappers.
wrap([](
auto &mod) { mod.def(
"makeBackground", makeBackground<ImageT>,
"img"_a,
"bgCtrl"_a); });
45 template <
typename PixelT,
typename PyClass>
47 cls.def((
"getImage" + suffix).c_str(),
50 Background::getImage<PixelT>,
52 cls.def((
"getImage" + suffix).c_str(),
55 Background::getImage<PixelT>,
56 "interpStyle"_a,
"undersampleStyle"_a =
"THROW_EXCEPTION");
57 cls.def((
"getImage" + suffix).c_str(),
60 Background::getImage<PixelT>,
62 cls.def((
"getImage" + suffix).c_str(),
65 Background::getImage<PixelT>,
66 "bbox"_a,
"interpStyle"_a,
"undersampleStyle"_a =
"THROW_EXCEPTION");
67 cls.def((
"getImage" + suffix).c_str(),
69 Background::getImage<PixelT>);
75 wrappers.
wrapType(py::enum_<UndersampleStyle>(wrappers.
module,
"UndersampleStyle"),
76 [](
auto &mod,
auto &enm) {
77 enm.value(
"THROW_EXCEPTION", UndersampleStyle::THROW_EXCEPTION);
78 enm.value(
"REDUCE_INTERP_ORDER", UndersampleStyle::REDUCE_INTERP_ORDER);
79 enm.value(
"INCREASE_NXNYSAMPLE", UndersampleStyle::INCREASE_NXNYSAMPLE);
83 using PyBackgroundControl = py::class_<BackgroundControl, std::shared_ptr<BackgroundControl>>;
84 wrappers.
wrapType(PyBackgroundControl(wrappers.
module,
"BackgroundControl"), [](
auto &mod,
auto &cls) {
86 cls.def(py::init<int const, int const, StatisticsControl const, Property const,
87 ApproximateControl const>(),
88 "nxSample"_a,
"nySample"_a,
"sctrl"_a = StatisticsControl(),
"prop"_a = MEANCLIP,
89 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
90 cls.def(py::init<int const, int const, StatisticsControl const, std::string const &,
91 ApproximateControl const>(),
92 "nxSample"_a,
"nySample"_a,
"sctrl"_a,
"prop"_a,
93 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
94 cls.def(py::init<Interpolate::Style const, int const, int const, UndersampleStyle const,
95 StatisticsControl const, Property const, ApproximateControl const>(),
96 "style"_a,
"nxSample"_a = 10,
"nySample"_a = 10,
"undersampleStyle"_a = THROW_EXCEPTION,
97 "sctrl"_a = StatisticsControl(),
"prop"_a = MEANCLIP,
98 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
99 cls.def(py::init<std::string const &, int const, int const, std::string const &,
100 StatisticsControl const, std::string const &, ApproximateControl const>(),
101 "style"_a,
"nxSample"_a = 10,
"nySample"_a = 10,
"undersampleStyle"_a =
"THROW_EXCEPTION",
102 "sctrl"_a = StatisticsControl(),
"prop"_a =
"MEANCLIP",
103 "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
106 cls.def(
"setNxSample", &BackgroundControl::setNxSample);
107 cls.def(
"setNySample", &BackgroundControl::setNySample);
108 cls.def(
"setInterpStyle",
109 (void (BackgroundControl::*)(Interpolate::Style const)) & BackgroundControl::setInterpStyle);
110 cls.def(
"setInterpStyle",
111 (void (BackgroundControl::*)(std::string const &)) & BackgroundControl::setInterpStyle);
112 cls.def(
"setUndersampleStyle", (void (BackgroundControl::*)(UndersampleStyle const)) &
113 BackgroundControl::setUndersampleStyle);
114 cls.def(
"setUndersampleStyle",
115 (void (BackgroundControl::*)(std::string const &)) & BackgroundControl::setUndersampleStyle);
116 cls.def(
"getNxSample", &BackgroundControl::getNxSample);
117 cls.def(
"getNySample", &BackgroundControl::getNySample);
118 cls.def(
"getInterpStyle", &BackgroundControl::getInterpStyle);
119 cls.def(
"getUndersampleStyle", &BackgroundControl::getUndersampleStyle);
120 cls.def(
"getStatisticsControl", (std::shared_ptr<StatisticsControl>(BackgroundControl::*)()) &
121 BackgroundControl::getStatisticsControl);
122 cls.def(
"getStatisticsProperty", &BackgroundControl::getStatisticsProperty);
123 cls.def(
"setStatisticsProperty",
124 (void (BackgroundControl::*)(Property)) & BackgroundControl::setStatisticsProperty);
125 cls.def(
"setStatisticsProperty",
126 (void (BackgroundControl::*)(std::string)) & BackgroundControl::setStatisticsProperty);
127 cls.def(
"setApproximateControl", &BackgroundControl::setApproximateControl);
128 cls.def(
"getApproximateControl", (std::shared_ptr<ApproximateControl>(BackgroundControl::*)()) &
129 BackgroundControl::getApproximateControl);
131 using PyBackground = py::class_<Background, std::shared_ptr<Background>>;
132 wrappers.
wrapType(PyBackground(wrappers.
module,
"Background"), [](
auto &mod,
auto &cls) {
134 declareGetImage<float>(cls,
"F");
136 cls.def(
"getAsUsedInterpStyle", &Background::getAsUsedInterpStyle);
137 cls.def(
"getAsUsedUndersampleStyle", &Background::getAsUsedUndersampleStyle);
138 cls.def(
"getApproximate", &Background::getApproximate,
"actrl"_a,
139 "undersampleStyle"_a = THROW_EXCEPTION);
140 cls.def(
"getBackgroundControl",
141 (std::shared_ptr<BackgroundControl>(Background::*)()) & Background::getBackgroundControl);
144 using PyBackgroundMI = py::class_<BackgroundMI, std::shared_ptr<BackgroundMI>,
Background>;
145 wrappers.
wrapType(PyBackgroundMI(wrappers.
module,
"BackgroundMI"), [](
auto &mod,
auto &cls) {
147 cls.def(py::init<lsst::geom::Box2I const,
148 image::MaskedImage<typename Background::InternalPixelT> const &>(),
149 "imageDimensions"_a,
"statsImage"_a);
152 cls.def(
"__iadd__", &BackgroundMI::operator+=);
153 cls.def(
"__isub__", &BackgroundMI::operator-=);
156 cls.def(
"getStatsImage", &BackgroundMI::getStatsImage);
157 cls.def(
"getImageBBox", &BackgroundMI::getImageBBox);
166 declareMakeBackground<image::Image<float>>(wrappers);
167 declareMakeBackground<image::MaskedImage<float>>(wrappers);
A class to represent a 2-dimensional array of pixels.
A virtual base class to evaluate image background levels.
An integer coordinate rectangle.
A helper class for subdividing pybind11 module across multiple translation units (i....
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
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...
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
void wrap(WrapperCallback function)
Add a set of wrappers without defining a class.
void wrapBackground(lsst::utils::python::WrapperCollection &wrappers)
void declareBackground(lsst::utils::python::WrapperCollection &wrappers)
UndersampleStyle stringToUndersampleStyle(std::string const &style)
Conversion function to switch a string to an UndersampleStyle.
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
A base class for image defects.