Skip to content

Commit

Permalink
Merge pull request #14 from lsst/tickets/DM-14828
Browse files Browse the repository at this point in the history
DM-14828: Update pybind11 wrappers for 2.2
  • Loading branch information
r-owen committed Jul 21, 2018
2 parents 2115a9e + d05e0d9 commit 839ba83
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 88 deletions.
22 changes: 11 additions & 11 deletions include/lsst/coadd/chisquared.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/*
/*
* LSST Data Management System
* Copyright 2008, 2009, 2010 LSST Corporation.
*
*
* 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,
*
* 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/>.
*/

/**
* @brief Include public interface of lsst/coadd/chisquared
*
* @file
*/
* @brief Include public interface of lsst/coadd/chisquared
*
* @file
*/
#include "lsst/coadd/chisquared/addToCoadd.h"
79 changes: 42 additions & 37 deletions include/lsst/coadd/chisquared/addToCoadd.h
Original file line number Diff line number Diff line change
@@ -1,67 +1,72 @@
// -*- LSST-C++ -*-
/*
/*
* LSST Data Management System
* Copyright 2008, 2009, 2010 LSST Corporation.
*
*
* 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,
*
* 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/>.
*/

#ifndef LSST_COADD_CHISQUARED_ADDTOCOADD_H
#define LSST_COADD_CHISQUARED_ADDTOCOADD_H
/**
* @file
*
* @author Russell Owen
*/
* @file
*
* @author Russell Owen
*/
#include "lsst/afw/geom.h"
#include "lsst/afw/image.h"

namespace lsst {
namespace coadd {
namespace chisquared {

/**
* @brief add good pixels from a masked image to a coadd and associated weight map
* using the chi squared algorithm
*
* For good pixels (image.mask & badPixelMask == 0), coadd and weightMap are altered as follows:
* coadd.image += image.image**2 / image.variance
* coadd.mask |= image.mask
* weightMap += weight
* For bad pixels, coadd and weightMap are not altered.
*
* Note that coadd.variance is not altered.
*
* @return overlapBBox: overlapping bounding box, relative to parent image (hence xy0 is taken into account)
*
* @throw pexExcept::InvalidParameterError if coadd and weightMap dimensions or xy0 do not match.
*/
template<typename CoaddPixelT, typename WeightPixelT>
lsst::afw::geom::Box2I addToCoadd(
/**
* @brief add good pixels from a masked image to a coadd and associated weight map
* using the chi squared algorithm
*
* For good pixels (image.mask & badPixelMask == 0), coadd and weightMap are altered as follows:
* coadd.image += image.image**2 / image.variance
* coadd.mask |= image.mask
* weightMap += weight
* For bad pixels, coadd and weightMap are not altered.
*
* Note that coadd.variance is not altered.
*
* @return overlapBBox: overlapping bounding box, relative to parent image (hence xy0 is taken into account)
*
* @throw pexExcept::InvalidParameterError if coadd and weightMap dimensions or xy0 do not match.
*/
template <typename CoaddPixelT, typename WeightPixelT>
lsst::afw::geom::Box2I addToCoadd(
lsst::afw::image::MaskedImage<CoaddPixelT, lsst::afw::image::MaskPixel,
lsst::afw::image::VariancePixel> &coadd, ///< [in,out] coadd to be modified
lsst::afw::image::Image<WeightPixelT> &weightMap, ///< [in,out] weight map to be modified
lsst::afw::image::VariancePixel>
&coadd, ///< [in,out] coadd to be modified
lsst::afw::image::Image<WeightPixelT> &weightMap, ///< [in,out] weight map to be modified
lsst::afw::image::MaskedImage<CoaddPixelT, lsst::afw::image::MaskPixel,
lsst::afw::image::VariancePixel> const &maskedImage, ///< masked image to add to coadd
lsst::afw::image::MaskPixel const badPixelMask, ///< skip input pixel if input mask & badPixelMask !=0
WeightPixelT weight ///< relative weight of this image
);
lsst::afw::image::VariancePixel> const
&maskedImage, ///< masked image to add to coadd
lsst::afw::image::MaskPixel const
badPixelMask, ///< skip input pixel if input mask & badPixelMask !=0
WeightPixelT weight ///< relative weight of this image
);

}}} // lsst::coadd::chisquared
} // namespace chisquared
} // namespace coadd
} // namespace lsst

#endif // !defined(LSST_COADD_CHISQUARED_ADDTOCOADD_H)
#endif // !defined(LSST_COADD_CHISQUARED_ADDTOCOADD_H)
14 changes: 5 additions & 9 deletions python/lsst/coadd/chisquared/addToCoadd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ void declareAddToCoadd(py::module& mod) {
"badPixelMask"_a, "weight"_a);
}

} // namespace lsst::coadd::chisquared::<anonymous>
} // namespace

PYBIND11_PLUGIN(addToCoadd) {
PYBIND11_MODULE(addToCoadd, mod) {
py::module::import("lsst.afw.geom");
py::module::import("lsst.afw.image");

py::module mod("addToCoadd");

declareAddToCoadd<double, double>(mod);
declareAddToCoadd<double, float>(mod);
declareAddToCoadd<double, int>(mod);
Expand All @@ -63,10 +61,8 @@ PYBIND11_PLUGIN(addToCoadd) {
declareAddToCoadd<float, float>(mod);
declareAddToCoadd<float, int>(mod);
declareAddToCoadd<float, std::uint16_t>(mod);

return mod.ptr();
}

} // chisquared
} // coadd
} // lsst
} // namespace chisquared
} // namespace coadd
} // namespace lsst
58 changes: 27 additions & 31 deletions src/addToCoadd.cc
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// -*- LSST-C++ -*-
/*
/*
* LSST Data Management System
* Copyright 2008, 2009, 2010 LSST Corporation.
*
*
* 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,
*
* 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/>.
*/
/**
* @file
*
* @author Russell Owen
*/
* @file
*
* @author Russell Owen
*/
#include <cmath>
#include <cstdint>

Expand All @@ -38,22 +38,21 @@ namespace coaddChiSq = lsst::coadd::chisquared;

template <typename CoaddPixelT, typename WeightPixelT>
afwGeom::Box2I coaddChiSq::addToCoadd(
// spell out lsst:afw::image to make Doxygen happy
lsst::afw::image::MaskedImage<CoaddPixelT, lsst::afw::image::MaskPixel,
lsst::afw::image::VariancePixel> &coadd,
lsst::afw::image::Image<WeightPixelT> &weightMap,
lsst::afw::image::MaskedImage<CoaddPixelT, lsst::afw::image::MaskPixel,
lsst::afw::image::VariancePixel> const &image,
lsst::afw::image::MaskPixel const badPixelMask,
WeightPixelT weight
) {
// spell out lsst:afw::image to make Doxygen happy
lsst::afw::image::MaskedImage<CoaddPixelT, lsst::afw::image::MaskPixel,
lsst::afw::image::VariancePixel> &coadd,
lsst::afw::image::Image<WeightPixelT> &weightMap,
lsst::afw::image::MaskedImage<CoaddPixelT, lsst::afw::image::MaskPixel,
lsst::afw::image::VariancePixel> const &image,
lsst::afw::image::MaskPixel const badPixelMask, WeightPixelT weight) {
typedef typename afwImage::MaskedImage<CoaddPixelT, afwImage::MaskPixel, afwImage::VariancePixel> Coadd;
typedef typename afwImage::Image<WeightPixelT> WeightMap;

if (coadd.getBBox() != weightMap.getBBox()) {
throw LSST_EXCEPT(pexExcept::InvalidParameterError,
(boost::format("coadd and weightMap parent bboxes differ: %s != %s") %
coadd.getBBox() % weightMap.getBBox()).str());
(boost::format("coadd and weightMap parent bboxes differ: %s != %s") %
coadd.getBBox() % weightMap.getBBox())
.str());
}

afwGeom::Box2I overlapBBox = coadd.getBBox();
Expand Down Expand Up @@ -87,16 +86,13 @@ afwGeom::Box2I coaddChiSq::addToCoadd(
// Explicit instantiations
//
/// \cond
#define MASKEDIMAGE(IMAGEPIXEL) afwImage::MaskedImage<IMAGEPIXEL, \
afwImage::MaskPixel, afwImage::VariancePixel>
#define INSTANTIATE(COADDPIXEL, WEIGHTPIXEL) \
template afwGeom::Box2I coaddChiSq::addToCoadd<COADDPIXEL, WEIGHTPIXEL>( \
MASKEDIMAGE(COADDPIXEL) &coadd, \
afwImage::Image<WEIGHTPIXEL> &weightMap, \
MASKEDIMAGE(COADDPIXEL) const &image, \
afwImage::MaskPixel const badPixelMask, \
WEIGHTPIXEL weight \
);
#define MASKEDIMAGE(IMAGEPIXEL) \
afwImage::MaskedImage<IMAGEPIXEL, afwImage::MaskPixel, afwImage::VariancePixel>
#define INSTANTIATE(COADDPIXEL, WEIGHTPIXEL) \
template afwGeom::Box2I coaddChiSq::addToCoadd<COADDPIXEL, WEIGHTPIXEL>( \
MASKEDIMAGE(COADDPIXEL) & coadd, afwImage::Image<WEIGHTPIXEL> & weightMap, \
MASKEDIMAGE(COADDPIXEL) const &image, afwImage::MaskPixel const badPixelMask, \
WEIGHTPIXEL weight);

INSTANTIATE(double, double);
INSTANTIATE(double, float);
Expand Down

0 comments on commit 839ba83

Please sign in to comment.