lsst.afw  16.0-43-gaa65a4573+2
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 #include "boost/filesystem/path.hpp"
40 
41 #include "boost/functional/hash.hpp"
42 
43 #include "lsst/daf/base.h"
44 #include "lsst/daf/base/Citizen.h"
45 #include "lsst/geom.h"
46 #include "lsst/pex/exceptions.h"
47 #include "lsst/log/Log.h"
48 #include "lsst/afw/image/Mask.h"
51 
52 //
53 // for FITS code
54 //
55 #include "boost/mpl/vector.hpp"
56 #include "boost/gil/gil_all.hpp"
59 
60 namespace dafBase = lsst::daf::base;
62 
63 namespace lsst {
64 namespace afw {
65 namespace image {
66 
67 namespace {
68 
69 } // namespace
70 
71 template <typename MaskPixelT>
72 void Mask<MaskPixelT>::_initializePlanes(MaskPlaneDict const& planeDefs) {
73  LOGL_DEBUG("afw.image.Mask", "Number of mask planes: %d", getNumPlanesMax());
74 
75  _maskDict = detail::MaskDict::copyOrGetDefault(planeDefs);
76 }
77 
78 template <typename MaskPixelT>
79 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPlaneDict const& planeDefs)
80  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
81  _initializePlanes(planeDefs);
82  *this = 0x0;
83 }
84 
85 template <typename MaskPixelT>
86 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPixelT initialValue,
87  MaskPlaneDict const& planeDefs)
88  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
89  _initializePlanes(planeDefs);
90  *this = initialValue;
91 }
92 
93 template <typename MaskPixelT>
95  : ImageBase<MaskPixelT>(dimensions) {
96  _initializePlanes(planeDefs);
97  *this = 0x0;
98 }
99 
100 template <typename MaskPixelT>
102  MaskPlaneDict const& planeDefs)
103  : ImageBase<MaskPixelT>(dimensions) {
104  _initializePlanes(planeDefs);
105  *this = initialValue;
106 }
107 
108 template <typename MaskPixelT>
110  : ImageBase<MaskPixelT>(bbox) {
111  _initializePlanes(planeDefs);
112  *this = 0x0;
113 }
114 
115 template <typename MaskPixelT>
116 Mask<MaskPixelT>::Mask(lsst::geom::Box2I const& bbox, MaskPixelT initialValue, MaskPlaneDict const& planeDefs)
117  : ImageBase<MaskPixelT>(bbox) {
118  _initializePlanes(planeDefs);
119  *this = initialValue;
120 }
121 
122 template <typename MaskPixelT>
124  bool const deep)
125  : ImageBase<MaskPixelT>(rhs, bbox, origin, deep), _maskDict(rhs._maskDict) {}
126 
127 template <typename MaskPixelT>
128 Mask<MaskPixelT>::Mask(Mask const& rhs, bool deep)
129  : ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {}
130 // Delegate to copy-constructor for backwards compatibility
131 template <typename MaskPixelT>
132 Mask<MaskPixelT>::Mask(Mask&& rhs) : Mask(rhs, false) {}
133 
134 template <typename MaskPixelT>
135 Mask<MaskPixelT>::~Mask() = default;
136 
137 template <typename MaskPixelT>
138 Mask<MaskPixelT>::Mask(ndarray::Array<MaskPixelT, 2, 1> const& array, bool deep,
139  lsst::geom::Point2I const& xy0)
140  : image::ImageBase<MaskPixelT>(array, deep, xy0), _maskDict(detail::MaskDict::getDefault()) {}
141 
142 template <typename PixelT>
144  using std::swap; // See Meyers, Effective C++, Item 25
145 
147  swap(_maskDict, rhs._maskDict);
148 }
149 
150 template <typename PixelT>
152  a.swap(b);
153 }
154 
155 template <typename MaskPixelT>
157  Mask tmp(rhs);
158  swap(tmp); // See Meyers, Effective C++, Item 11
159 
160  return *this;
161 }
162 // Delegate to copy-assignment for backwards compatibility
163 template <typename MaskPixelT>
165  return *this = rhs;
166 }
167 
168 template <typename MaskPixelT>
170  fill_pixels(_getRawView(), rhs);
171 
172  return *this;
173 }
174 
175 #ifndef DOXYGEN // doc for this section is already in header
176 
177 template <typename MaskPixelT>
179  lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks)
181  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
182  fitsfile.setHdu(hdu);
183  *this = Mask(fitsfile, metadata, bbox, origin, conformMasks);
184 }
185 
186 template <typename MaskPixelT>
189  ImageOrigin origin, bool conformMasks)
191  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
192  fitsfile.setHdu(hdu);
193  *this = Mask(fitsfile, metadata, bbox, origin, conformMasks);
194 }
195 
196 template <typename MaskPixelT>
198  lsst::geom::Box2I const& bbox, ImageOrigin const origin, bool const conformMasks)
200  // These are the permitted input file types
201  typedef boost::mpl::vector<unsigned char, unsigned short, short, std::int32_t> fits_mask_types;
202 
203  if (!metadata) {
205  }
206 
207  fits_read_image<fits_mask_types>(fitsfile, *this, *metadata, bbox, origin);
208 
209  // look for mask planes in the file
210  MaskPlaneDict fileMaskDict = parseMaskPlaneMetadata(metadata);
212 
213  if (*fileMD == *detail::MaskDict::getDefault()) { // file is already consistent with Mask
214  return;
215  }
216 
217  if (conformMasks) { // adopt the definitions in the file
219  _maskDict = fileMD;
220  }
221 
222  conformMaskPlanes(fileMaskDict); // convert planes defined by fileMaskDict to the order
223  // defined by Mask::_maskPlaneDict
224 }
225 
226 template <typename MaskPixelT>
227 void Mask<MaskPixelT>::writeFits(std::string const& fileName,
229  std::string const& mode) const {
230  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
231  writeFits(fitsfile, metadata_i);
232 }
233 
234 template <typename MaskPixelT>
237  std::string const& mode) const {
238  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
239  writeFits(fitsfile, metadata_i);
240 }
241 
242 template <typename MaskPixelT>
245  writeFits(fitsfile, fits::ImageWriteOptions(*this), metadata);
246 }
247 
248 template <typename MaskPixelT>
250  std::string const& mode,
252  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
253  writeFits(fitsfile, options, header);
254 }
255 
256 template <typename MaskPixelT>
258  std::string const& mode,
260  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
261  writeFits(fitsfile, options, header);
262 }
263 
264 template <typename MaskPixelT>
265 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
268  header ? header->deepCopy() : std::make_shared<dafBase::PropertySet>();
269  addMaskPlanesToMetadata(useHeader);
270  fitsfile.writeImage(*this, options, useHeader);
271 }
272 
273 #endif // !DOXYGEN
274 
275 
276 template <typename MaskPixelT>
278  std::string result = "";
279  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
280  for (MaskPlaneDict::const_iterator iter = mpd.begin(); iter != mpd.end(); ++iter) {
281  if (value & getBitMask(iter->second)) {
282  if (result.size() > 0) {
283  result += ",";
284  }
285  result += iter->first;
286  }
287  }
288  return result;
289 }
290 
291 template <typename MaskPixelT>
293  int id = getMaskPlaneNoThrow(name); // see if the plane is already available
294 
295  if (id < 0) { // doesn't exist
296  id = _maskPlaneDict()->getUnusedPlane();
297  }
298 
299  // build new entry, adding the plane to all Masks where this is no contradiction
300 
301  if (id >= getNumPlanesMax()) { // Max number of planes is already allocated
303  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
304  }
305 
307 
308  return id;
309 }
310 
311 template <typename MaskPixelT>
313  if (planeId < 0 || planeId >= getNumPlanesMax()) {
314  throw LSST_EXCEPT(
316  str(boost::format("mask plane ID must be between 0 and %1%") % (getNumPlanesMax() - 1)));
317  }
318 
319  _maskPlaneDict()->add(name, planeId);
320 
321  return planeId;
322 }
323 
324 template <typename MaskPixelT>
326  return _maskDict->getMaskPlaneDict();
327 }
328 
329 template <typename MaskPixelT>
331  if (detail::MaskDict::getDefault()->getMaskPlane(name) < 0) {
333  str(boost::format("Plane %s doesn't exist in the default Mask") % name));
334  }
335 
336  detail::MaskDict::detachDefault(); // leave current Masks alone
337  _maskPlaneDict()->erase(name);
338 }
339 
340 template <typename MaskPixelT>
341 void Mask<MaskPixelT>::removeAndClearMaskPlane(const std::string& name, bool const removeFromDefault
342 
343 ) {
344  clearMaskPlane(getMaskPlane(name)); // clear this bits in this Mask
345 
346  if (_maskDict == detail::MaskDict::getDefault() && removeFromDefault) { // we are the default
347  ;
348  } else {
349  _maskDict = _maskDict->clone();
350  }
351 
352  _maskDict->erase(name);
353 
354  if (removeFromDefault && detail::MaskDict::getDefault()->getMaskPlane(name) >= 0) {
355  removeMaskPlane(name);
356  }
357 }
358 
359 template <typename MaskPixelT>
360 MaskPixelT Mask<MaskPixelT>::getBitMaskNoThrow(int planeId) {
361  return (planeId >= 0 && planeId < getNumPlanesMax()) ? (1 << planeId) : 0;
362 }
363 
364 template <typename MaskPixelT>
365 MaskPixelT Mask<MaskPixelT>::getBitMask(int planeId) {
366  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
367 
368  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
369  if (planeId == i->second) {
370  MaskPixelT const bitmask = getBitMaskNoThrow(planeId);
371  if (bitmask == 0) { // failed
372  break;
373  }
374  return bitmask;
375  }
376  }
378  str(boost::format("Invalid mask plane ID: %d") % planeId));
379 }
380 
381 template <typename MaskPixelT>
383  int const plane = getMaskPlaneNoThrow(name);
384 
385  if (plane < 0) {
387  str(boost::format("Invalid mask plane name: %s") % name));
388  } else {
389  return plane;
390  }
391 }
392 
393 template <typename MaskPixelT>
395  return _maskPlaneDict()->getMaskPlane(name);
396 }
397 
398 template <typename MaskPixelT>
400  return getBitMask(getMaskPlane(name));
401 }
402 
403 template <typename MaskPixelT>
405  MaskPixelT mpix = 0x0;
406  for (std::vector<std::string>::const_iterator it = name.begin(); it != name.end(); ++it) {
407  mpix |= getBitMask(getMaskPlane(*it));
408  }
409  return mpix;
410 }
411 
412 template <typename MaskPixelT>
414  return _maskPlaneDict()->size();
415 }
416 
417 template <typename MaskPixelT>
419  _maskPlaneDict()->clear();
420 }
421 
422 template <typename MaskPixelT>
424  *this = 0;
425 }
426 
427 template <typename MaskPixelT>
429  *this &= ~getBitMask(planeId);
430 }
431 
432 template <typename MaskPixelT>
433 void Mask<MaskPixelT>::conformMaskPlanes(MaskPlaneDict const& currentPlaneDict) {
435 
436  if (*_maskDict == *currentMD) {
437  if (*detail::MaskDict::getDefault() == *_maskDict) {
438  return; // nothing to do
439  }
440  } else {
441  //
442  // Find out which planes need to be permuted
443  //
444  MaskPixelT keepBitmask = 0; // mask of bits to keep
445  MaskPixelT canonicalMask[sizeof(MaskPixelT) * 8]; // bits in lsst::afw::image::Mask that should be
446  MaskPixelT currentMask[sizeof(MaskPixelT) * 8]; // mapped to these bits
447  int numReMap = 0;
448 
449  for (MaskPlaneDict::const_iterator i = currentPlaneDict.begin(); i != currentPlaneDict.end(); i++) {
450  std::string const name = i->first; // name of mask plane
451  int const currentPlaneNumber = i->second; // plane number currently in use
452  int canonicalPlaneNumber = getMaskPlaneNoThrow(name); // plane number in lsst::afw::image::Mask
453 
454  if (canonicalPlaneNumber < 0) { // no such plane; add it
455  canonicalPlaneNumber = addMaskPlane(name);
456  }
457 
458  if (canonicalPlaneNumber == currentPlaneNumber) {
459  keepBitmask |= getBitMask(canonicalPlaneNumber); // bit is unchanged, so preserve it
460  } else {
461  canonicalMask[numReMap] = getBitMask(canonicalPlaneNumber);
462  currentMask[numReMap] = getBitMaskNoThrow(currentPlaneNumber);
463  numReMap++;
464  }
465  }
466 
467  // Now loop over all pixels in Mask
468  if (numReMap > 0) {
469  for (int r = 0; r != this->getHeight(); ++r) { // "this->": Meyers, Effective C++, Item 43
470  for (typename Mask::x_iterator ptr = this->row_begin(r), end = this->row_end(r); ptr != end;
471  ++ptr) {
472  MaskPixelT const pixel = *ptr;
473 
474  MaskPixelT newPixel = pixel & keepBitmask; // value of invariant mask bits
475  for (int i = 0; i < numReMap; i++) {
476  if (pixel & currentMask[i]) newPixel |= canonicalMask[i];
477  }
478 
479  *ptr = newPixel;
480  }
481  }
482  }
483  }
484  // We've made the planes match the current mask dictionary
485  _maskDict = detail::MaskDict::getDefault();
486 }
487 
488 template <typename MaskPixelT>
490  return this->ImageBase<MaskPixelT>::operator()(x, y);
491 }
492 
493 template <typename MaskPixelT>
495  CheckIndices const& check) {
496  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
497 }
498 
499 template <typename MaskPixelT>
501  return this->ImageBase<MaskPixelT>::operator()(x, y);
502 }
503 
504 template <typename MaskPixelT>
506  int x, int y, CheckIndices const& check) const {
507  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
508 }
509 
510 template <typename MaskPixelT>
511 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId) const {
512  // !! converts an int to a bool
513  return !!(this->ImageBase<MaskPixelT>::operator()(x, y) & getBitMask(planeId));
514 }
515 
516 template <typename MaskPixelT>
517 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId, CheckIndices const& check) const {
518  // !! converts an int to a bool
519  return !!(this->ImageBase<MaskPixelT>::operator()(x, y, check) & getBitMask(planeId));
520 }
521 
522 template <typename MaskPixelT>
524  if (*_maskDict != *other._maskDict) {
525  throw LSST_EXCEPT(pexExcept::RuntimeError, "Mask dictionaries do not match");
526  }
527 }
528 
529 template <typename MaskPixelT>
531  transform_pixels(_getRawView(), _getRawView(),
532  [&val](MaskPixelT const& l) -> MaskPixelT { return l | val; });
533  return *this;
534 }
535 
536 template <typename MaskPixelT>
538  checkMaskDictionaries(rhs);
539 
540  if (this->getDimensions() != rhs.getDimensions()) {
542  str(boost::format("Images are of different size, %dx%d v %dx%d") %
543  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
544  }
545  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
546  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l | r; });
547  return *this;
548 }
549 
550 template <typename MaskPixelT>
551 Mask<MaskPixelT>& Mask<MaskPixelT>::operator&=(MaskPixelT const val) {
552  transform_pixels(_getRawView(), _getRawView(), [&val](MaskPixelT const& l) { return l & val; });
553  return *this;
554 }
555 
556 template <typename MaskPixelT>
558  checkMaskDictionaries(rhs);
559 
560  if (this->getDimensions() != rhs.getDimensions()) {
562  str(boost::format("Images are of different size, %dx%d v %dx%d") %
563  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
564  }
565  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
566  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l & r; });
567  return *this;
568 }
569 
570 template <typename MaskPixelT>
572  transform_pixels(_getRawView(), _getRawView(),
573  [&val](MaskPixelT const& l) -> MaskPixelT { return l ^ val; });
574  return *this;
575 }
576 
577 template <typename MaskPixelT>
579  checkMaskDictionaries(rhs);
580 
581  if (this->getDimensions() != rhs.getDimensions()) {
583  str(boost::format("Images are of different size, %dx%d v %dx%d") %
584  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
585  }
586  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
587  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l ^ r; });
588  return *this;
589 }
590 
591 template <typename MaskPixelT>
592 void Mask<MaskPixelT>::setMaskPlaneValues(int const planeId, int const x0, int const x1, int const y) {
593  MaskPixelT const bitMask = getBitMask(planeId);
594 
595  for (int x = x0; x <= x1; x++) {
596  operator()(x, y) = operator()(x, y) | bitMask;
597  }
598 }
599 
600 template <typename MaskPixelT>
602  if (!metadata) {
603  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "Null std::shared_ptr<PropertySet>");
604  }
605 
606  // First, clear existing MaskPlane metadata
607  typedef std::vector<std::string> NameList;
608  NameList paramNames = metadata->paramNames(false);
609  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
610  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
611  metadata->remove(*i);
612  }
613  }
614 
615  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
616 
617  // Add new MaskPlane metadata
618  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
619  std::string const& planeName = i->first;
620  int const planeNumber = i->second;
621 
622  if (planeName != "") {
623  metadata->add(maskPlanePrefix + planeName, planeNumber);
624  }
625  }
626 }
627 
628 template <typename MaskPixelT>
631  MaskPlaneDict newDict;
632 
633  // First, clear existing MaskPlane metadata
634  typedef std::vector<std::string> NameList;
635  NameList paramNames = metadata->paramNames(false);
636  int numPlanesUsed = 0; // number of planes used
637 
638  // Iterate over childless properties with names starting with maskPlanePrefix
639  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
640  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
641  // split off maskPlanePrefix to obtain plane name
642  std::string planeName = i->substr(maskPlanePrefix.size());
643  int const planeId = metadata->getAsInt(*i);
644 
645  MaskPlaneDict::const_iterator plane = newDict.find(planeName);
646  if (plane != newDict.end() && planeId != plane->second) {
647  throw LSST_EXCEPT(pexExcept::RuntimeError, "File specifies plane " + planeName + " twice");
648  }
649  for (MaskPlaneDict::const_iterator j = newDict.begin(); j != newDict.end(); ++j) {
650  if (planeId == j->second) {
652  str(boost::format("File specifies plane %s has same value (%d) as %s") %
653  planeName % planeId % j->first));
654  }
655  }
656  // build new entry
657  if (numPlanesUsed >= getNumPlanesMax()) {
658  // Max number of planes already allocated
659  throw LSST_EXCEPT(
661  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
662  }
663  newDict[planeName] = planeId;
664  }
665  }
666  return newDict;
667 }
668 
669 template <typename MaskPixelT>
671  _maskDict->print();
672 }
673 
674 /*
675  * Static members of Mask
676  */
677 template <typename MaskPixelT>
679 
680 template <typename MaskPixelT>
683 }
684 
685 //
686 // Explicit instantiations
687 //
688 template class Mask<MaskPixel>;
689 } // namespace image
690 } // namespace afw
691 } // namespace lsst
static std::shared_ptr< MaskDict > getDefault()
Definition: MaskDict.cc:115
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:277
static void clearMaskPlaneDict()
Reset the maskPlane dictionary.
Definition: Mask.cc:418
static void setDefault(std::shared_ptr< MaskDict > dict)
Definition: MaskDict.cc:119
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:382
T swap(T... args)
int getHeight() const
Return the number of rows in the image.
Definition: ImageBase.h:320
std::map< std::string, int > MaskPlaneDict
Definition: Mask.h:59
Options for writing an image to FITS.
Definition: fits.h:218
Mask & operator=(MaskPixelT const rhs)
Definition: Mask.cc:169
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:134
static std::shared_ptr< MaskDict > detachDefault()
Definition: MaskDict.cc:123
T end(T... args)
tuple options
ItemVariant const * other
Definition: Schema.cc:55
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:601
static int getNumPlanesUsed()
Definition: Mask.cc:413
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:296
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:103
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:341
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:629
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y&#39;th row.
Definition: ImageBase.h:423
#define LOGL_DEBUG(logger, message...)
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition: Mask.cc:489
static void addAllMasksPlane(std::string const &name, int bitId)
Definition: MaskDict.cc:127
iterator end() const
Return an STL compliant iterator to the end of the image.
Definition: Image.cc:275
STL class.
Mask(unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition: Mask.cc:79
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:78
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:120
table::Key< int > b
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:592
A class used to request that array accesses be checked.
Definition: ImageBase.h:75
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR&#39;d together.
Definition: Mask.cc:404
double x
void swap(ImageBase &rhs)
Definition: Image.cc:253
std::unique_ptr< SchemaItem< U > > result
Definition: Schema.cc:194
MaskPlaneDict const & getMaskPlaneDict() const
Return the Mask&#39;s maskPlaneDict.
Definition: Mask.cc:325
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Definition: fits.cc:478
T find(T... args)
T size(T... args)
#define LSST_EXCEPT(type,...)
static void removeMaskPlane(const std::string &name)
Definition: Mask.cc:330
static int getNumPlanesMax()
Definition: Mask.h:486
static std::shared_ptr< MaskDict > copyOrGetDefault(MaskPlaneDict const &dict)
Definition: MaskDict.cc:111
T begin(T... args)
Mask & operator &=(Mask const &rhs)
AND a Mask into a Mask.
int getWidth() const
Return the number of columns in the image.
Definition: ImageBase.h:318
Mask & operator|=(Mask const &rhs)
OR a Mask into a Mask.
Definition: Mask.cc:537
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: ImageBase.h:426
T substr(T... args)
table::Box2IKey bbox
table::Key< int > a
table::PointKey< int > pixel
void swap(Mask &rhs)
Definition: Mask.cc:143
void conformMaskPlanes(const MaskPlaneDict &masterPlaneDict)
Adjust this mask to conform to the standard Mask class&#39;s mask plane dictionary, adding any new mask p...
Definition: Mask.cc:433
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.
lsst::geom::Extent2I getDimensions() const
Return the image&#39;s size; useful for passing to constructors.
Definition: ImageBase.h:378
Mask & operator^=(Mask const &rhs)
XOR a Mask into a Mask.
Definition: Mask.cc:578
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition: Mask.cc:428
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
Definition: fits.h:476
void clearAllMaskPlanes()
Clear all the pixels.
Definition: Mask.cc:423
int y
Definition: SpanSet.cc:49
static int addMaskPlane(const std::string &name)
Definition: Mask.cc:292
PixelReference operator()(int x, int y)
Definition: Image.cc:190
void printMaskPlanes() const
print the mask plane dictionary to std::cout
Definition: Mask.cc:670