LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
MaskedImage.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
29 #include <typeinfo>
30 #include <sys/stat.h>
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wunused-variable"
33 #include "boost/lambda/lambda.hpp"
34 #pragma clang diagnostic pop
35 #include "boost/regex.hpp"
36 #include "boost/filesystem/path.hpp"
37 #include "lsst/pex/logging/Trace.h"
38 #include "lsst/pex/exceptions.h"
39 #include "boost/algorithm/string/trim.hpp"
40 
43 #include "lsst/afw/fits.h"
44 
45 namespace bl = boost::lambda;
46 namespace image = lsst::afw::image;
47 
52 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
54  unsigned int width,
55  unsigned int height,
56  MaskPlaneDict const& planeDict
57 ) :
58  lsst::daf::base::Citizen(typeid(this)),
59  _image(new Image(width, height)),
60  _mask(new Mask(width, height, planeDict)),
61  _variance(new Variance(width, height)) {
62  *_image = 0;
63  *_mask = 0x0;
64  *_variance = 0;
65 }
66 
71 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
73  geom::Extent2I const & dimensions,
74  MaskPlaneDict const& planeDict
75 ) :
76  lsst::daf::base::Citizen(typeid(this)),
77  _image(new Image(dimensions)),
78  _mask(new Mask(dimensions, planeDict)),
79  _variance(new Variance(dimensions)) {
80  *_image = 0;
81  *_mask = 0x0;
82  *_variance = 0;
83 }
84 
93 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
95  geom::Box2I const & bbox,
96  MaskPlaneDict const& planeDict
97 ) :
98  lsst::daf::base::Citizen(typeid(this)),
99  _image(new Image(bbox)),
100  _mask(new Mask(bbox, planeDict)),
101  _variance(new Variance(bbox)) {
102  *_image = 0;
103  *_mask = 0x0;
104  *_variance = 0;
105 }
106 
107 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
109  std::string const & fileName, PTR(daf::base::PropertySet) metadata,
110  geom::Box2I const & bbox, ImageOrigin origin, bool conformMasks, bool needAllHdus,
111  PTR(daf::base::PropertySet) imageMetadata,
112  PTR(daf::base::PropertySet) maskMetadata,
113  PTR(daf::base::PropertySet) varianceMetadata
114 ) : lsst::daf::base::Citizen(typeid(this)),
115  _image(), _mask(), _variance()
116 {
117  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
118  *this = MaskedImage(fitsfile, metadata, bbox, origin, conformMasks, needAllHdus,
119  imageMetadata, maskMetadata, varianceMetadata);
120  }
121 
122 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
124  fits::MemFileManager & manager, PTR(daf::base::PropertySet) metadata,
125  geom::Box2I const & bbox, ImageOrigin origin, bool conformMasks, bool needAllHdus,
126  PTR(daf::base::PropertySet) imageMetadata,
127  PTR(daf::base::PropertySet) maskMetadata,
128  PTR(daf::base::PropertySet) varianceMetadata
129 ) : lsst::daf::base::Citizen(typeid(this)),
130  _image(), _mask(), _variance()
131 {
132  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
133  *this = MaskedImage(fitsfile, metadata, bbox, origin, conformMasks, needAllHdus,
134  imageMetadata, maskMetadata, varianceMetadata);
135 }
136 
137 namespace {
138 
139 // Helper functions for MaskedImage FITS ctor.
140 
141 void checkExtType(
142  lsst::afw::fits::Fits & fitsfile,
144  std::string const & expected
145 ) {
146  try {
147  std::string exttype = boost::algorithm::trim_right_copy(metadata->getAsString("EXTTYPE"));
148  if (exttype != "" && exttype != expected) {
149  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
150  (boost::format("Reading %s (hdu %d) Expected EXTTYPE==\"%s\", saw \"%s\"") %
151  expected % fitsfile.getFileName() % fitsfile.getHdu() % exttype).str());
152  }
153  metadata->remove("EXTTYPE");
154  } catch(lsst::pex::exceptions::NotFoundError) {
156  log.warn(boost::format("Expected extension type not found: %s") % expected);
157  }
158 }
159 
160 void ensureMetadata(PTR(lsst::daf::base::PropertySet) & metadata) {
161  if (!metadata) {
162  metadata.reset(new lsst::daf::base::PropertyList());
163  }
164 }
165 
166 } // anonymous
167 
168 
169 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
171  fits::Fits & fitsfile, PTR(daf::base::PropertySet) metadata,
172  geom::Box2I const & bbox, ImageOrigin origin, bool conformMasks, bool needAllHdus,
173  PTR(daf::base::PropertySet) imageMetadata,
174  PTR(daf::base::PropertySet) maskMetadata,
175  PTR(daf::base::PropertySet) varianceMetadata
176 ) : lsst::daf::base::Citizen(typeid(this)),
177  _image(), _mask(), _variance()
178 {
179  // When reading a standard Masked Image, we expect four HDUs:
180  // * The primary (HDU 1) is empty;
181  // * The first extension (HDU 2) contains the image data;
182  // * The second extension (HDU 3) contains mask data;
183  // * The third extension (HDU 4) contains the variance.
184  //
185  // If the image HDU is unreadable, we will throw.
186  //
187  // If the user has specified a non-default HDU, we load image data from
188  // that HDU, but do not attempt to load mask/variance data; rather, log a
189  // warning and return (blank) defaults.
190  //
191  // If the mask and/or variance is unreadable, we log a warning and return
192  // (blank) defaults.
193 
194  // We log warnings about image loading through a child logger, so the user
195  // can disable them if required.
196  pex::logging::Log log(pex::logging::Log::getDefaultLog(), "afw.image.MaskedImage");
197 
198  enum class Hdu {
199  Primary = 1,
200  Image,
201  Mask,
202  Variance
203  };
204 
205  // If the user has requested a non-default HDU and we require all HDUs, we fail.
206  if (needAllHdus && fitsfile.getHdu() > static_cast<int>(Hdu::Image)) {
207  throw LSST_EXCEPT(fits::FitsError,
208  "Cannot read all HDUs starting from non-default");
209  }
210 
211  if (metadata) {
212  // Read primary metadata - only if user asks for it.
213  // If the primary HDU is not empty, this may be the same as imageMetadata.
214  auto prevHdu = fitsfile.getHdu();
215  fitsfile.setHdu(static_cast<int>(Hdu::Primary));
216  fitsfile.readMetadata(*metadata);
217  fitsfile.setHdu(prevHdu);
218  }
219 
220  // setHdu(0) jumps to the first extension iff the primary HDU is both
221  // empty and currently selected.
222  fitsfile.setHdu(0);
223  ensureMetadata(imageMetadata);
224  _image.reset(new Image(fitsfile, imageMetadata, bbox, origin));
225  checkExtType(fitsfile, imageMetadata, "IMAGE");
226 
227  if (fitsfile.getHdu() != static_cast<int>(Hdu::Image)) {
228  // Reading the image from a non-default HDU means we do not attempt to
229  // read mask and variance.
230  _mask.reset(new Mask(_image->getBBox()));
231  _variance.reset(new Variance(_image->getBBox()));
232  } else {
233  try {
234  fitsfile.setHdu(static_cast<int>(Hdu::Mask));
235  ensureMetadata(maskMetadata);
236  _mask.reset(new Mask(fitsfile, maskMetadata, bbox, origin, conformMasks));
237  checkExtType(fitsfile, maskMetadata, "MASK");
238  } catch(fits::FitsError &e) {
239  if (needAllHdus) {
240  LSST_EXCEPT_ADD(e, "Reading Mask");
241  throw e;
242  }
243  log.warn("Mask unreadable; using default");
244  // By resetting the status we are able to read the next HDU (the variance).
245  fitsfile.status = 0;
246  _mask.reset(new Mask(_image->getBBox()));
247  }
248 
249  try {
250  fitsfile.setHdu(static_cast<int>(Hdu::Variance));
251  ensureMetadata(varianceMetadata);
252  _variance.reset(new Variance(fitsfile, varianceMetadata, bbox, origin));
253  checkExtType(fitsfile, varianceMetadata, "VARIANCE");
254  } catch(fits::FitsError &e) {
255  if (needAllHdus) {
256  LSST_EXCEPT_ADD(e, "Reading Variance");
257  throw e;
258  }
259  log.warn("Variance unreadable; using default");
260  fitsfile.status = 0;
261  _variance.reset(new Variance(_image->getBBox()));
262  }
263  }
264 }
265 
270 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
272  ImagePtr image,
273  MaskPtr mask,
274  VariancePtr variance
275 ) :
276  lsst::daf::base::Citizen(typeid(this)),
277  _image(image),
278  _mask(mask),
279  _variance(variance) {
280  conformSizes();
281 }
282 
286 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
288  MaskedImage const& rhs,
289  bool deep
290 ) :
291  lsst::daf::base::Citizen(typeid(this)),
292  _image(rhs._image), _mask(rhs._mask), _variance(rhs._variance) {
293  if (deep) {
294  _image = typename Image::Ptr(new Image(*rhs.getImage(), deep));
295  _mask = typename Mask::Ptr(new Mask(*rhs.getMask(), deep));
296  _variance = typename Variance::Ptr(new Variance(*rhs.getVariance(), deep));
297  }
298  conformSizes();
299 }
300 
304 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
306  MaskedImage const& rhs,
307  const geom::Box2I& bbox,
308  ImageOrigin const origin,
309  bool deep
310 ) :
312  lsst::daf::base::Citizen(typeid(this)),
313  _image(new Image(*rhs.getImage(), bbox, origin, deep)),
314  _mask(rhs._mask ? new Mask(*rhs.getMask(), bbox, origin, deep) : static_cast<Mask *>(NULL)),
315  _variance(rhs._variance ? new Variance(*rhs.getVariance(), bbox, origin, deep) : static_cast<Variance *>(NULL)) {
316  conformSizes();
317 }
318 
319 #if defined(DOXYGEN)
320 
327 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
329  ) {}
330 #endif
331 
332 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
334  using std::swap; // See Meyers, Effective C++, Item 25
335 
336  _image.swap(rhs._image);
337  _mask.swap(rhs._mask);
338  _variance.swap(rhs._variance);
339 }
340 // Use compiler generated version of:
341 // MaskedImage<ImagePixelT, MaskPixelT> &operator=(const MaskedImage<ImagePixelT, MaskPixelT>& rhs);
342 
343 /************************************************************************************************************/
344 // Operators
348 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
351  *_image = rhs.image();
352  *_mask = rhs.mask();
353  *_variance = rhs.variance();
354 
355  return *this;
356 }
357 
361 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
364  *_image = rhs.image();
365  *_mask = rhs.mask();
366  *_variance = rhs.variance();
367 
368  return *this;
369 }
370 
376 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
378  *_image <<= *rhs.getImage();
379  *_mask <<= *rhs.getMask();
380  *_variance <<= *rhs.getVariance();
381 }
382 
390 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
392  *_image += *rhs.getImage();
393  *_mask |= *rhs.getMask();
394  *_variance += *rhs.getVariance();
395 }
396 
404 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
406  MaskedImage const& rhs) {
407  (*_image).scaledPlus(c, *rhs.getImage());
408  *_mask |= *rhs.getMask();
409  (*_variance).scaledPlus(c*c, *rhs.getVariance());
410 }
411 
413 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
415  *_image += rhs;
416 }
417 
423 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
425  *_image -= *rhs.getImage();
426  *_mask |= *rhs.getMask();
427  *_variance += *rhs.getVariance();
428 }
429 
435 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
437  MaskedImage const& rhs) {
438  (*_image).scaledMinus(c, *rhs.getImage());
439  *_mask |= *rhs.getMask();
440  (*_variance).scaledPlus(c*c, *rhs.getVariance());
441 }
442 
444 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
446  *_image -= rhs;
447 }
448 
449 namespace {
451  template<typename ImagePixelT, typename VariancePixelT>
452  struct productVariance {
453  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
454  return lhs*lhs*varRhs + rhs*rhs*varLhs;
455  }
456  };
457 
459  template<typename ImagePixelT, typename VariancePixelT>
460  struct scaledProductVariance {
461  double _c;
462  scaledProductVariance(double const c) : _c(c) {}
463  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
464  return _c*_c*(lhs*lhs*varRhs + rhs*rhs*varLhs);
465  }
466  };
467 }
468 
469 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
471  // Must do variance before we modify the image values
472  transform_pixels(_image->_getRawView(), // lhs
473  rhs._image->_getRawView(), // rhs,
474  _variance->_getRawView(), // Var(lhs),
475  rhs._variance->_getRawView(), // Var(rhs)
476  _variance->_getRawView(), // result
477  productVariance<ImagePixelT, VariancePixelT>());
478 
479  *_image *= *rhs.getImage();
480  *_mask |= *rhs.getMask();
481 }
482 
483 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
485  MaskedImage const& rhs) {
486  // Must do variance before we modify the image values
487  transform_pixels(_image->_getRawView(), // lhs
488  rhs._image->_getRawView(), // rhs,
489  _variance->_getRawView(), // Var(lhs),
490  rhs._variance->_getRawView(), // Var(rhs)
491  _variance->_getRawView(), // result
492  scaledProductVariance<ImagePixelT, VariancePixelT>(c));
493 
494  (*_image).scaledMultiplies(c, *rhs.getImage());
495  *_mask |= *rhs.getMask();
496 }
497 
498 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
500  *_image *= rhs;
501  *_variance *= rhs*rhs;
502 }
503 
504 
505 namespace {
507  template<typename ImagePixelT, typename VariancePixelT>
508  struct quotientVariance {
509  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
510  ImagePixelT const rhs2 = rhs*rhs;
511  return (lhs*lhs*varRhs + rhs2*varLhs)/(rhs2*rhs2);
512  }
513  };
515  template<typename ImagePixelT, typename VariancePixelT>
516  struct scaledQuotientVariance {
517  double _c;
518  scaledQuotientVariance(double c) : _c(c) {}
519  double operator()(ImagePixelT lhs, ImagePixelT rhs, VariancePixelT varLhs, VariancePixelT varRhs) {
520  ImagePixelT const rhs2 = rhs*rhs;
521  return (lhs*lhs*varRhs + rhs2*varLhs)/(_c*_c*rhs2*rhs2);
522  }
523  };
524 }
525 
526 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
528  // Must do variance before we modify the image values
529  transform_pixels(_image->_getRawView(), // lhs
530  rhs._image->_getRawView(), // rhs,
531  _variance->_getRawView(), // Var(lhs),
532  rhs._variance->_getRawView(), // Var(rhs)
533  _variance->_getRawView(), // result
534  quotientVariance<ImagePixelT, VariancePixelT>());
535 
536  *_image /= *rhs.getImage();
537  *_mask |= *rhs.getMask();
538 }
539 
540 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
542  MaskedImage const& rhs) {
543  // Must do variance before we modify the image values
544  transform_pixels(_image->_getRawView(), // lhs
545  rhs._image->_getRawView(), // rhs,
546  _variance->_getRawView(), // Var(lhs),
547  rhs._variance->_getRawView(), // Var(rhs)
548  _variance->_getRawView(), // result
549  scaledQuotientVariance<ImagePixelT, VariancePixelT>(c));
550 
551  (*_image).scaledDivides(c, *rhs.getImage());
552  *_mask |= *rhs._mask;
553 }
554 
555 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
557  *_image /= rhs;
558  *_variance /= rhs*rhs;
559 }
560 
561 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
563  std::string const& fileName,
565  CONST_PTR(daf::base::PropertySet) imageMetadata,
566  CONST_PTR(daf::base::PropertySet) maskMetadata,
567  CONST_PTR(daf::base::PropertySet) varianceMetadata
568 ) const {
569  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
570  writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
571 }
572 
573 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
575  fits::MemFileManager & manager,
577  CONST_PTR(daf::base::PropertySet) imageMetadata,
578  CONST_PTR(daf::base::PropertySet) maskMetadata,
579  CONST_PTR(daf::base::PropertySet) varianceMetadata
580 ) const {
581  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
582  writeFits(fitsfile, metadata, imageMetadata, maskMetadata, varianceMetadata);
583 }
584 
585 namespace {
586 
587 void processPlaneMetadata(
590  char const * exttype
591 ) {
592  if (metadata) {
593  hdr = metadata->deepCopy();
594  } else {
595  hdr.reset(new lsst::daf::base::PropertyList());
596  }
597  hdr->set("INHERIT", true);
598  hdr->set("EXTTYPE", exttype);
599 }
600 
601 } // anonymous
602 
603 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
605  fits::Fits & fitsfile,
607  CONST_PTR(daf::base::PropertySet) imageMetadata,
608  CONST_PTR(daf::base::PropertySet) maskMetadata,
609  CONST_PTR(daf::base::PropertySet) varianceMetadata
610 ) const {
611 
613  if (metadata) {
614  hdr = metadata->deepCopy();
615  } else {
616  hdr.reset(new daf::base::PropertyList());
617  }
618 
619  if (fitsfile.countHdus() != 0) {
620  throw LSST_EXCEPT(
621  pex::exceptions::LogicError,
622  "MaskedImage::writeFits can only write to an empty file"
623  );
624  }
625  if (fitsfile.getHdu() <= 1) {
626  // Don't ever write images to primary; instead we make an empty primary.
627  fitsfile.createEmpty();
628  } else {
629  fitsfile.setHdu(1);
630  }
631  fitsfile.writeMetadata(*hdr);
632 
633  processPlaneMetadata(imageMetadata, hdr, "IMAGE");
634  _image->writeFits(fitsfile, hdr);
635 
636  processPlaneMetadata(maskMetadata, hdr, "MASK");
637  _mask->writeFits(fitsfile, hdr);
638 
639  processPlaneMetadata(varianceMetadata, hdr, "VARIANCE");
640  _variance->writeFits(fitsfile, hdr);
641 }
642 
643 /************************************************************************************************************/
644 // private function conformSizes() ensures that the Mask and Variance have the same dimensions
645 // as Image. If Mask and/or Variance have non-zero dimensions that conflict with the size of Image,
646 // a lsst::pex::exceptions::LengthError is thrown.
647 
648 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
650 
651  if (!_mask || _mask->getWidth() == 0 || _mask->getHeight() == 0) {
652  _mask = MaskPtr(new Mask(_image->getBBox()));
653  *_mask = 0;
654  } else {
655  if (_mask->getDimensions() != _image->getDimensions()) {
656  throw LSST_EXCEPT(
657  lsst::pex::exceptions::LengthError,
658  (boost::format("Dimension mismatch: Image %dx%d v. Mask %dx%d") %
659  _image->getWidth() % _image->getHeight() %
660  _mask->getWidth() % _mask->getHeight()
661  ).str()
662  );
663  }
664  }
665 
666  if (!_variance || _variance->getWidth() == 0 || _variance->getHeight() == 0) {
667  _variance = VariancePtr(new Variance(_image->getBBox()));
668  *_variance = 0;
669  } else {
670  if (_variance->getDimensions() != _image->getDimensions()) {
671  throw LSST_EXCEPT(
672  lsst::pex::exceptions::LengthError,
673  (boost::format("Dimension mismatch: Image %dx%d v. Variance %dx%d") %
674  _image->getWidth() % _image->getHeight() %
675  _variance->getWidth() % _variance->getHeight()
676  ).str()
677  );
678  }
679  }
680 }
681 
682 /************************************************************************************************************/
683 //
684 // Iterators and locators
685 //
687 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
689 #if 0 // this doesn't compile; why?
690  return iterator(_image->begin(), _mask->begin(), _variance->begin());
691 #else
692  typename Image::iterator imageBegin = _image->begin();
693  typename Mask::iterator maskBegin = _mask->begin();
694  typename Variance::iterator varianceBegin = _variance->begin();
695 
696  return iterator(imageBegin, maskBegin, varianceBegin);
697 #endif
698 }
699 
701 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
703  typename Image::iterator imageEnd = getImage()->end();
704  typename Mask::iterator maskEnd = getMask()->end();
705  typename Variance::iterator varianceEnd = getVariance()->end();
706 
707  return iterator(imageEnd, maskEnd, varianceEnd);
708 }
709 
711 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
713  typename Image::iterator imageEnd = getImage()->at(x, y);
714  typename Mask::iterator maskEnd = getMask()->at(x, y);
715  typename Variance::iterator varianceEnd = getVariance()->at(x, y);
716 
717  return iterator(imageEnd, maskEnd, varianceEnd);
718 }
719 
721 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
723  typename Image::reverse_iterator imageBegin = _image->rbegin();
724  typename Mask::reverse_iterator maskBegin = _mask->rbegin();
725  typename Variance::reverse_iterator varianceBegin = _variance->rbegin();
726 
727  return reverse_iterator(imageBegin, maskBegin, varianceBegin);
728 }
729 
731 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
733  typename Image::reverse_iterator imageEnd = getImage()->rend();
734  typename Mask::reverse_iterator maskEnd = getMask()->rend();
735  typename Variance::reverse_iterator varianceEnd = getVariance()->rend();
736 
737  return reverse_iterator(imageEnd, maskEnd, varianceEnd);
738 }
739 
741 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
743  typename Image::x_iterator imageBegin = _image->row_begin(y);
744  typename Mask::x_iterator maskBegin = _mask->row_begin(y);
745  typename Variance::x_iterator varianceBegin = _variance->row_begin(y);
746 
747  return x_iterator(imageBegin, maskBegin, varianceBegin);
748 }
749 
751 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
753  typename Image::x_iterator imageEnd = getImage()->row_end(y);
754  typename Mask::x_iterator maskEnd = getMask()->row_end(y);
755  typename Variance::x_iterator varianceEnd = getVariance()->row_end(y);
756 
757  return x_iterator(imageEnd, maskEnd, varianceEnd);
758 }
759 
760 /************************************************************************************************************/
761 
763 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
765  typename Image::y_iterator imageBegin = _image->col_begin(x);
766  typename Mask::y_iterator maskBegin = _mask->col_begin(x);
767  typename Variance::y_iterator varianceBegin = _variance->col_begin(x);
768 
769  return y_iterator(imageBegin, maskBegin, varianceBegin);
770 }
771 
773 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
775  typename Image::y_iterator imageEnd = getImage()->col_end(x);
776  typename Mask::y_iterator maskEnd = getMask()->col_end(x);
777  typename Variance::y_iterator varianceEnd = getVariance()->col_end(x);
778 
779  return y_iterator(imageEnd, maskEnd, varianceEnd);
780 }
781 
782 /************************************************************************************************************/
790 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
793  bool contiguous
794  ) const {
795  typename Image::fast_iterator imageBegin = _image->begin(contiguous);
796  typename Mask::fast_iterator maskBegin = _mask->begin(contiguous);
797  typename Variance::fast_iterator varianceBegin = _variance->begin(contiguous);
798 
799  return fast_iterator(imageBegin, maskBegin, varianceBegin);
800 }
801 
807 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
810  bool contiguous
811  ) const {
812  typename Image::fast_iterator imageEnd = getImage()->end(contiguous);
813  typename Mask::fast_iterator maskEnd = getMask()->end(contiguous);
814  typename Variance::fast_iterator varianceEnd = getVariance()->end(contiguous);
815 
816  return fast_iterator(imageEnd, maskEnd, varianceEnd);
817 }
818 
819 /************************************************************************************************************/
820 //
821 // Explicit instantiations
822 //
824 template class image::MaskedImage<int>;
825 template class image::MaskedImage<float>;
826 template class image::MaskedImage<double>;
828 
int y
MaskPixelT mask() const
Definition: Pixel.h:81
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
Mask< MaskPixelT >::Ptr MaskPtr
shared pointer to the Mask
Definition: MaskedImage.h:83
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:869
Image< VariancePixelT >::Ptr VariancePtr
shared pointer to the variance Image
Definition: MaskedImage.h:85
x_iterator fast_iterator
Definition: Image.h:154
#define PTR(...)
Definition: base.h:41
Mask< MaskPixelT >::MaskPlaneDict MaskPlaneDict
The Mask&#39;s MaskPlaneDict.
Definition: MaskedImage.h:90
void setHdu(int hdu, bool relative=false)
Set the current HDU.
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:291
iterator end() const
Return an iterator to the end of the image.
Definition: MaskedImage.cc:702
void scaledDivides(double const c, MaskedImage const &rhs)
Definition: MaskedImage.cc:541
virtual void remove(std::string const &name)
Definition: PropertySet.cc:754
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
VariancePixelT variance() const
Return the variance part of a Pixel.
Definition: Pixel.h:203
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
iterator at(int const x, int const y) const
Return an iterator at the point (x, y)
Definition: MaskedImage.cc:712
void operator-=(ImagePixelT const rhs)
Subtract a scalar rhs from a MaskedImage.
Definition: MaskedImage.cc:445
y_iterator col_begin(int x) const
Return an y_iterator to the start of the image.
Definition: MaskedImage.cc:764
_view_t::y_iterator y_iterator
An iterator for traversing the pixels in a column.
Definition: Image.h:160
#define CONST_PTR(...)
Definition: base.h:47
definition of the Trace messaging facilities
MaskedImage(unsigned int width, unsigned int height, MaskPlaneDict const &planeDict=MaskPlaneDict())
Construct from a supplied dimensions. The Image, Mask, and Variance will be set to zero...
Definition: MaskedImage.cc:53
A single pixel of the same type as a MaskedImage.
Definition: Pixel.h:63
x_iterator row_end(int y) const
Return an x_iterator to the end of the image.
Definition: MaskedImage.cc:752
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
lsst::afw::image::Mask< MaskPixelT > Mask
Definition: MaskedImage.h:94
boost::shared_ptr< Image< PixelT > > Ptr
Definition: Image.h:418
void set(std::string const &name, T const &value)
Definition: PropertySet.cc:581
a place to record messages and descriptions of the state of processing.
Definition: Log.h:154
static Log & getDefaultLog()
ImagePixelT image() const
Definition: Pixel.h:80
void swap(MaskedImage &rhs)
Definition: MaskedImage.cc:333
ImagePixelT image() const
Return the image part of a Pixel.
Definition: Pixel.h:199
boost::shared_ptr< Mask > Ptr
Definition: Mask.h:95
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
_view_t::iterator iterator
An STL compliant iterator.
Definition: Image.h:143
An iterator to the MaskedImage.
Definition: MaskedImage.h:109
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:890
std::string getFileName() const
Return the file name associated with the FITS object or &quot;&lt;unknown&gt;&quot; if there is none.
afw::table::PointKey< int > dimensions
def log
Definition: log.py:85
lsst::afw::image::Image< ImagePixelT > Image
Definition: MaskedImage.h:93
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:93
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:106
lsst::afw::image::Image< VariancePixelT > Variance
Definition: MaskedImage.h:92
int getHdu()
Return the current HDU (1-indexed; 1 is the Primary HDU).
void writeFits(std::string const &fileName, boost::shared_ptr< daf::base::PropertySet const > metadata=boost::shared_ptr< daf::base::PropertySet const >(), boost::shared_ptr< daf::base::PropertySet const > imageMetadata=boost::shared_ptr< daf::base::PropertySet const >(), boost::shared_ptr< daf::base::PropertySet const > maskMetadata=boost::shared_ptr< daf::base::PropertySet const >(), boost::shared_ptr< daf::base::PropertySet const > varianceMetadata=boost::shared_ptr< daf::base::PropertySet const >()) const
Write a MaskedImage to a regular FITS file.
Definition: MaskedImage.cc:562
void operator*=(ImagePixelT const rhs)
Definition: MaskedImage.cc:499
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
_view_t::reverse_iterator reverse_iterator
An STL compliant reverse iterator.
Definition: Image.h:147
Image< ImagePixelT >::Ptr ImagePtr
shared pointer to the Image
Definition: MaskedImage.h:81
void operator/=(ImagePixelT const rhs)
Definition: MaskedImage.cc:556
MaskedImage & operator=(MaskedImage const &rhs)
Make the lhs use the rhs&#39;s pixels.
Definition: MaskedImage.cc:328
int x
void operator<<=(MaskedImage const &rhs)
Definition: MaskedImage.cc:377
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A pixel of a MaskedImage.
Definition: Pixel.h:137
MaskPixelT mask() const
Return the mask part of a Pixel.
Definition: Pixel.h:201
MaskPtr getMask(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:879
VariancePixelT variance() const
Definition: Pixel.h:82
void scaledMultiplies(double const c, MaskedImage const &rhs)
Definition: MaskedImage.cc:484
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: Image.h:151
Class for storing generic metadata.
Definition: PropertySet.h:82
void warn(const std::string &message, const lsst::daf::base::PropertySet &properties)
Definition: Log.h:494
virtual Ptr deepCopy(void) const
Definition: PropertySet.cc:70
std::string getAsString(std::string const &name) const
Definition: PropertySet.cc:444
reverse_iterator rbegin() const
Return a reverse_iterator to the start of the image.
Definition: MaskedImage.cc:722
int countHdus()
Return the number of HDUs in the file.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the image.
Definition: MaskedImage.cc:742
Implementation of the Class MaskedImage.
void operator+=(ImagePixelT const rhs)
Add a scalar rhs to a MaskedImage.
Definition: MaskedImage.cc:414
reverse_iterator rend() const
Return a reverse_iterator to the end of the image.
Definition: MaskedImage.cc:732
#define LSST_EXCEPT_ADD(e, m)
Definition: Exception.h:51
y_iterator col_end(int x) const
Return an y_iterator to the end of the image.
Definition: MaskedImage.cc:774
void scaledMinus(double const c, MaskedImage const &rhs)
Definition: MaskedImage.cc:436
void scaledPlus(double const c, MaskedImage const &rhs)
Definition: MaskedImage.cc:405
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
iterator begin() const
Return an iterator to the start of the image.
Definition: MaskedImage.cc:688
Include files required for standard LSST Exception handling.