LSSTApplications  15.0+21,16.0+1,16.0+3,16.0+4,16.0+8,16.0-1-g2115a9e+2,16.0-1-g4515a79+6,16.0-1-g5c6f5ee+4,16.0-1-g7bb14cc,16.0-1-g80120d7+4,16.0-1-g98efed3+4,16.0-1-gb7f560d+1,16.0-14-gb4f0cd2fa,16.0-2-g1ad129e+1,16.0-2-g2ed7261+1,16.0-2-g311bfd2,16.0-2-g568a347+3,16.0-2-g852da13+6,16.0-2-gd4c87cb+3,16.0-3-g099ede0,16.0-3-g150e024+3,16.0-3-g1f513a6,16.0-3-g958ce35,16.0-4-g08dccf71+4,16.0-4-g128aaef,16.0-4-g84f75fb+5,16.0-4-gcfd1396+4,16.0-4-gde8cee2,16.0-4-gdfb0d14+1,16.0-5-g7bc0afb+3,16.0-5-g86fb31a+3,16.0-6-g2dd73041+4,16.0-7-g95fb7bf,16.0-7-gc37dbc2+4,w.2018.28
LSSTDataManagementBasePackage
mask.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 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 "ndarray/pybind11.h"
27 
29 #include "lsst/afw/image/Mask.h"
30 #include "lsst/afw/fits.h"
31 
32 namespace py = pybind11;
33 using namespace pybind11::literals;
34 
35 namespace lsst {
36 namespace afw {
37 namespace image {
38 namespace {
39 
40 template <typename MaskPixelT>
41 using PyMask = py::class_<Mask<MaskPixelT>, std::shared_ptr<Mask<MaskPixelT>>, ImageBase<MaskPixelT>>;
42 
43 template <typename MaskPixelT>
44 static void declareMask(py::module &mod, std::string const &suffix) {
45  PyMask<MaskPixelT> cls(mod, ("Mask" + suffix).c_str());
46 
47  /* Constructors */
48  cls.def(py::init<unsigned int, unsigned int, typename Mask<MaskPixelT>::MaskPlaneDict const &>(),
49  "width"_a, "height"_a, "planeDefs"_a = typename Mask<MaskPixelT>::MaskPlaneDict());
50  cls.def(py::init<unsigned int, unsigned int, MaskPixelT,
51  typename Mask<MaskPixelT>::MaskPlaneDict const &>(),
52  "width"_a, "height"_a, "initialValue"_a,
53  "planeDefs"_a = typename Mask<MaskPixelT>::MaskPlaneDict());
54  cls.def(py::init<lsst::geom::Extent2I const &, typename Mask<MaskPixelT>::MaskPlaneDict const &>(),
55  "dimensions"_a = lsst::geom::Extent2I(), "planeDefs"_a = typename Mask<MaskPixelT>::MaskPlaneDict());
56  cls.def(py::init<lsst::geom::Extent2I const &, MaskPixelT, typename Mask<MaskPixelT>::MaskPlaneDict const &>(),
57  "dimensions"_a = lsst::geom::Extent2I(), "initialValue"_a,
58  "planeDefs"_a = typename Mask<MaskPixelT>::MaskPlaneDict());
59  cls.def(py::init<lsst::geom::Box2I const &, typename Mask<MaskPixelT>::MaskPlaneDict const &>(), "bbox"_a,
60  "planeDefs"_a = typename Mask<MaskPixelT>::MaskPlaneDict());
61  cls.def(py::init<lsst::geom::Box2I const &, MaskPixelT, typename Mask<MaskPixelT>::MaskPlaneDict const &>(),
62  "bbox"_a, "initialValue"_a, "planeDefs"_a = typename Mask<MaskPixelT>::MaskPlaneDict());
63  cls.def(py::init<const Mask<MaskPixelT> &, const bool>(), "src"_a, "deep"_a = false);
64  cls.def(py::init<const Mask<MaskPixelT> &, const lsst::geom::Box2I &, ImageOrigin const, const bool>(), "src"_a,
65  "bbox"_a, "origin"_a = PARENT, "deep"_a = false);
66  cls.def(py::init<ndarray::Array<MaskPixelT, 2, 1> const &, bool, lsst::geom::Point2I const &>(), "array"_a,
67  "deep"_a = false, "xy0"_a = lsst::geom::Point2I());
69  lsst::geom::Box2I const &, ImageOrigin, bool>(),
70  "fileName"_a, "hdu"_a = fits::DEFAULT_HDU, "metadata"_a = nullptr, "bbox"_a = lsst::geom::Box2I(),
71  "origin"_a = PARENT, "conformMasks"_a = false);
72  cls.def(py::init<fits::MemFileManager &, int, std::shared_ptr<lsst::daf::base::PropertySet>,
73  lsst::geom::Box2I const &, ImageOrigin, bool>(),
74  "manager"_a, "hdu"_a = fits::DEFAULT_HDU, "metadata"_a = nullptr, "bbox"_a = lsst::geom::Box2I(),
75  "origin"_a = PARENT, "conformMasks"_a = false);
77  ImageOrigin, bool>(),
78  "fitsFile"_a, "metadata"_a = nullptr, "bbox"_a = lsst::geom::Box2I(), "origin"_a = PARENT,
79  "conformMasks"_a = false);
80 
81  /* Operators */
82  cls.def("__ior__", [](Mask<MaskPixelT> &self, Mask<MaskPixelT> &other) { return self |= other; });
83  cls.def("__ior__", [](Mask<MaskPixelT> &self, MaskPixelT const other) { return self |= other; });
84  cls.def("__ior__", [](Mask<MaskPixelT> &self, int other) { return self |= other; });
85  cls.def("__iand__", [](Mask<MaskPixelT> &self, Mask<MaskPixelT> &other) { return self &= other; });
86  cls.def("__iand__", [](Mask<MaskPixelT> &self, MaskPixelT const other) { return self &= other; });
87  cls.def("__iand__", [](Mask<MaskPixelT> &self, int other) { return self &= other; });
88  cls.def("__ixor__", [](Mask<MaskPixelT> &self, Mask<MaskPixelT> &other) { return self ^= other; });
89  cls.def("__ixor__", [](Mask<MaskPixelT> &self, MaskPixelT const other) { return self ^= other; });
90  cls.def("__ixor__", [](Mask<MaskPixelT> &self, int other) { return self ^= other; });
91 
92  /* Members */
93  cls.def("swap", (void (Mask<MaskPixelT>::*)(Mask<MaskPixelT> &)) & Mask<MaskPixelT>::swap);
94  cls.def("writeFits", (void (Mask<MaskPixelT>::*)(std::string const &,
96  std::string const &) const) &
97  Mask<MaskPixelT>::writeFits,
98  "fileName"_a, "metadata"_a = std::shared_ptr<lsst::daf::base::PropertySet>(), "mode"_a = "w");
99  cls.def("writeFits", (void (Mask<MaskPixelT>::*)(fits::MemFileManager &,
101  std::string const &) const) &
102  Mask<MaskPixelT>::writeFits,
103  "manager"_a, "metadata"_a = std::shared_ptr<lsst::daf::base::PropertySet>(), "mode"_a = "w");
104  cls.def("writeFits", (void (Mask<MaskPixelT>::*)(
106  Mask<MaskPixelT>::writeFits,
107  "fitsfile"_a, "metadata"_a = std::shared_ptr<lsst::daf::base::PropertySet const>());
108  cls.def("writeFits",
109  (void (Mask<MaskPixelT>::*)(std::string const&, fits::ImageWriteOptions const&,
110  std::string const&,
112  &Mask<MaskPixelT>::writeFits,
113  "filename"_a, "options"_a, "mode"_a="w", "header"_a=std::shared_ptr<daf::base::PropertyList>());
114  cls.def("writeFits",
115  (void (Mask<MaskPixelT>::*)(fits::MemFileManager &, fits::ImageWriteOptions const&,
116  std::string const&,
118  &Mask<MaskPixelT>::writeFits,
119  "manager"_a, "options"_a, "mode"_a="w", "header"_a=std::shared_ptr<daf::base::PropertyList>());
120  cls.def("writeFits",
121  (void (Mask<MaskPixelT>::*)(fits::Fits &, fits::ImageWriteOptions const&,
123  &Mask<MaskPixelT>::writeFits,
124  "fits"_a, "options"_a, "header"_a=std::shared_ptr<daf::base::PropertyList>());
125  cls.def_static("readFits", (Mask<MaskPixelT>(*)(std::string const &, int))Mask<MaskPixelT>::readFits,
126  "filename"_a, "hdu"_a = fits::DEFAULT_HDU);
127  cls.def_static("readFits", (Mask<MaskPixelT>(*)(fits::MemFileManager &, int))Mask<MaskPixelT>::readFits,
128  "manager"_a, "hdu"_a = fits::DEFAULT_HDU);
129  cls.def_static("interpret", Mask<MaskPixelT>::interpret);
130 
131  cls.def("subset", &Mask<MaskPixelT>::subset, "bbox"_a, "origin"_a=PARENT);
132 
133  cls.def("getAsString", &Mask<MaskPixelT>::getAsString);
134  cls.def("clearAllMaskPlanes", &Mask<MaskPixelT>::clearAllMaskPlanes);
135  cls.def("clearMaskPlane", &Mask<MaskPixelT>::clearMaskPlane);
136  cls.def("setMaskPlaneValues", &Mask<MaskPixelT>::setMaskPlaneValues);
137  cls.def_static("parseMaskPlaneMetadata", Mask<MaskPixelT>::parseMaskPlaneMetadata);
138  cls.def_static("clearMaskPlaneDict", Mask<MaskPixelT>::clearMaskPlaneDict);
139  cls.def_static("removeMaskPlane", Mask<MaskPixelT>::removeMaskPlane);
140  cls.def("removeAndClearMaskPlane", &Mask<MaskPixelT>::removeAndClearMaskPlane, "name"_a,
141  "removeFromDefault"_a = false);
142  cls.def_static("getMaskPlane", Mask<MaskPixelT>::getMaskPlane);
143  cls.def_static("getPlaneBitMask", (MaskPixelT(*)(const std::string &))Mask<MaskPixelT>::getPlaneBitMask);
144  cls.def_static("getPlaneBitMask",
145  (MaskPixelT(*)(const std::vector<std::string> &))Mask<MaskPixelT>::getPlaneBitMask);
146  cls.def_static("getNumPlanesMax", Mask<MaskPixelT>::getNumPlanesMax);
147  cls.def_static("getNumPlanesUsed", Mask<MaskPixelT>::getNumPlanesUsed);
148  cls.def("getMaskPlaneDict", &Mask<MaskPixelT>::getMaskPlaneDict);
149  cls.def("printMaskPlanes", &Mask<MaskPixelT>::printMaskPlanes);
150  cls.def_static("addMaskPlanesToMetadata", Mask<MaskPixelT>::addMaskPlanesToMetadata);
151  cls.def("conformMaskPlanes", &Mask<MaskPixelT>::conformMaskPlanes);
152  cls.def_static("addMaskPlane", (int (*)(const std::string &))Mask<MaskPixelT>::addMaskPlane);
153 
154 }
155 
157  py::module mod("mask");
158 
159  py::module::import("lsst.afw.image.image");
160 
161  declareMask<MaskPixel>(mod, "X");
162 
163  return mod.ptr();
164 }
165 }
166 }
167 }
168 } // namespace lsst::afw::image::<anonymous>
def init()
Definition: tests.py:79
std::map< std::string, int > MaskPlaneDict
Definition: Mask.h:65
PYBIND11_PLUGIN(_cameraSys)
Definition: cameraSys.cc:62
STL class.
A base class for image defects.
Definition: cameraGeom.dox:3
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:473
afw::table::Key< afw::table::Array< MaskPixelT > > mask
ItemVariant const * other
Definition: Schema.cc:55
An integer coordinate rectangle.
Definition: Box.h:54
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18