LSST Applications  21.0.0+c4f5df5339,21.0.0+e70536a077,21.0.0-1-ga51b5d4+7c60f8a6ea,21.0.0-10-gcf60f90+74aa0801fd,21.0.0-12-g63909ac9+643a1044a5,21.0.0-15-gedb9d5423+1041c3824f,21.0.0-2-g103fe59+a356b2badb,21.0.0-2-g1367e85+6d3f3f41db,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+6d3f3f41db,21.0.0-2-g7f82c8f+8d7c04eab9,21.0.0-2-g8f08a60+9c9a9cfcc8,21.0.0-2-ga326454+8d7c04eab9,21.0.0-2-gde069b7+bedfc5e1fb,21.0.0-2-gecfae73+6cb6558258,21.0.0-2-gfc62afb+6d3f3f41db,21.0.0-3-g21c7a62+f6e98b25aa,21.0.0-3-g357aad2+bd62456bea,21.0.0-3-g4be5c26+6d3f3f41db,21.0.0-3-g65f322c+03a4076c01,21.0.0-3-g7d9da8d+c4f5df5339,21.0.0-3-gaa929c8+c6b98066dc,21.0.0-3-gc44e71e+a26d5c1aea,21.0.0-3-ge02ed75+04b527a9d5,21.0.0-35-g64f566ff+b27e5ef93e,21.0.0-4-g591bb35+04b527a9d5,21.0.0-4-g88306b8+8773047b2e,21.0.0-4-gc004bbf+80a0b7acb7,21.0.0-4-gccdca77+a5c54364a0,21.0.0-4-ge8fba5a+ccfc328107,21.0.0-5-gdf36809+87b8d260e6,21.0.0-6-g00874e7+7eeda2b6ba,21.0.0-6-g2d4f3f3+e70536a077,21.0.0-6-g4e60332+04b527a9d5,21.0.0-6-g5ef7dad+f53629abd8,21.0.0-7-gc8ca178+b63e69433b,21.0.0-8-gfbe0b4b+c6b98066dc,w.2021.06
LSST Data Management Base Package
statistics.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>
25 
27 
28 namespace py = pybind11;
29 using namespace pybind11::literals;
30 
31 namespace lsst {
32 namespace afw {
33 namespace math {
34 
35 template <typename Pixel>
37  mod.def("makeStatistics",
38  (Statistics(*)(image::Image<Pixel> const &, image::Mask<image::MaskPixel> const &, int const,
39  StatisticsControl const &))makeStatistics<Pixel>,
40  "img"_a, "msk"_a, "flags"_a, "sctrl"_a = StatisticsControl());
41  mod.def("makeStatistics", (Statistics(*)(image::MaskedImage<Pixel> const &, int const,
42  StatisticsControl const &))makeStatistics<Pixel>,
43  "mimg"_a, "flags"_a, "sctrl"_a = StatisticsControl());
44  mod.def("makeStatistics",
45  (Statistics(*)(image::MaskedImage<Pixel> const &, image::Image<WeightPixel> const &, int const,
46  StatisticsControl const &))makeStatistics<Pixel>,
47  "mimg"_a, "weights"_a, "flags"_a, "sctrl"_a = StatisticsControl());
48  mod.def("makeStatistics",
49  (Statistics(*)(image::Mask<image::MaskPixel> const &, int const, StatisticsControl const &))
50  makeStatistics, // this is not a template, just a regular overload
51  "msk"_a,
52  "flags"_a, "sctrl"_a = StatisticsControl());
53  mod.def("makeStatistics", (Statistics(*)(image::Image<Pixel> const &, int const,
54  StatisticsControl const &))makeStatistics<Pixel>,
55  "img"_a, "flags"_a, "sctrl"_a = StatisticsControl());
56 }
57 
58 template <typename Pixel>
60  mod.def("makeStatistics", (Statistics(*)(std::vector<Pixel> const &, int const,
61  StatisticsControl const &))makeStatistics<Pixel>,
62  "v"_a, "flags"_a, "sctrl"_a = StatisticsControl());
63  mod.def("makeStatistics", (Statistics(*)(std::vector<Pixel> const &, std::vector<WeightPixel> const &,
64  int const, StatisticsControl const &))makeStatistics<Pixel>,
65  "v"_a, "vweights"_a, "flags"_a, "sctrl"_a = StatisticsControl());
66 }
67 
68 PYBIND11_MODULE(statistics, mod) {
69  /* Module level */
70  py::enum_<Property>(mod, "Property", py::arithmetic())
71  .value("NOTHING", Property::NOTHING)
72  .value("ERRORS", Property::ERRORS)
73  .value("NPOINT", Property::NPOINT)
74  .value("MEAN", Property::MEAN)
75  .value("STDEV", Property::STDEV)
76  .value("VARIANCE", Property::VARIANCE)
77  .value("MEDIAN", Property::MEDIAN)
78  .value("IQRANGE", Property::IQRANGE)
79  .value("MEANCLIP", Property::MEANCLIP)
80  .value("STDEVCLIP", Property::STDEVCLIP)
81  .value("VARIANCECLIP", Property::VARIANCECLIP)
82  .value("MIN", Property::MIN)
83  .value("MAX", Property::MAX)
84  .value("SUM", Property::SUM)
85  .value("MEANSQUARE", Property::MEANSQUARE)
86  .value("ORMASK", Property::ORMASK)
87  .value("NCLIPPED", Property::NCLIPPED)
88  .value("NMASKED", Property::NMASKED)
89  .export_values();
90 
91  mod.def("stringToStatisticsProperty", stringToStatisticsProperty);
92 
93  py::class_<StatisticsControl, std::shared_ptr<StatisticsControl>> clsStatisticsControl(
94  mod, "StatisticsControl");
95 
96  py::enum_<StatisticsControl::WeightsBoolean>(clsStatisticsControl, "WeightsBoolean")
97  .value("WEIGHTS_FALSE", StatisticsControl::WeightsBoolean::WEIGHTS_FALSE)
98  .value("WEIGHTS_TRUE", StatisticsControl::WeightsBoolean::WEIGHTS_TRUE)
99  .value("WEIGHTS_NONE", StatisticsControl::WeightsBoolean::WEIGHTS_NONE)
100  .export_values();
101 
102  clsStatisticsControl.def(py::init<double, int, lsst::afw::image::MaskPixel, bool,
104  "numSigmaClip"_a = 3.0, "numIter"_a = 3, "andMask"_a = 0x0, "isNanSafe"_a = true,
105  "useWeights"_a = StatisticsControl::WEIGHTS_NONE);
106 
107  clsStatisticsControl.def("getMaskPropagationThreshold", &StatisticsControl::getMaskPropagationThreshold);
108  clsStatisticsControl.def("setMaskPropagationThreshold", &StatisticsControl::setMaskPropagationThreshold);
109  clsStatisticsControl.def("getNumSigmaClip", &StatisticsControl::getNumSigmaClip);
110  clsStatisticsControl.def("getNumIter", &StatisticsControl::getNumIter);
111  clsStatisticsControl.def("getAndMask", &StatisticsControl::getAndMask);
112  clsStatisticsControl.def("getNoGoodPixelsMask", &StatisticsControl::getNoGoodPixelsMask);
113  clsStatisticsControl.def("getNanSafe", &StatisticsControl::getNanSafe);
114  clsStatisticsControl.def("getWeighted", &StatisticsControl::getWeighted);
115  clsStatisticsControl.def("getWeightedIsSet", &StatisticsControl::getWeightedIsSet);
116  clsStatisticsControl.def("getCalcErrorFromInputVariance",
117  &StatisticsControl::getCalcErrorFromInputVariance);
118  clsStatisticsControl.def("setNumSigmaClip", &StatisticsControl::setNumSigmaClip);
119  clsStatisticsControl.def("setNumIter", &StatisticsControl::setNumIter);
120  clsStatisticsControl.def("setAndMask", &StatisticsControl::setAndMask);
121  clsStatisticsControl.def("setNoGoodPixelsMask", &StatisticsControl::setNoGoodPixelsMask);
122  clsStatisticsControl.def("setNanSafe", &StatisticsControl::setNanSafe);
123  clsStatisticsControl.def("setWeighted", &StatisticsControl::setWeighted);
124  clsStatisticsControl.def("setCalcErrorFromInputVariance",
125  &StatisticsControl::setCalcErrorFromInputVariance);
126 
127  py::class_<Statistics> clsStatistics(mod, "Statistics");
128 
129  clsStatistics.def("getResult", &Statistics::getResult, "prop"_a = Property::NOTHING);
130  clsStatistics.def("getError", &Statistics::getError, "prop"_a = Property::NOTHING);
131  clsStatistics.def("getValue", &Statistics::getValue, "prop"_a = Property::NOTHING);
132  clsStatistics.def("getOrMask", &Statistics::getOrMask);
133 
134  declareStatistics<unsigned short>(mod);
135  declareStatistics<double>(mod);
136  declareStatistics<float>(mod);
137  declareStatistics<int>(mod);
138 
139  // Declare vector overloads separately to prevent casting errors
140  // that otherwise (mysteriously) occur when overloads are tried
141  // in order.
142  declareStatisticsVectorOverloads<unsigned short>(mod);
143  declareStatisticsVectorOverloads<double>(mod);
144  declareStatisticsVectorOverloads<float>(mod);
145  declareStatisticsVectorOverloads<int>(mod);
146 }
147 
148 } // math
149 } // afw
150 } // lsst
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
Pass parameters to a Statistics object.
Definition: Statistics.h:93
A class to evaluate image statistics.
Definition: Statistics.h:215
void declareStatisticsVectorOverloads(py::module &mod)
Definition: statistics.cc:59
PYBIND11_MODULE(statistics, mod)
Definition: statistics.cc:68
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition: Statistics.h:354
@ ORMASK
get the or-mask of all pixels used.
Definition: Statistics.h:80
@ ERRORS
Include errors of requested quantities.
Definition: Statistics.h:65
@ VARIANCECLIP
estimate sample N-sigma clipped variance (N set in StatisticsControl, default=3)
Definition: Statistics.h:74
@ MEANSQUARE
find mean value of square of pixel values
Definition: Statistics.h:79
@ MIN
estimate sample minimum
Definition: Statistics.h:76
@ NCLIPPED
number of clipped points
Definition: Statistics.h:81
@ NOTHING
We don't want anything.
Definition: Statistics.h:64
@ STDEV
estimate sample standard deviation
Definition: Statistics.h:68
@ NMASKED
number of masked points
Definition: Statistics.h:82
@ STDEVCLIP
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
Definition: Statistics.h:73
@ VARIANCE
estimate sample variance
Definition: Statistics.h:69
@ MEDIAN
estimate sample median
Definition: Statistics.h:70
@ MAX
estimate sample maximum
Definition: Statistics.h:77
@ SUM
find sum of pixels in the image
Definition: Statistics.h:78
@ IQRANGE
estimate sample inter-quartile range
Definition: Statistics.h:71
@ MEAN
estimate sample mean
Definition: Statistics.h:67
@ MEANCLIP
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
Definition: Statistics.h:72
@ NPOINT
number of sample points
Definition: Statistics.h:66
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
Definition: Statistics.cc:747
void declareStatistics(py::module &mod)
Definition: statistics.cc:36
def init()
Definition: tests.py:59
A base class for image defects.