lsst.afw  22.0.1-24-g2e899d296+4206820b0d
Mask.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2016 AURA/LSST.
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 
25 /*
26  * The fundamental type defined here is Mask; a 2-d array of pixels. Each of
27  * these pixels should be thought of as a set of bits, and the names of these
28  * bits are given by MaskPlaneDict (which is implemented as a std::map)
29  */
30 
31 #include <functional>
32 #include <list>
33 #include <string>
34 
35 #pragma clang diagnostic push
36 #pragma clang diagnostic ignored "-Wunused-variable"
37 #pragma clang diagnostic pop
38 #include "boost/format.hpp"
39 
40 #include "boost/functional/hash.hpp"
41 
42 #include "lsst/daf/base.h"
43 #include "lsst/geom.h"
44 #include "lsst/pex/exceptions.h"
45 #include "lsst/log/Log.h"
46 #include "lsst/afw/image/Mask.h"
50 
51 namespace dafBase = lsst::daf::base;
53 
54 namespace lsst {
55 namespace afw {
56 namespace image {
57 
58 namespace {} // namespace
59 
60 template <typename MaskPixelT>
61 void Mask<MaskPixelT>::_initializePlanes(MaskPlaneDict const& planeDefs) {
62  LOGL_DEBUG("afw.image.Mask", "Number of mask planes: %d", getNumPlanesMax());
63 
64  _maskDict = detail::MaskDict::copyOrGetDefault(planeDefs);
65 }
66 
67 template <typename MaskPixelT>
68 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPlaneDict const& planeDefs)
69  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
70  _initializePlanes(planeDefs);
71  *this = 0x0;
72 }
73 
74 template <typename MaskPixelT>
75 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPixelT initialValue,
76  MaskPlaneDict const& planeDefs)
77  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
78  _initializePlanes(planeDefs);
79  *this = initialValue;
80 }
81 
82 template <typename MaskPixelT>
84  : ImageBase<MaskPixelT>(dimensions) {
85  _initializePlanes(planeDefs);
86  *this = 0x0;
87 }
88 
89 template <typename MaskPixelT>
90 Mask<MaskPixelT>::Mask(lsst::geom::Extent2I const& dimensions, MaskPixelT initialValue,
91  MaskPlaneDict const& planeDefs)
92  : ImageBase<MaskPixelT>(dimensions) {
93  _initializePlanes(planeDefs);
94  *this = initialValue;
95 }
96 
97 template <typename MaskPixelT>
99  : ImageBase<MaskPixelT>(bbox) {
100  _initializePlanes(planeDefs);
101  *this = 0x0;
102 }
103 
104 template <typename MaskPixelT>
105 Mask<MaskPixelT>::Mask(lsst::geom::Box2I const& bbox, MaskPixelT initialValue, MaskPlaneDict const& planeDefs)
106  : ImageBase<MaskPixelT>(bbox) {
107  _initializePlanes(planeDefs);
108  *this = initialValue;
109 }
110 
111 template <typename MaskPixelT>
113  bool const deep)
114  : ImageBase<MaskPixelT>(rhs, bbox, origin, deep), _maskDict(rhs._maskDict) {}
115 
116 template <typename MaskPixelT>
117 Mask<MaskPixelT>::Mask(Mask const& rhs, bool deep)
118  : ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {}
119 // Delegate to copy-constructor for backwards compatibility
120 template <typename MaskPixelT>
121 Mask<MaskPixelT>::Mask(Mask&& rhs) : Mask(rhs, false) {}
122 
123 template <typename MaskPixelT>
124 Mask<MaskPixelT>::~Mask() = default;
125 
126 template <typename MaskPixelT>
127 Mask<MaskPixelT>::Mask(ndarray::Array<MaskPixelT, 2, 1> const& array, bool deep,
128  lsst::geom::Point2I const& xy0)
129  : image::ImageBase<MaskPixelT>(array, deep, xy0), _maskDict(detail::MaskDict::getDefault()) {}
130 
131 template <typename PixelT>
133  using std::swap; // See Meyers, Effective C++, Item 25
134 
136  swap(_maskDict, rhs._maskDict);
137 }
138 
139 template <typename PixelT>
141  a.swap(b);
142 }
143 
144 template <typename MaskPixelT>
146  Mask tmp(rhs);
147  swap(tmp); // See Meyers, Effective C++, Item 11
148 
149  return *this;
150 }
151 // Delegate to copy-assignment for backwards compatibility
152 template <typename MaskPixelT>
154  return *this = rhs;
155 }
156 
157 template <typename MaskPixelT>
159  fill_pixels(_getRawView(), rhs);
160 
161  return *this;
162 }
163 
164 #ifndef DOXYGEN // doc for this section is already in header
165 
166 template <typename MaskPixelT>
168  lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool allowUnsafe)
169  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
170  MaskFitsReader reader(fileName, hdu);
171  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
172  if (metadata) {
173  metadata->combine(reader.readMetadata());
174  }
175 }
176 
177 template <typename MaskPixelT>
178 Mask<MaskPixelT>::Mask(fits::MemFileManager& manager, int hdu,
180  ImageOrigin origin, bool conformMasks, bool allowUnsafe)
181  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
182  MaskFitsReader reader(manager, hdu);
183  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
184  if (metadata) {
185  metadata->combine(reader.readMetadata());
186  }
187 }
188 
189 template <typename MaskPixelT>
191  lsst::geom::Box2I const& bbox, ImageOrigin const origin, bool const conformMasks,
192  bool allowUnsafe)
193  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
194  MaskFitsReader reader(&fitsFile);
195  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
196  if (metadata) {
197  metadata->combine(reader.readMetadata());
198  }
199 }
200 
201 template <typename MaskPixelT>
202 void Mask<MaskPixelT>::writeFits(std::string const& fileName,
204  std::string const& mode) const {
205  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
206  writeFits(fitsfile, metadata_i);
207 }
208 
209 template <typename MaskPixelT>
210 void Mask<MaskPixelT>::writeFits(fits::MemFileManager& manager,
212  std::string const& mode) const {
213  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
214  writeFits(fitsfile, metadata_i);
215 }
216 
217 template <typename MaskPixelT>
218 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile,
220  writeFits(fitsfile, fits::ImageWriteOptions(*this), metadata);
221 }
222 
223 template <typename MaskPixelT>
224 void Mask<MaskPixelT>::writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
225  std::string const& mode,
227  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
228  writeFits(fitsfile, options, header);
229 }
230 
231 template <typename MaskPixelT>
232 void Mask<MaskPixelT>::writeFits(fits::MemFileManager& manager, fits::ImageWriteOptions const& options,
233  std::string const& mode,
235  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
236  writeFits(fitsfile, options, header);
237 }
238 
239 template <typename MaskPixelT>
240 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
243  header ? header->deepCopy() : std::make_shared<dafBase::PropertySet>();
244  addMaskPlanesToMetadata(useHeader);
245  fitsfile.writeImage(*this, options, useHeader);
246 }
247 
248 #endif // !DOXYGEN
249 
250 template <typename MaskPixelT>
252  std::string result = "";
253  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
254  for (MaskPlaneDict::const_iterator iter = mpd.begin(); iter != mpd.end(); ++iter) {
255  if (value & getBitMask(iter->second)) {
256  if (result.size() > 0) {
257  result += ",";
258  }
259  result += iter->first;
260  }
261  }
262  return result;
263 }
264 
265 template <typename MaskPixelT>
267  int id = getMaskPlaneNoThrow(name); // see if the plane is already available
268 
269  if (id < 0) { // doesn't exist
270  id = _maskPlaneDict()->getUnusedPlane();
271  }
272 
273  // build new entry, adding the plane to all Masks where this is no contradiction
274 
275  if (id >= getNumPlanesMax()) { // Max number of planes is already allocated
277  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
278  }
279 
281 
282  return id;
283 }
284 
285 template <typename MaskPixelT>
287  if (planeId < 0 || planeId >= getNumPlanesMax()) {
288  throw LSST_EXCEPT(
290  str(boost::format("mask plane ID must be between 0 and %1%") % (getNumPlanesMax() - 1)));
291  }
292 
293  _maskPlaneDict()->add(name, planeId);
294 
295  return planeId;
296 }
297 
298 template <typename MaskPixelT>
300  return _maskDict->getMaskPlaneDict();
301 }
302 
303 template <typename MaskPixelT>
305  if (detail::MaskDict::getDefault()->getMaskPlane(name) < 0) {
307  str(boost::format("Plane %s doesn't exist in the default Mask") % name));
308  }
309 
310  detail::MaskDict::detachDefault(); // leave current Masks alone
311  _maskPlaneDict()->erase(name);
312 }
313 
314 template <typename MaskPixelT>
315 void Mask<MaskPixelT>::removeAndClearMaskPlane(const std::string& name, bool const removeFromDefault
316 
317 ) {
318  clearMaskPlane(getMaskPlane(name)); // clear this bits in this Mask
319 
320  if (_maskDict == detail::MaskDict::getDefault() && removeFromDefault) { // we are the default
321  ;
322  } else {
323  _maskDict = _maskDict->clone();
324  }
325 
326  _maskDict->erase(name);
327 
328  if (removeFromDefault && detail::MaskDict::getDefault()->getMaskPlane(name) >= 0) {
329  removeMaskPlane(name);
330  }
331 }
332 
333 template <typename MaskPixelT>
334 MaskPixelT Mask<MaskPixelT>::getBitMaskNoThrow(int planeId) {
335  return (planeId >= 0 && planeId < getNumPlanesMax()) ? (1 << planeId) : 0;
336 }
337 
338 template <typename MaskPixelT>
339 MaskPixelT Mask<MaskPixelT>::getBitMask(int planeId) {
340  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
341 
342  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
343  if (planeId == i->second) {
344  MaskPixelT const bitmask = getBitMaskNoThrow(planeId);
345  if (bitmask == 0) { // failed
346  break;
347  }
348  return bitmask;
349  }
350  }
352  str(boost::format("Invalid mask plane ID: %d") % planeId));
353 }
354 
355 template <typename MaskPixelT>
357  int const plane = getMaskPlaneNoThrow(name);
358 
359  if (plane < 0) {
361  str(boost::format("Invalid mask plane name: %s") % name));
362  } else {
363  return plane;
364  }
365 }
366 
367 template <typename MaskPixelT>
369  return _maskPlaneDict()->getMaskPlane(name);
370 }
371 
372 template <typename MaskPixelT>
374  return getBitMask(getMaskPlane(name));
375 }
376 
377 template <typename MaskPixelT>
379  MaskPixelT mpix = 0x0;
380  for (std::vector<std::string>::const_iterator it = name.begin(); it != name.end(); ++it) {
381  mpix |= getBitMask(getMaskPlane(*it));
382  }
383  return mpix;
384 }
385 
386 template <typename MaskPixelT>
388  return _maskPlaneDict()->size();
389 }
390 
391 template <typename MaskPixelT>
393  _maskPlaneDict()->clear();
394 }
395 
396 template <typename MaskPixelT>
398  *this = 0;
399 }
400 
401 template <typename MaskPixelT>
403  *this &= ~getBitMask(planeId);
404 }
405 
406 template <typename MaskPixelT>
407 void Mask<MaskPixelT>::conformMaskPlanes(MaskPlaneDict const& currentPlaneDict) {
409 
410  if (*_maskDict == *currentMD) {
411  if (*detail::MaskDict::getDefault() == *_maskDict) {
412  return; // nothing to do
413  }
414  } else {
415  //
416  // Find out which planes need to be permuted
417  //
418  MaskPixelT keepBitmask = 0; // mask of bits to keep
419  MaskPixelT canonicalMask[sizeof(MaskPixelT) * 8]; // bits in lsst::afw::image::Mask that should be
420  MaskPixelT currentMask[sizeof(MaskPixelT) * 8]; // mapped to these bits
421  int numReMap = 0;
422 
423  for (MaskPlaneDict::const_iterator i = currentPlaneDict.begin(); i != currentPlaneDict.end(); i++) {
424  std::string const name = i->first; // name of mask plane
425  int const currentPlaneNumber = i->second; // plane number currently in use
426  int canonicalPlaneNumber = getMaskPlaneNoThrow(name); // plane number in lsst::afw::image::Mask
427 
428  if (canonicalPlaneNumber < 0) { // no such plane; add it
429  canonicalPlaneNumber = addMaskPlane(name);
430  }
431 
432  if (canonicalPlaneNumber == currentPlaneNumber) {
433  keepBitmask |= getBitMask(canonicalPlaneNumber); // bit is unchanged, so preserve it
434  } else {
435  canonicalMask[numReMap] = getBitMask(canonicalPlaneNumber);
436  currentMask[numReMap] = getBitMaskNoThrow(currentPlaneNumber);
437  numReMap++;
438  }
439  }
440 
441  // Now loop over all pixels in Mask
442  if (numReMap > 0) {
443  for (int r = 0; r != this->getHeight(); ++r) { // "this->": Meyers, Effective C++, Item 43
444  for (typename Mask::x_iterator ptr = this->row_begin(r), end = this->row_end(r); ptr != end;
445  ++ptr) {
446  MaskPixelT const pixel = *ptr;
447 
448  MaskPixelT newPixel = pixel & keepBitmask; // value of invariant mask bits
449  for (int i = 0; i < numReMap; i++) {
450  if (pixel & currentMask[i]) newPixel |= canonicalMask[i];
451  }
452 
453  *ptr = newPixel;
454  }
455  }
456  }
457  }
458  // We've made the planes match the current mask dictionary
459  _maskDict = detail::MaskDict::getDefault();
460 }
461 
462 template <typename MaskPixelT>
464  return this->ImageBase<MaskPixelT>::operator()(x, y);
465 }
466 
467 template <typename MaskPixelT>
469  CheckIndices const& check) {
470  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
471 }
472 
473 template <typename MaskPixelT>
475  return this->ImageBase<MaskPixelT>::operator()(x, y);
476 }
477 
478 template <typename MaskPixelT>
480  int x, int y, CheckIndices const& check) const {
481  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
482 }
483 
484 template <typename MaskPixelT>
485 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId) const {
486  // !! converts an int to a bool
487  return !!(this->ImageBase<MaskPixelT>::operator()(x, y) & getBitMask(planeId));
488 }
489 
490 template <typename MaskPixelT>
491 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId, CheckIndices const& check) const {
492  // !! converts an int to a bool
493  return !!(this->ImageBase<MaskPixelT>::operator()(x, y, check) & getBitMask(planeId));
494 }
495 
496 template <typename MaskPixelT>
498  if (*_maskDict != *other._maskDict) {
499  throw LSST_EXCEPT(pexExcept::RuntimeError, "Mask dictionaries do not match");
500  }
501 }
502 
503 template <typename MaskPixelT>
505  transform_pixels(_getRawView(), _getRawView(),
506  [&val](MaskPixelT const& l) -> MaskPixelT { return l | val; });
507  return *this;
508 }
509 
510 template <typename MaskPixelT>
512  checkMaskDictionaries(rhs);
513 
514  if (this->getDimensions() != rhs.getDimensions()) {
516  str(boost::format("Images are of different size, %dx%d v %dx%d") %
517  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
518  }
519  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
520  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l | r; });
521  return *this;
522 }
523 
524 template <typename MaskPixelT>
526  transform_pixels(_getRawView(), _getRawView(), [&val](MaskPixelT const& l) { return l & val; });
527  return *this;
528 }
529 
530 template <typename MaskPixelT>
532  checkMaskDictionaries(rhs);
533 
534  if (this->getDimensions() != rhs.getDimensions()) {
536  str(boost::format("Images are of different size, %dx%d v %dx%d") %
537  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
538  }
539  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
540  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l & r; });
541  return *this;
542 }
543 
544 template <typename MaskPixelT>
546  transform_pixels(_getRawView(), _getRawView(),
547  [&val](MaskPixelT const& l) -> MaskPixelT { return l ^ val; });
548  return *this;
549 }
550 
551 template <typename MaskPixelT>
553  checkMaskDictionaries(rhs);
554 
555  if (this->getDimensions() != rhs.getDimensions()) {
557  str(boost::format("Images are of different size, %dx%d v %dx%d") %
558  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
559  }
560  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
561  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l ^ r; });
562  return *this;
563 }
564 
565 template <typename MaskPixelT>
566 void Mask<MaskPixelT>::setMaskPlaneValues(int const planeId, int const x0, int const x1, int const y) {
567  MaskPixelT const bitMask = getBitMask(planeId);
568 
569  for (int x = x0; x <= x1; x++) {
570  operator()(x, y) = operator()(x, y) | bitMask;
571  }
572 }
573 
574 template <typename MaskPixelT>
576  if (!metadata) {
577  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "Null std::shared_ptr<PropertySet>");
578  }
579 
580  // First, clear existing MaskPlane metadata
581  typedef std::vector<std::string> NameList;
582  NameList paramNames = metadata->paramNames(false);
583  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
584  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
585  metadata->remove(*i);
586  }
587  }
588 
589  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
590 
591  // Add new MaskPlane metadata
592  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
593  std::string const& planeName = i->first;
594  int const planeNumber = i->second;
595 
596  if (planeName != "") {
597  metadata->add(maskPlanePrefix + planeName, planeNumber);
598  }
599  }
600 }
601 
602 template <typename MaskPixelT>
605  MaskPlaneDict newDict;
606 
607  // First, clear existing MaskPlane metadata
608  typedef std::vector<std::string> NameList;
609  NameList paramNames = metadata->paramNames(false);
610  int numPlanesUsed = 0; // number of planes used
611 
612  // Iterate over childless properties with names starting with maskPlanePrefix
613  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
614  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
615  // split off maskPlanePrefix to obtain plane name
616  std::string planeName = i->substr(maskPlanePrefix.size());
617  int const planeId = metadata->getAsInt(*i);
618 
619  MaskPlaneDict::const_iterator plane = newDict.find(planeName);
620  if (plane != newDict.end() && planeId != plane->second) {
621  throw LSST_EXCEPT(pexExcept::RuntimeError, "File specifies plane " + planeName + " twice");
622  }
623  for (MaskPlaneDict::const_iterator j = newDict.begin(); j != newDict.end(); ++j) {
624  if (planeId == j->second) {
626  str(boost::format("File specifies plane %s has same value (%d) as %s") %
627  planeName % planeId % j->first));
628  }
629  }
630  // build new entry
631  if (numPlanesUsed >= getNumPlanesMax()) {
632  // Max number of planes already allocated
633  throw LSST_EXCEPT(
635  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
636  }
637  newDict[planeName] = planeId;
638  }
639  }
640  return newDict;
641 }
642 
643 template <typename MaskPixelT>
645  _maskDict->print();
646 }
647 
648 /*
649  * Static members of Mask
650  */
651 template <typename MaskPixelT>
653 
654 template <typename MaskPixelT>
657 }
658 
659 //
660 // Explicit instantiations
661 //
662 template class Mask<MaskPixel>;
663 } // namespace image
664 } // namespace afw
665 } // namespace lsst
table::Key< std::string > name
Definition: Amplifier.cc:116
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
int end
double x
table::PointKey< int > pixel
table::Key< int > id
Definition: Detector.cc:162
#define LSST_EXCEPT(type,...)
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
#define LOGL_DEBUG(logger, message...)
int y
Definition: SpanSet.cc:49
table::Key< int > b
table::Key< int > a
T begin(T... args)
A class used to request that array accesses be checked.
Definition: ImageBase.h:74
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:102
Reference< PixelT >::type PixelReference
A Reference to a PixelT.
Definition: ImageBase.h:117
PixelReference operator()(int x, int y)
Return a reference to the pixel (x, y) in LOCAL coordinates.
Definition: Image.cc:183
int getWidth() const
Return the number of columns in the image.
Definition: ImageBase.h:294
lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Definition: ImageBase.h:356
int getHeight() const
Return the number of rows in the image.
Definition: ImageBase.h:296
ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
Definition: ImageBase.h:119
_view_t _getRawView() const
Definition: ImageBase.h:465
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:133
void swap(ImageBase &rhs)
Definition: Image.cc:245
A FITS reader class for Masks.
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet >(), std::string const &mode="w") const
Write a mask to a regular FITS file.
void swap(Mask &rhs)
Definition: Mask.cc:132
Mask & operator=(MaskPixelT const rhs)
Definition: Mask.cc:158
friend class MaskFitsReader
Definition: Mask.h:521
void printMaskPlanes() const
print the mask plane dictionary to std::cout
Definition: Mask.cc:644
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:356
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:251
static void removeMaskPlane(const std::string &name)
Definition: Mask.cc:304
void removeAndClearMaskPlane(const std::string &name, bool const removeFromDefault=false)
Clear all pixels of the specified mask and remove the plane from the mask plane dictionary; optionall...
Definition: Mask.cc:315
static void clearMaskPlaneDict()
Reset the maskPlane dictionary.
Definition: Mask.cc:392
void setMaskPlaneValues(const int plane, const int x0, const int x1, const int y)
Set the bit specified by "planeId" for pixels (x0, y) ...
Definition: Mask.cc:566
static void addMaskPlanesToMetadata(std::shared_ptr< lsst::daf::base::PropertySet >)
Given a PropertySet, replace any existing MaskPlane assignments with the current ones.
Definition: Mask.cc:575
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition: Mask.cc:463
Mask & operator^=(Mask const &rhs)
XOR a Mask into a Mask.
Definition: Mask.cc:552
static int addMaskPlane(const std::string &name)
Definition: Mask.cc:266
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR'd together.
Definition: Mask.cc:378
Mask(unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition: Mask.cc:68
MaskPlaneDict const & getMaskPlaneDict() const
Return the Mask's maskPlaneDict.
Definition: Mask.cc:299
void conformMaskPlanes(const MaskPlaneDict &masterPlaneDict)
Adjust this mask to conform to the standard Mask class's mask plane dictionary, adding any new mask p...
Definition: Mask.cc:407
Mask & operator|=(Mask const &rhs)
OR a Mask into a Mask.
Definition: Mask.cc:511
static MaskPlaneDict parseMaskPlaneMetadata(std::shared_ptr< lsst::daf::base::PropertySet const > metadata)
Given a PropertySet that contains the MaskPlane assignments, setup the MaskPlanes.
Definition: Mask.cc:603
void clearAllMaskPlanes()
Clear all the pixels.
Definition: Mask.cc:397
static int getNumPlanesUsed()
Definition: Mask.cc:387
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition: Mask.cc:402
Mask & operator&=(Mask const &rhs)
AND a Mask into a Mask.
Definition: Mask.cc:531
static void addAllMasksPlane(std::string const &name, int bitId)
Definition: MaskDict.cc:127
static std::shared_ptr< MaskDict > detachDefault()
Definition: MaskDict.cc:123
static std::shared_ptr< MaskDict > getDefault()
Definition: MaskDict.cc:115
static std::shared_ptr< MaskDict > copyOrGetDefault(MaskPlaneDict const &dict)
Definition: MaskDict.cc:111
T end(T... args)
T find(T... args)
def iter(self)
std::map< std::string, int > MaskPlaneDict
Definition: Mask.h:58
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:455
A base class for image defects.
T size(T... args)
T substr(T... args)
T swap(T... args)