23 #include "pybind11/pybind11.h" 24 #include "pybind11/stl.h" 26 #include "numpy/arrayobject.h" 27 #include "ndarray/pybind11.h" 33 namespace py = pybind11;
41 template <
typename MaskPixelT>
42 using PyMask = py::class_<Mask<MaskPixelT>, std::shared_ptr<Mask<MaskPixelT>>, ImageBase<MaskPixelT>>;
44 template <
typename MaskPixelT>
45 static void declareMask(py::module &mod, std::string
const &suffix) {
46 PyMask<MaskPixelT>
cls(mod, (
"Mask" + suffix).c_str());
51 cls.def(py::init<
unsigned int,
unsigned int, MaskPixelT,
53 "width"_a,
"height"_a,
"initialValue"_a,
64 cls.def(py::init<
const Mask<MaskPixelT> &,
const bool>(),
"src"_a,
"deep"_a =
false);
65 cls.def(py::init<
const Mask<MaskPixelT> &,
const geom::Box2I &,
ImageOrigin const,
const bool>(),
"src"_a,
66 "bbox"_a,
"origin"_a =
PARENT,
"deep"_a =
false);
67 cls.def(py::init<ndarray::Array<MaskPixelT, 2, 1>
const &,
bool,
geom::Point2I const &>(),
"array"_a,
69 cls.def(py::init<std::string
const &,
int, std::shared_ptr<lsst::daf::base::PropertySet>,
71 "fileName"_a,
"hdu"_a = INT_MIN,
"metadata"_a =
nullptr,
"bbox"_a = geom::Box2I(),
72 "origin"_a =
PARENT,
"conformMasks"_a =
false);
73 cls.def(py::init<fits::MemFileManager &,
int, std::shared_ptr<lsst::daf::base::PropertySet>,
75 "manager"_a,
"hdu"_a = INT_MIN,
"metadata"_a =
nullptr,
"bbox"_a = geom::Box2I(),
76 "origin"_a =
PARENT,
"conformMasks"_a =
false);
77 cls.def(py::init<fits::Fits &, std::shared_ptr<lsst::daf::base::PropertySet>, geom::Box2I
const &,
79 "fitsFile"_a,
"metadata"_a =
nullptr,
"bbox"_a = geom::Box2I(),
"origin"_a =
PARENT,
80 "conformMasks"_a =
false);
83 cls.def(
"__ior__", [](Mask<MaskPixelT> &
self, Mask<MaskPixelT> &other) {
return self |= other; });
84 cls.def(
"__ior__", [](Mask<MaskPixelT> &
self, MaskPixelT
const other) {
return self |= other; });
85 cls.def(
"__ior__", [](Mask<MaskPixelT> &
self,
int other) {
return self |= other; });
86 cls.def(
"__iand__", [](Mask<MaskPixelT> &
self, Mask<MaskPixelT> &other) {
return self &= other; });
87 cls.def(
"__iand__", [](Mask<MaskPixelT> &
self, MaskPixelT
const other) {
return self &= other; });
88 cls.def(
"__iand__", [](Mask<MaskPixelT> &
self,
int other) {
return self &= other; });
89 cls.def(
"__ixor__", [](Mask<MaskPixelT> &
self, Mask<MaskPixelT> &other) {
return self ^= other; });
90 cls.def(
"__ixor__", [](Mask<MaskPixelT> &
self, MaskPixelT
const other) {
return self ^= other; });
91 cls.def(
"__ixor__", [](Mask<MaskPixelT> &
self,
int other) {
return self ^= other; });
95 cls.def(
"writeFits", (
void (Mask<MaskPixelT>::*)(std::string
const &,
96 std::shared_ptr<lsst::daf::base::PropertySet const>,
97 std::string
const &)
const) &
98 Mask<MaskPixelT>::writeFits,
99 "fileName"_a,
"metadata"_a = std::shared_ptr<lsst::daf::base::PropertySet>(),
"mode"_a =
"w");
100 cls.def(
"writeFits", (
void (Mask<MaskPixelT>::*)(fits::MemFileManager &,
101 std::shared_ptr<lsst::daf::base::PropertySet const>,
102 std::string
const &)
const) &
103 Mask<MaskPixelT>::writeFits,
104 "manager"_a,
"metadata"_a = std::shared_ptr<lsst::daf::base::PropertySet>(),
"mode"_a =
"w");
105 cls.def(
"writeFits", (
void (Mask<MaskPixelT>::*)(
106 fits::Fits &, std::shared_ptr<lsst::daf::base::PropertySet const>)
const) &
107 Mask<MaskPixelT>::writeFits,
108 "fitsfile"_a,
"metadata"_a = std::shared_ptr<lsst::daf::base::PropertySet const>());
109 cls.def_static(
"readFits", (Mask<MaskPixelT>(*)(std::string
const &,
int))Mask<MaskPixelT>::readFits,
110 "filename"_a,
"hdu"_a = INT_MIN);
111 cls.def_static(
"readFits", (Mask<MaskPixelT>(*)(fits::MemFileManager &,
int))Mask<MaskPixelT>::readFits,
112 "manager"_a,
"hdu"_a = INT_MIN);
113 cls.def_static(
"interpret", Mask<MaskPixelT>::interpret);
114 cls.def(
"getAsString", &Mask<MaskPixelT>::getAsString);
115 cls.def(
"clearAllMaskPlanes", &Mask<MaskPixelT>::clearAllMaskPlanes);
116 cls.def(
"clearMaskPlane", &Mask<MaskPixelT>::clearMaskPlane);
117 cls.def(
"setMaskPlaneValues", &Mask<MaskPixelT>::setMaskPlaneValues);
118 cls.def_static(
"parseMaskPlaneMetadata", Mask<MaskPixelT>::parseMaskPlaneMetadata);
119 cls.def_static(
"clearMaskPlaneDict", Mask<MaskPixelT>::clearMaskPlaneDict);
120 cls.def_static(
"removeMaskPlane", Mask<MaskPixelT>::removeMaskPlane);
121 cls.def(
"removeAndClearMaskPlane", &Mask<MaskPixelT>::removeAndClearMaskPlane,
"name"_a,
122 "removeFromDefault"_a =
false);
123 cls.def_static(
"getMaskPlane", Mask<MaskPixelT>::getMaskPlane);
124 cls.def_static(
"getPlaneBitMask", (MaskPixelT(*)(
const std::string &))Mask<MaskPixelT>::getPlaneBitMask);
125 cls.def_static(
"getPlaneBitMask",
126 (MaskPixelT(*)(
const std::vector<std::string> &))Mask<MaskPixelT>::getPlaneBitMask);
127 cls.def_static(
"getNumPlanesMax", Mask<MaskPixelT>::getNumPlanesMax);
128 cls.def_static(
"getNumPlanesUsed", Mask<MaskPixelT>::getNumPlanesUsed);
129 cls.def(
"getMaskPlaneDict", &Mask<MaskPixelT>::getMaskPlaneDict);
130 cls.def(
"printMaskPlanes", &Mask<MaskPixelT>::printMaskPlanes);
131 cls.def_static(
"addMaskPlanesToMetadata", Mask<MaskPixelT>::addMaskPlanesToMetadata);
132 cls.def(
"conformMaskPlanes", &Mask<MaskPixelT>::conformMaskPlanes);
133 cls.def_static(
"addMaskPlane", (
int (*)(
const std::string &))Mask<MaskPixelT>::addMaskPlane);
138 cls.def(
"set", [](Mask<MaskPixelT> &
self, MaskPixelT val) {
self = val; });
143 cls.def(
"set", [](Mask<MaskPixelT> &
self,
int x,
int y,
double val) {
147 cls.def(
"get", [](Mask<MaskPixelT>
const &
self,
int x,
int y) -> MaskPixelT {
151 cls.def(
"get", [](Mask<MaskPixelT>
const &
self,
int x,
int y,
int plane) ->
bool {
157 py::module mod(
"mask");
159 py::module::import(
"lsst.afw.image.image");
161 if (_import_array() < 0) {
162 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
166 declareMask<MaskPixel>(mod,
"X");
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
std::map< std::string, int > MaskPlaneDict
Extent< int, 2 > Extent2I
PYBIND11_PLUGIN(_cameraPoint)
A base class for image defects.
A class used to request that array accesses be checked.