lsst.coadd.chisquared  14.0+32
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>
41  // spell out lsst:afw::image to make Doxygen happy
46  lsst::afw::image::VariancePixel> const &image,
47  lsst::afw::image::MaskPixel const badPixelMask,
48  WeightPixelT weight
49 ) {
51  typedef typename afwImage::Image<WeightPixelT> WeightMap;
52 
53  if (coadd.getBBox() != weightMap.getBBox()) {
55  (boost::format("coadd and weightMap parent bboxes differ: %s != %s") %
56  coadd.getBBox() % weightMap.getBBox()).str());
57  }
58 
59  afwGeom::Box2I overlapBBox = coadd.getBBox();
60  overlapBBox.clip(image.getBBox());
61  if (overlapBBox.isEmpty()) {
62  return overlapBBox;
63  }
64 
65  Coadd coaddView(coadd, overlapBBox, afwImage::PARENT, false);
66  WeightMap weightMapView(weightMap, overlapBBox, afwImage::PARENT, false);
67  Coadd imageView(image, overlapBBox, afwImage::PARENT, false);
68 
69  for (int y = 0, endY = imageView.getHeight(); y != endY; ++y) {
70  typename Coadd::const_x_iterator imageIter = imageView.row_begin(y);
71  typename Coadd::const_x_iterator const imageEndIter = imageView.row_end(y);
72  typename Coadd::x_iterator coaddIter = coaddView.row_begin(y);
73  typename WeightMap::x_iterator weightMapIter = weightMapView.row_begin(y);
74  for (; imageIter != imageEndIter; ++imageIter, ++coaddIter, ++weightMapIter) {
75  if ((imageIter.mask() & badPixelMask) == 0) {
76  CoaddPixelT value = imageIter.image() * imageIter.image() / imageIter.variance();
77  coaddIter.image() += value;
78  coaddIter.mask() |= imageIter.mask();
79  *weightMapIter += weight;
80  }
81  }
82  }
83  return overlapBBox;
84 }
85 
86 //
87 // Explicit instantiations
88 //
90 #define MASKEDIMAGE(IMAGEPIXEL) afwImage::MaskedImage<IMAGEPIXEL, \
91  afwImage::MaskPixel, afwImage::VariancePixel>
92 #define INSTANTIATE(COADDPIXEL, WEIGHTPIXEL) \
93  template afwGeom::Box2I coaddChiSq::addToCoadd<COADDPIXEL, WEIGHTPIXEL>( \
94  MASKEDIMAGE(COADDPIXEL) &coadd, \
95  afwImage::Image<WEIGHTPIXEL> &weightMap, \
96  MASKEDIMAGE(COADDPIXEL) const &image, \
97  afwImage::MaskPixel const badPixelMask, \
98  WEIGHTPIXEL weight \
99  );
100 
101 INSTANTIATE(double, double);
102 INSTANTIATE(double, float);
103 INSTANTIATE(double, int);
104 INSTANTIATE(double, std::uint16_t);
105 INSTANTIATE(float, double);
106 INSTANTIATE(float, float);
107 INSTANTIATE(float, int);
108 INSTANTIATE(float, std::uint16_t);
afw::table::Key< afw::table::Array< ImagePixelT > > image
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
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...
#define INSTANTIATE(FROMSYS, TOSYS)
#define LSST_EXCEPT(type,...)
void clip(Box2I const &other)