lsst.coadd.chisquared  16.0-2-g839ba83+43
addToCoadd.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
28 #include <cmath>
29 #include <cstdint>
30 
31 #include "lsst/pex/exceptions.h"
33 
35 namespace afwImage = lsst::afw::image;
36 namespace afwGeom = lsst::afw::geom;
38 
39 template <typename CoaddPixelT, typename WeightPixelT>
40 afwGeom::Box2I coaddChiSq::addToCoadd(
41  // spell out lsst:afw::image to make Doxygen happy
46  lsst::afw::image::VariancePixel> const &image,
47  lsst::afw::image::MaskPixel const badPixelMask, WeightPixelT weight) {
49  typedef typename afwImage::Image<WeightPixelT> WeightMap;
50 
51  if (coadd.getBBox() != weightMap.getBBox()) {
53  (boost::format("coadd and weightMap parent bboxes differ: %s != %s") %
54  coadd.getBBox() % weightMap.getBBox())
55  .str());
56  }
57 
58  afwGeom::Box2I overlapBBox = coadd.getBBox();
59  overlapBBox.clip(image.getBBox());
60  if (overlapBBox.isEmpty()) {
61  return overlapBBox;
62  }
63 
64  Coadd coaddView(coadd, overlapBBox, afwImage::PARENT, false);
65  WeightMap weightMapView(weightMap, overlapBBox, afwImage::PARENT, false);
66  Coadd imageView(image, overlapBBox, afwImage::PARENT, false);
67 
68  for (int y = 0, endY = imageView.getHeight(); y != endY; ++y) {
69  typename Coadd::const_x_iterator imageIter = imageView.row_begin(y);
70  typename Coadd::const_x_iterator const imageEndIter = imageView.row_end(y);
71  typename Coadd::x_iterator coaddIter = coaddView.row_begin(y);
72  typename WeightMap::x_iterator weightMapIter = weightMapView.row_begin(y);
73  for (; imageIter != imageEndIter; ++imageIter, ++coaddIter, ++weightMapIter) {
74  if ((imageIter.mask() & badPixelMask) == 0) {
75  CoaddPixelT value = imageIter.image() * imageIter.image() / imageIter.variance();
76  coaddIter.image() += value;
77  coaddIter.mask() |= imageIter.mask();
78  *weightMapIter += weight;
79  }
80  }
81  }
82  return overlapBBox;
83 }
84 
85 //
86 // Explicit instantiations
87 //
89 #define MASKEDIMAGE(IMAGEPIXEL) \
90  afwImage::MaskedImage<IMAGEPIXEL, afwImage::MaskPixel, afwImage::VariancePixel>
91 #define INSTANTIATE(COADDPIXEL, WEIGHTPIXEL) \
92  template afwGeom::Box2I coaddChiSq::addToCoadd<COADDPIXEL, WEIGHTPIXEL>( \
93  MASKEDIMAGE(COADDPIXEL) & coadd, afwImage::Image<WEIGHTPIXEL> & weightMap, \
94  MASKEDIMAGE(COADDPIXEL) const &image, afwImage::MaskPixel const badPixelMask, \
95  WEIGHTPIXEL weight);
96 
97 INSTANTIATE(double, double);
98 INSTANTIATE(double, float);
99 INSTANTIATE(double, int);
100 INSTANTIATE(double, std::uint16_t);
101 INSTANTIATE(float, double);
102 INSTANTIATE(float, float);
103 INSTANTIATE(float, int);
104 INSTANTIATE(float, std::uint16_t);
afw::table::Key< afw::table::Array< ImagePixelT > > image
lsst::afw::geom::Box2I addToCoadd(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 &maskedImage, lsst::afw::image::MaskPixel const badPixelMask, WeightPixelT weight)
add good pixels from a masked image to a coadd and associated weight map using the chi squared algori...
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
#define INSTANTIATE(FROMSYS, TOSYS)
#define LSST_EXCEPT(type,...)
int y