LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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>
24 //#include <pybind11/operators.h>
25 #include <pybind11/stl.h>
26 
27 #include "lsst/afw/image/Image.h"
30 
31 namespace py = pybind11;
32 
33 using namespace py::literals;
34 
35 namespace lsst {
36 namespace afw {
37 namespace math {
38 
39 namespace {
40 template <typename ImageT>
41 void declareMakeBackground(py::module &mod) {
42  mod.def("makeBackground", makeBackground<ImageT>, "img"_a, "bgCtrl"_a);
43 }
44 
45 template <typename PixelT, typename PyClass>
46 void declareGetImage(PyClass &cls, std::string const &suffix) {
47  cls.def(("getImage" + suffix).c_str(),
49  Interpolate::Style const, UndersampleStyle const) const) &
50  Background::getImage<PixelT>,
51  "interpStyle"_a, "undersampleStyle"_a = THROW_EXCEPTION);
52  cls.def(("getImage" + suffix).c_str(),
54  std::string const &) const) &
55  Background::getImage<PixelT>,
56  "interpStyle"_a, "undersampleStyle"_a = "THROW_EXCEPTION");
57  cls.def(("getImage" + suffix).c_str(),
59  lsst::geom::Box2I const &, Interpolate::Style const, UndersampleStyle const) const) &
60  Background::getImage<PixelT>,
61  "bbox"_a, "interpStyle"_a, "undersampleStyle"_a = THROW_EXCEPTION);
62  cls.def(("getImage" + suffix).c_str(),
64  lsst::geom::Box2I const &, std::string const &, std::string const &) const) &
65  Background::getImage<PixelT>,
66  "bbox"_a, "interpStyle"_a, "undersampleStyle"_a = "THROW_EXCEPTION");
67  cls.def(("getImage" + suffix).c_str(),
68  (std::shared_ptr<lsst::afw::image::Image<PixelT>> (Background::*)() const) &
69  Background::getImage<PixelT>);
70 }
71 }
72 
74  py::module::import("lsst.afw.image.image");
75 
76  /* Member types and enums */
77  py::enum_<UndersampleStyle>(mod, "UndersampleStyle")
78  .value("THROW_EXCEPTION", UndersampleStyle::THROW_EXCEPTION)
79  .value("REDUCE_INTERP_ORDER", UndersampleStyle::REDUCE_INTERP_ORDER)
80  .value("INCREASE_NXNYSAMPLE", UndersampleStyle::INCREASE_NXNYSAMPLE)
81  .export_values();
82 
83  py::class_<BackgroundControl, std::shared_ptr<BackgroundControl>> clsBackgroundControl(
84  mod, "BackgroundControl");
85 
86  /* Constructors */
87  clsBackgroundControl.def(py::init<int const, int const, StatisticsControl const, Property const,
88  ApproximateControl const>(),
89  "nxSample"_a, "nySample"_a, "sctrl"_a = StatisticsControl(), "prop"_a = MEANCLIP,
90  "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
91  clsBackgroundControl.def(py::init<int const, int const, StatisticsControl const, std::string const &,
92  ApproximateControl const>(),
93  "nxSample"_a, "nySample"_a, "sctrl"_a, "prop"_a,
94  "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
95  clsBackgroundControl.def(py::init<Interpolate::Style const, int const, int const, UndersampleStyle const,
96  StatisticsControl const, Property const, ApproximateControl const>(),
97  "style"_a, "nxSample"_a = 10, "nySample"_a = 10,
98  "undersampleStyle"_a = THROW_EXCEPTION, "sctrl"_a = StatisticsControl(),
99  "prop"_a = MEANCLIP,
100  "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
101  clsBackgroundControl.def(
102  py::init<std::string const &, int const, int const, std::string const &, StatisticsControl const,
103  std::string const &, ApproximateControl const>(),
104  "style"_a, "nxSample"_a = 10, "nySample"_a = 10, "undersampleStyle"_a = "THROW_EXCEPTION",
105  "sctrl"_a = StatisticsControl(), "prop"_a = "MEANCLIP",
106  "actrl"_a = ApproximateControl(ApproximateControl::UNKNOWN, 1));
107 
108  /* Members */
109  clsBackgroundControl.def("setNxSample", &BackgroundControl::setNxSample);
110  clsBackgroundControl.def("setNySample", &BackgroundControl::setNySample);
111  clsBackgroundControl.def("setInterpStyle", (void (BackgroundControl::*)(Interpolate::Style const)) &
112  BackgroundControl::setInterpStyle);
113  clsBackgroundControl.def("setInterpStyle", (void (BackgroundControl::*)(std::string const &)) &
114  BackgroundControl::setInterpStyle);
115  clsBackgroundControl.def("setUndersampleStyle", (void (BackgroundControl::*)(UndersampleStyle const)) &
116  BackgroundControl::setUndersampleStyle);
117  clsBackgroundControl.def("setUndersampleStyle", (void (BackgroundControl::*)(std::string const &)) &
118  BackgroundControl::setUndersampleStyle);
119  clsBackgroundControl.def("getNxSample", &BackgroundControl::getNxSample);
120  clsBackgroundControl.def("getNySample", &BackgroundControl::getNySample);
121  clsBackgroundControl.def("getInterpStyle", &BackgroundControl::getInterpStyle);
122  clsBackgroundControl.def("getUndersampleStyle", &BackgroundControl::getUndersampleStyle);
123  clsBackgroundControl.def("getStatisticsControl",
125  BackgroundControl::getStatisticsControl);
126  clsBackgroundControl.def("getStatisticsProperty", &BackgroundControl::getStatisticsProperty);
127  clsBackgroundControl.def("setStatisticsProperty", (void (BackgroundControl::*)(Property)) &
128  BackgroundControl::setStatisticsProperty);
129  clsBackgroundControl.def("setStatisticsProperty", (void (BackgroundControl::*)(std::string)) &
130  BackgroundControl::setStatisticsProperty);
131  clsBackgroundControl.def("setApproximateControl", &BackgroundControl::setApproximateControl);
132  clsBackgroundControl.def("getApproximateControl",
134  BackgroundControl::getApproximateControl);
135 
136  /* Note that, in this case, the holder type must be unique_ptr to enable usage
137  * of py::nodelete, which in turn is needed because Background has a protected
138  * destructor. Adding py::nodelete prevents pybind11 from calling the destructor
139  * when the pointer is destroyed. Thus care needs to be taken to prevent leaks.
140  * Basically Background should only ever be used as a base class (without data
141  * members). */
142  py::class_<Background, std::unique_ptr<Background, py::nodelete>> clsBackground(mod, "Background");
143 
144  /* Members */
145  declareGetImage<float>(clsBackground, "F");
146 
147  clsBackground.def("getAsUsedInterpStyle", &Background::getAsUsedInterpStyle);
148  clsBackground.def("getAsUsedUndersampleStyle", &Background::getAsUsedUndersampleStyle);
149  clsBackground.def("getApproximate", &Background::getApproximate, "actrl"_a,
150  "undersampleStyle"_a = THROW_EXCEPTION);
151  clsBackground.def("getBackgroundControl", (std::shared_ptr<BackgroundControl> (Background::*)()) &
152  Background::getBackgroundControl);
153 
154  py::class_<BackgroundMI, std::shared_ptr<BackgroundMI>, Background> clsBackgroundMI(mod, "BackgroundMI");
155 
156  /* Constructors */
157  clsBackgroundMI.def(
159  "imageDimensions"_a, "statsImage"_a);
160 
161  /* Operators */
162  clsBackgroundMI.def("__iadd__", &BackgroundMI::operator+=);
163  clsBackgroundMI.def("__isub__", &BackgroundMI::operator-=);
164 
165  /* Members */
166  clsBackgroundMI.def("getStatsImage", &BackgroundMI::getStatsImage);
167  clsBackgroundMI.def("getImageBBox", &BackgroundMI::getImageBBox);
168 
169  // Yes, really only float
170  declareMakeBackground<image::Image<float>>(mod);
171  declareMakeBackground<image::MaskedImage<float>>(mod);
172 
173  mod.def("stringToUndersampleStyle", stringToUndersampleStyle, "style"_a);
174 }
175 }
176 }
177 } // lsst::afw::math
lsst::afw::math::UndersampleStyle
UndersampleStyle
Definition: Background.h:47
lsst::afw::math::REDUCE_INTERP_ORDER
@ REDUCE_INTERP_ORDER
Definition: Background.h:47
std::string
STL class.
std::shared_ptr
STL class.
Background.h
MaskedImage.h
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::math::THROW_EXCEPTION
@ THROW_EXCEPTION
Definition: Background.h:47
Image.h
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
lsst::afw::math::MEANCLIP
@ MEANCLIP
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
Definition: Statistics.h:72
lsst::afw::math::PYBIND11_MODULE
PYBIND11_MODULE(background, mod)
Definition: background.cc:73
lsst::afw::image::MaskedImage
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
lsst::afw::math::Background
A virtual base class to evaluate image background levels.
Definition: Background.h:235
lsst.pipe.drivers.visualizeVisit.background
background
Definition: visualizeVisit.py:37
lsst::afw::math::Interpolate::Style
Style
Definition: Interpolate.h:38
PyClass
py::class_< ProductBoundedField, std::shared_ptr< ProductBoundedField >, BoundedField > PyClass
Definition: productBoundedField.cc:32
lsst::afw::math::BackgroundControl
Pass parameters to a Background object.
Definition: Background.h:56
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::math::StatisticsControl
Pass parameters to a Statistics object.
Definition: Statistics.h:93
lsst::afw::math::ApproximateControl
Control how to make an approximation.
Definition: Approximate.h:48
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
pybind11
Definition: _GenericMap.cc:40
lsst::afw::math::Property
Property
control what is calculated
Definition: Statistics.h:63
lsst::afw::math::stringToUndersampleStyle
UndersampleStyle stringToUndersampleStyle(std::string const &style)
Conversion function to switch a string to an UndersampleStyle.
Definition: Background.cc:117
lsst::afw::image::Image
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:58
lsst::utils.tests.init
def init()
Definition: tests.py:59
lsst::afw::math::INCREASE_NXNYSAMPLE
@ INCREASE_NXNYSAMPLE
Definition: Background.h:47
lsst::meas::modelfit.psf.psfContinued.module
module
Definition: psfContinued.py:42