lsst.afw  13.0-94-ga1c444047
heavyFootprint.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 
26 #include "numpy/arrayobject.h"
27 #include "ndarray/pybind11.h"
28 #include "ndarray/converter.h"
29 
33 
34 namespace py = pybind11;
35 using namespace py::literals;
36 
37 namespace lsst {
38 namespace afw {
39 namespace detection {
40 
41 namespace {
42 template <typename ImagePixelT, typename MaskPixelT = lsst::afw::image::MaskPixel,
43  typename VariancePixelT = lsst::afw::image::VariancePixel>
44 void declareHeavyFootprint(py::module &mod, std::string const &suffix) {
45  using Class = HeavyFootprint<ImagePixelT>;
46  py::class_<Class, std::shared_ptr<Class>, Footprint> clsHeavyFootprint(
47  mod, ("HeavyFootprint" + suffix).c_str());
48 
49  /* Constructors */
50  clsHeavyFootprint.def(
51  py::init<Footprint const &,
53  HeavyFootprintCtrl const *>(),
54  "foot"_a, "mimage"_a, "ctrl"_a = nullptr);
55  clsHeavyFootprint.def(py::init<Footprint const &, HeavyFootprintCtrl const *>(), "foot"_a,
56  "ctrl"_a = nullptr);
57 
58  /* Members */
59  clsHeavyFootprint.def("isHeavy", &Class::isHeavy);
60  clsHeavyFootprint.def(
61  "insert", (void (Class::*)(lsst::afw::image::MaskedImage<ImagePixelT> &) const) & Class::insert);
62  clsHeavyFootprint.def("insert",
63  (void (Class::*)(lsst::afw::image::Image<ImagePixelT> &) const) & Class::insert);
64  clsHeavyFootprint.def("getImageArray",
65  (ndarray::Array<ImagePixelT, 1, 1> (Class::*)()) & Class::getImageArray);
66  clsHeavyFootprint.def("getMaskArray",
67  (ndarray::Array<MaskPixelT, 1, 1> (Class::*)()) & Class::getMaskArray);
68  clsHeavyFootprint.def("getVarianceArray",
69  (ndarray::Array<VariancePixelT, 1, 1> (Class::*)()) & Class::getVarianceArray);
70  clsHeavyFootprint.def("getMaskBitsSet", &Class::getMaskBitsSet);
71  clsHeavyFootprint.def("dot", &Class::dot);
72 
73  /* Module level */
74  mod.def("makeHeavyFootprint",
75  (Class(*)(Footprint const &,
77  HeavyFootprintCtrl const *))makeHeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>,
78  "foot"_a, "img"_a, "ctrl"_a = nullptr);
79 
80  // In Swig this seems to be suffixed with a type (i.e. mergeHeavyFootprintsF)
81  // but there really doesn't seem any good reason why that is done, so removed it
82  mod.def("mergeHeavyFootprints", mergeHeavyFootprints<ImagePixelT, MaskPixelT, VariancePixelT>);
83 }
84 } // namespace
85 
87  py::module mod("_heavyFootprint", "Python wrapper for afw _heavyFootprint library");
88 
89  if (_import_array() < 0) {
90  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
91  return nullptr;
92  };
93 
94  declareHeavyFootprint<int>(mod, "I");
95  declareHeavyFootprint<std::uint16_t>(mod, "U");
96  declareHeavyFootprint<float>(mod, "F");
97  declareHeavyFootprint<double>(mod, "D");
98 
99  return mod.ptr();
100 }
101 }
102 }
103 } // lsst::afw::detection
def dot(symb, c, r, frame=None, size=2, ctype=None, origin=afwImage.PARENT, args, kwargs)
Definition: ds9.py:109
A base class for image defects.
Definition: cameraGeom.dox:3
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:81
PYBIND11_PLUGIN(_heavyFootprint)
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
lsst::afw::detection::Footprint Footprint
Definition: Source.h:60
float VariancePixel
default type for MaskedImage variance images
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:486