LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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
boost::uint16_t MaskPixel
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
Include files required for standard LSST Exception handling.
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
#define INSTANTIATE(T)
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