Skip to content

Commit

Permalink
Wrap with pybind11 instead of swig
Browse files Browse the repository at this point in the history
  • Loading branch information
kfindeisen authored and Pim Schellart committed Mar 3, 2017
1 parent 5961e7a commit ec0e000
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 87 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ config.log
*.cfgc
*.pyc
*.fits
*_wrap.cc
*Lib.py
doc/html
doc/*.tag
doc/*.inc
Expand Down
4 changes: 3 additions & 1 deletion python/lsst/coadd/utils/SConscript
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.python(['utilsLib'])
scripts.BasicSConscript.pybind11(['addToCoadd',
'copyGoodPixels',
'setCoaddEdgeBits'])
10 changes: 7 additions & 3 deletions python/lsst/coadd/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
# Copyright 2008-2016 AURA/LSST.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
Expand All @@ -17,8 +17,12 @@
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
# see <https://www.lsstcorp.org/LegalNotices/>.
#/

"""lsst.coadd.utils
"""
from __future__ import absolute_import
from .version import *

from .makeBitMask import *
Expand Down
79 changes: 79 additions & 0 deletions python/lsst/coadd/utils/addToCoadd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* LSST Data Management System
* Copyright 2008-2016 AURA/LSST.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>

#include "lsst/coadd/utils/addToCoadd.h"

namespace py = pybind11;
using namespace pybind11::literals;

namespace lsst {
namespace coadd {
namespace utils {

namespace {
template <typename CoaddPixelT, typename WeightPixelT>
void declareAddToCoadd(py::module & mod) {
namespace afwGeom = lsst::afw::geom;
namespace afwImage = lsst::afw::image;

mod.def("addToCoadd", (afwGeom::Box2I (*) (afwImage::Image<CoaddPixelT> &,
afwImage::Image<WeightPixelT> &,
afwImage::Image<CoaddPixelT> const &,
WeightPixelT)) &addToCoadd,
"coadd"_a, "weightMap"_a, "image"_a, "weight"_a);
mod.def("addToCoadd", (afwGeom::Box2I (*) (afwImage::MaskedImage<CoaddPixelT> &,
afwImage::Image<WeightPixelT> &,
afwImage::MaskedImage<CoaddPixelT> const &,
afwImage::MaskPixel const,
WeightPixelT)) &addToCoadd,
"coadd"_a, "weightMap"_a, "maskedImage"_a, "badPixelMask"_a, "weight"_a);
}
}

PYBIND11_PLUGIN(_addToCoadd) {
py::module mod("_addToCoadd", "Python wrapper for afw _addToCoadd library");

/* Module level */
declareAddToCoadd<double, double>(mod);
declareAddToCoadd<double, float>(mod);
declareAddToCoadd<double, int>(mod);
declareAddToCoadd<double, std::uint16_t>(mod);
declareAddToCoadd<float, double>(mod);
declareAddToCoadd<float, float>(mod);
declareAddToCoadd<float, int>(mod);
declareAddToCoadd<float, std::uint16_t>(mod);

/* Member types and enums */

/* Constructors */

/* Operators */

/* Members */

return mod.ptr();
}

}}} // lsst::coadd::utils
70 changes: 70 additions & 0 deletions python/lsst/coadd/utils/copyGoodPixels.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* LSST Data Management System
* Copyright 2008-2016 AURA/LSST.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>

#include "lsst/coadd/utils/copyGoodPixels.h"

namespace py = pybind11;
using namespace pybind11::literals;

namespace lsst {
namespace coadd {
namespace utils {

namespace {
template <typename ImagePixelT>
void declareCopyGoodPixels(py::module & mod) {
namespace afwImage = lsst::afw::image;

mod.def("copyGoodPixels", (int (*) (afwImage::Image<ImagePixelT> &,
afwImage::Image<ImagePixelT> const &)) &copyGoodPixels,
"destImage"_a, "srcImage"_a);
mod.def("copyGoodPixels", (int (*) (afwImage::MaskedImage<ImagePixelT> &,
afwImage::MaskedImage<ImagePixelT> const &,
afwImage::MaskPixel const)) &copyGoodPixels,
"destImage"_a, "srcImage"_a, "badPixelMask"_a);
}
}

PYBIND11_PLUGIN(_copyGoodPixels) {
py::module mod("_copyGoodPixels", "Python wrapper for afw _copyGoodPixels library");

/* Module level */
declareCopyGoodPixels<double>(mod);
declareCopyGoodPixels<float>(mod);
declareCopyGoodPixels<int>(mod);
declareCopyGoodPixels<std::uint16_t>(mod);

/* Member types and enums */

/* Constructors */

/* Operators */

/* Members */

return mod.ptr();
}

}}} // lsst::coadd::utils
2 changes: 1 addition & 1 deletion python/lsst/coadd/utils/makeBitMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def makeBitMask(maskPlaneNameList, doInvert=False):
"""
bitMask = afwImage.MaskU.getPlaneBitMask(maskPlaneNameList)
if doInvert:
bitMask = (2**afwImage.MaskU_getNumPlanesMax() - 1) - bitMask
bitMask = (2**afwImage.MaskU.getNumPlanesMax() - 1) - bitMask
return bitMask
66 changes: 66 additions & 0 deletions python/lsst/coadd/utils/setCoaddEdgeBits.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* LSST Data Management System
* Copyright 2008-2016 AURA/LSST.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the LSST License Statement and
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>

#include "lsst/coadd/utils/setCoaddEdgeBits.h"

namespace py = pybind11;
using namespace pybind11::literals;

namespace lsst {
namespace coadd {
namespace utils {

namespace {
template <typename WeightPixelT>
void declareSetCoaddEdgeBits(py::module & mod) {
namespace afwImage = lsst::afw::image;

mod.def("setCoaddEdgeBits", (void (*) (afwImage::Mask<afwImage::MaskPixel> &,
afwImage::Image<WeightPixelT> const &)) &setCoaddEdgeBits,
"coaddMask"_a, "weightMap"_a);
}
}

PYBIND11_PLUGIN(_setCoaddEdgeBits) {
py::module mod("_setCoaddEdgeBits", "Python wrapper for afw _setCoaddEdgeBits library");

/* Module level */
declareSetCoaddEdgeBits<double>(mod);
declareSetCoaddEdgeBits<float>(mod);
declareSetCoaddEdgeBits<int>(mod);
declareSetCoaddEdgeBits<std::uint16_t>(mod);

/* Member types and enums */

/* Constructors */

/* Operators */

/* Members */

return mod.ptr();
}

}}} // lsst::coadd::utils
77 changes: 0 additions & 77 deletions python/lsst/coadd/utils/utilsLib.i

This file was deleted.

4 changes: 4 additions & 0 deletions python/lsst/coadd/utils/utilsLib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import absolute_import
from ._addToCoadd import *
from ._copyGoodPixels import *
from ._setCoaddEdgeBits import *
1 change: 1 addition & 0 deletions tests/SConscript
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- python -*-
import os
from lsst.sconsUtils import scripts, env

scripts.BasicSConscript.tests()
1 change: 1 addition & 0 deletions tests/testAddToCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

"""Test lsst.coadd.utils.addToCoadd
"""
from __future__ import absolute_import, division, print_function
from builtins import range
import os
import unittest
Expand Down
2 changes: 1 addition & 1 deletion tests/testSetMaskBits.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def countBits(val):
val >>= 1
return nBits

MaxBitMask = (2**afwImage.MaskU_getNumPlanesMax() - 1)
MaxBitMask = (2**afwImage.MaskU.getNumPlanesMax() - 1)

MaskPlaneNameIDDict = dict(afwImage.MaskU().getMaskPlaneDict())

Expand Down
4 changes: 2 additions & 2 deletions ups/coadd_utils.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import lsst.sconsUtils

dependencies = {
"required": ["afw"],
"buildRequired": ["swig"],
"buildRequired": ["pybind11"],
}

config = lsst.sconsUtils.Configuration(
__file__,
headers=["lsst/coadd/utils/addToCoadd.h"],
hasDoxygenInclude=False,
hasSwigFiles=True,
hasSwigFiles=False,
)
1 change: 1 addition & 0 deletions ups/coadd_utils.table
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
setupRequired(afw)
setupRequired(log)
setupRequired(pybind11)
setupRequired(numpy)
setupRequired(pex_config)
setupRequired(pipe_base)
Expand Down

0 comments on commit ec0e000

Please sign in to comment.