LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
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 
30 #include "lsst/pex/exceptions.h"
32 
33 namespace pexExcept = lsst::pex::exceptions;
34 namespace afwImage = lsst::afw::image;
35 namespace afwGeom = lsst::afw::geom;
36 namespace coaddChiSq = lsst::coadd::chisquared;
37 
38 template <typename CoaddPixelT, typename WeightPixelT>
40  // spell out lsst:afw::image to make Doxygen happy
46  lsst::afw::image::MaskPixel const badPixelMask,
47  WeightPixelT weight
48 ) {
50  typedef typename afwImage::Image<WeightPixelT> WeightMap;
51 
52  if (coadd.getBBox() != weightMap.getBBox()) {
53  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
54  (boost::format("coadd and weightMap parent bboxes differ: %s != %s") %
55  coadd.getBBox() % weightMap.getBBox()).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) afwImage::MaskedImage<IMAGEPIXEL, \
90  afwImage::MaskPixel, afwImage::VariancePixel>
91 #define INSTANTIATE(COADDPIXEL, WEIGHTPIXEL) \
92  template afwGeom::Box2I coaddChiSq::addToCoadd<COADDPIXEL, WEIGHTPIXEL>( \
93  MASKEDIMAGE(COADDPIXEL) &coadd, \
94  afwImage::Image<WEIGHTPIXEL> &weightMap, \
95  MASKEDIMAGE(COADDPIXEL) const &image, \
96  afwImage::MaskPixel const badPixelMask, \
97  WEIGHTPIXEL weight \
98  );
99 
100 INSTANTIATE(double, double);
101 INSTANTIATE(double, float);
102 INSTANTIATE(double, int);
103 INSTANTIATE(double, boost::uint16_t);
104 INSTANTIATE(float, double);
105 INSTANTIATE(float, float);
106 INSTANTIATE(float, int);
107 INSTANTIATE(float, boost::uint16_t);
int y
tbl::Key< double > weight
Include files required for standard LSST Exception handling.
boost::uint16_t MaskPixel
#define INSTANTIATE(MATCH)
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Definition: Image.h:377
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:166
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
lsst::afw::geom::Box2I addToCoadd(lsst::afw::image::Image< CoaddPixelT > &coadd, lsst::afw::image::Image< WeightPixelT > &weightMap, lsst::afw::image::Image< CoaddPixelT > const &image, WeightPixelT weight)
add good pixels from an image to a coadd and associated weight map
Definition: addToCoadd.cc:126
void clip(Box2I const &other)
Shrink this to ensure that other.contains(*this).
float VariancePixel
! default type for Masks and MaskedImage Masks
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415