LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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/geom.h"
45 #include "lsst/pex/exceptions.h"
46 #include "lsst/log/Log.h"
47 #include "lsst/afw/image/Mask.h"
51 
52 namespace dafBase = lsst::daf::base;
54 
55 namespace lsst {
56 namespace afw {
57 namespace image {
58 
59 namespace {} // namespace
60 
61 template <typename MaskPixelT>
62 void Mask<MaskPixelT>::_initializePlanes(MaskPlaneDict const& planeDefs) {
63  LOGL_DEBUG("afw.image.Mask", "Number of mask planes: %d", getNumPlanesMax());
64 
65  _maskDict = detail::MaskDict::copyOrGetDefault(planeDefs);
66 }
67 
68 template <typename MaskPixelT>
69 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPlaneDict const& planeDefs)
70  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
71  _initializePlanes(planeDefs);
72  *this = 0x0;
73 }
74 
75 template <typename MaskPixelT>
76 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPixelT initialValue,
77  MaskPlaneDict const& planeDefs)
78  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
79  _initializePlanes(planeDefs);
80  *this = initialValue;
81 }
82 
83 template <typename MaskPixelT>
85  : ImageBase<MaskPixelT>(dimensions) {
86  _initializePlanes(planeDefs);
87  *this = 0x0;
88 }
89 
90 template <typename MaskPixelT>
91 Mask<MaskPixelT>::Mask(lsst::geom::Extent2I const& dimensions, MaskPixelT initialValue,
92  MaskPlaneDict const& planeDefs)
93  : ImageBase<MaskPixelT>(dimensions) {
94  _initializePlanes(planeDefs);
95  *this = initialValue;
96 }
97 
98 template <typename MaskPixelT>
100  : ImageBase<MaskPixelT>(bbox) {
101  _initializePlanes(planeDefs);
102  *this = 0x0;
103 }
104 
105 template <typename MaskPixelT>
106 Mask<MaskPixelT>::Mask(lsst::geom::Box2I const& bbox, MaskPixelT initialValue, MaskPlaneDict const& planeDefs)
107  : ImageBase<MaskPixelT>(bbox) {
108  _initializePlanes(planeDefs);
109  *this = initialValue;
110 }
111 
112 template <typename MaskPixelT>
114  bool const deep)
115  : ImageBase<MaskPixelT>(rhs, bbox, origin, deep), _maskDict(rhs._maskDict) {}
116 
117 template <typename MaskPixelT>
118 Mask<MaskPixelT>::Mask(Mask const& rhs, bool deep)
119  : ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {}
120 // Delegate to copy-constructor for backwards compatibility
121 template <typename MaskPixelT>
122 Mask<MaskPixelT>::Mask(Mask&& rhs) : Mask(rhs, false) {}
123 
124 template <typename MaskPixelT>
125 Mask<MaskPixelT>::~Mask() = default;
126 
127 template <typename MaskPixelT>
128 Mask<MaskPixelT>::Mask(ndarray::Array<MaskPixelT, 2, 1> const& array, bool deep,
129  lsst::geom::Point2I const& xy0)
130  : image::ImageBase<MaskPixelT>(array, deep, xy0), _maskDict(detail::MaskDict::getDefault()) {}
131 
132 template <typename PixelT>
134  using std::swap; // See Meyers, Effective C++, Item 25
135 
137  swap(_maskDict, rhs._maskDict);
138 }
139 
140 template <typename PixelT>
142  a.swap(b);
143 }
144 
145 template <typename MaskPixelT>
147  Mask tmp(rhs);
148  swap(tmp); // See Meyers, Effective C++, Item 11
149 
150  return *this;
151 }
152 // Delegate to copy-assignment for backwards compatibility
153 template <typename MaskPixelT>
155  return *this = rhs;
156 }
157 
158 template <typename MaskPixelT>
160  fill_pixels(_getRawView(), rhs);
161 
162  return *this;
163 }
164 
165 #ifndef DOXYGEN // doc for this section is already in header
166 
167 template <typename MaskPixelT>
169  lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool allowUnsafe)
170  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
171  MaskFitsReader reader(fileName, hdu);
172  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
173  if (metadata) {
174  metadata->combine(reader.readMetadata());
175  }
176 }
177 
178 template <typename MaskPixelT>
179 Mask<MaskPixelT>::Mask(fits::MemFileManager& manager, int hdu,
181  ImageOrigin origin, bool conformMasks, bool allowUnsafe)
182  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
183  MaskFitsReader reader(manager, hdu);
184  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
185  if (metadata) {
186  metadata->combine(reader.readMetadata());
187  }
188 }
189 
190 template <typename MaskPixelT>
192  lsst::geom::Box2I const& bbox, ImageOrigin const origin, bool const conformMasks,
193  bool allowUnsafe)
194  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
195  MaskFitsReader reader(&fitsFile);
196  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
197  if (metadata) {
198  metadata->combine(reader.readMetadata());
199  }
200 }
201 
202 template <typename MaskPixelT>
203 void Mask<MaskPixelT>::writeFits(std::string const& fileName,
205  std::string const& mode) const {
206  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
207  writeFits(fitsfile, metadata_i);
208 }
209 
210 template <typename MaskPixelT>
211 void Mask<MaskPixelT>::writeFits(fits::MemFileManager& manager,
213  std::string const& mode) const {
214  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
215  writeFits(fitsfile, metadata_i);
216 }
217 
218 template <typename MaskPixelT>
219 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile,
221  writeFits(fitsfile, fits::ImageWriteOptions(*this), metadata);
222 }
223 
224 template <typename MaskPixelT>
225 void Mask<MaskPixelT>::writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
226  std::string const& mode,
228  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
229  writeFits(fitsfile, options, header);
230 }
231 
232 template <typename MaskPixelT>
233 void Mask<MaskPixelT>::writeFits(fits::MemFileManager& manager, fits::ImageWriteOptions const& options,
234  std::string const& mode,
236  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
237  writeFits(fitsfile, options, header);
238 }
239 
240 template <typename MaskPixelT>
241 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
244  header ? header->deepCopy() : std::make_shared<dafBase::PropertySet>();
245  addMaskPlanesToMetadata(useHeader);
246  fitsfile.writeImage(*this, options, useHeader);
247 }
248 
249 #endif // !DOXYGEN
250 
251 template <typename MaskPixelT>
253  std::string result = "";
254  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
255  for (MaskPlaneDict::const_iterator iter = mpd.begin(); iter != mpd.end(); ++iter) {
256  if (value & getBitMask(iter->second)) {
257  if (result.size() > 0) {
258  result += ",";
259  }
260  result += iter->first;
261  }
262  }
263  return result;
264 }
265 
266 template <typename MaskPixelT>
268  int id = getMaskPlaneNoThrow(name); // see if the plane is already available
269 
270  if (id < 0) { // doesn't exist
271  id = _maskPlaneDict()->getUnusedPlane();
272  }
273 
274  // build new entry, adding the plane to all Masks where this is no contradiction
275 
276  if (id >= getNumPlanesMax()) { // Max number of planes is already allocated
278  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
279  }
280 
282 
283  return id;
284 }
285 
286 template <typename MaskPixelT>
288  if (planeId < 0 || planeId >= getNumPlanesMax()) {
289  throw LSST_EXCEPT(
291  str(boost::format("mask plane ID must be between 0 and %1%") % (getNumPlanesMax() - 1)));
292  }
293 
294  _maskPlaneDict()->add(name, planeId);
295 
296  return planeId;
297 }
298 
299 template <typename MaskPixelT>
301  return _maskDict->getMaskPlaneDict();
302 }
303 
304 template <typename MaskPixelT>
306  if (detail::MaskDict::getDefault()->getMaskPlane(name) < 0) {
308  str(boost::format("Plane %s doesn't exist in the default Mask") % name));
309  }
310 
311  detail::MaskDict::detachDefault(); // leave current Masks alone
312  _maskPlaneDict()->erase(name);
313 }
314 
315 template <typename MaskPixelT>
316 void Mask<MaskPixelT>::removeAndClearMaskPlane(const std::string& name, bool const removeFromDefault
317 
318 ) {
319  clearMaskPlane(getMaskPlane(name)); // clear this bits in this Mask
320 
321  if (_maskDict == detail::MaskDict::getDefault() && removeFromDefault) { // we are the default
322  ;
323  } else {
324  _maskDict = _maskDict->clone();
325  }
326 
327  _maskDict->erase(name);
328 
329  if (removeFromDefault && detail::MaskDict::getDefault()->getMaskPlane(name) >= 0) {
330  removeMaskPlane(name);
331  }
332 }
333 
334 template <typename MaskPixelT>
335 MaskPixelT Mask<MaskPixelT>::getBitMaskNoThrow(int planeId) {
336  return (planeId >= 0 && planeId < getNumPlanesMax()) ? (1 << planeId) : 0;
337 }
338 
339 template <typename MaskPixelT>
340 MaskPixelT Mask<MaskPixelT>::getBitMask(int planeId) {
341  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
342 
343  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
344  if (planeId == i->second) {
345  MaskPixelT const bitmask = getBitMaskNoThrow(planeId);
346  if (bitmask == 0) { // failed
347  break;
348  }
349  return bitmask;
350  }
351  }
353  str(boost::format("Invalid mask plane ID: %d") % planeId));
354 }
355 
356 template <typename MaskPixelT>
358  int const plane = getMaskPlaneNoThrow(name);
359 
360  if (plane < 0) {
362  str(boost::format("Invalid mask plane name: %s") % name));
363  } else {
364  return plane;
365  }
366 }
367 
368 template <typename MaskPixelT>
370  return _maskPlaneDict()->getMaskPlane(name);
371 }
372 
373 template <typename MaskPixelT>
375  return getBitMask(getMaskPlane(name));
376 }
377 
378 template <typename MaskPixelT>
380  MaskPixelT mpix = 0x0;
381  for (std::vector<std::string>::const_iterator it = name.begin(); it != name.end(); ++it) {
382  mpix |= getBitMask(getMaskPlane(*it));
383  }
384  return mpix;
385 }
386 
387 template <typename MaskPixelT>
389  return _maskPlaneDict()->size();
390 }
391 
392 template <typename MaskPixelT>
394  _maskPlaneDict()->clear();
395 }
396 
397 template <typename MaskPixelT>
399  *this = 0;
400 }
401 
402 template <typename MaskPixelT>
404  *this &= ~getBitMask(planeId);
405 }
406 
407 template <typename MaskPixelT>
408 void Mask<MaskPixelT>::conformMaskPlanes(MaskPlaneDict const& currentPlaneDict) {
410 
411  if (*_maskDict == *currentMD) {
412  if (*detail::MaskDict::getDefault() == *_maskDict) {
413  return; // nothing to do
414  }
415  } else {
416  //
417  // Find out which planes need to be permuted
418  //
419  MaskPixelT keepBitmask = 0; // mask of bits to keep
420  MaskPixelT canonicalMask[sizeof(MaskPixelT) * 8]; // bits in lsst::afw::image::Mask that should be
421  MaskPixelT currentMask[sizeof(MaskPixelT) * 8]; // mapped to these bits
422  int numReMap = 0;
423 
424  for (MaskPlaneDict::const_iterator i = currentPlaneDict.begin(); i != currentPlaneDict.end(); i++) {
425  std::string const name = i->first; // name of mask plane
426  int const currentPlaneNumber = i->second; // plane number currently in use
427  int canonicalPlaneNumber = getMaskPlaneNoThrow(name); // plane number in lsst::afw::image::Mask
428 
429  if (canonicalPlaneNumber < 0) { // no such plane; add it
430  canonicalPlaneNumber = addMaskPlane(name);
431  }
432 
433  if (canonicalPlaneNumber == currentPlaneNumber) {
434  keepBitmask |= getBitMask(canonicalPlaneNumber); // bit is unchanged, so preserve it
435  } else {
436  canonicalMask[numReMap] = getBitMask(canonicalPlaneNumber);
437  currentMask[numReMap] = getBitMaskNoThrow(currentPlaneNumber);
438  numReMap++;
439  }
440  }
441 
442  // Now loop over all pixels in Mask
443  if (numReMap > 0) {
444  for (int r = 0; r != this->getHeight(); ++r) { // "this->": Meyers, Effective C++, Item 43
445  for (typename Mask::x_iterator ptr = this->row_begin(r), end = this->row_end(r); ptr != end;
446  ++ptr) {
447  MaskPixelT const pixel = *ptr;
448 
449  MaskPixelT newPixel = pixel & keepBitmask; // value of invariant mask bits
450  for (int i = 0; i < numReMap; i++) {
451  if (pixel & currentMask[i]) newPixel |= canonicalMask[i];
452  }
453 
454  *ptr = newPixel;
455  }
456  }
457  }
458  }
459  // We've made the planes match the current mask dictionary
460  _maskDict = detail::MaskDict::getDefault();
461 }
462 
463 template <typename MaskPixelT>
465  return this->ImageBase<MaskPixelT>::operator()(x, y);
466 }
467 
468 template <typename MaskPixelT>
470  CheckIndices const& check) {
471  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
472 }
473 
474 template <typename MaskPixelT>
476  return this->ImageBase<MaskPixelT>::operator()(x, y);
477 }
478 
479 template <typename MaskPixelT>
481  int x, int y, CheckIndices const& check) const {
482  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
483 }
484 
485 template <typename MaskPixelT>
486 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId) const {
487  // !! converts an int to a bool
488  return !!(this->ImageBase<MaskPixelT>::operator()(x, y) & getBitMask(planeId));
489 }
490 
491 template <typename MaskPixelT>
492 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId, CheckIndices const& check) const {
493  // !! converts an int to a bool
494  return !!(this->ImageBase<MaskPixelT>::operator()(x, y, check) & getBitMask(planeId));
495 }
496 
497 template <typename MaskPixelT>
499  if (*_maskDict != *other._maskDict) {
500  throw LSST_EXCEPT(pexExcept::RuntimeError, "Mask dictionaries do not match");
501  }
502 }
503 
504 template <typename MaskPixelT>
506  transform_pixels(_getRawView(), _getRawView(),
507  [&val](MaskPixelT const& l) -> MaskPixelT { return l | val; });
508  return *this;
509 }
510 
511 template <typename MaskPixelT>
513  checkMaskDictionaries(rhs);
514 
515  if (this->getDimensions() != rhs.getDimensions()) {
517  str(boost::format("Images are of different size, %dx%d v %dx%d") %
518  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
519  }
520  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
521  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l | r; });
522  return *this;
523 }
524 
525 template <typename MaskPixelT>
527  transform_pixels(_getRawView(), _getRawView(), [&val](MaskPixelT const& l) { return l & val; });
528  return *this;
529 }
530 
531 template <typename MaskPixelT>
533  checkMaskDictionaries(rhs);
534 
535  if (this->getDimensions() != rhs.getDimensions()) {
537  str(boost::format("Images are of different size, %dx%d v %dx%d") %
538  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
539  }
540  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
541  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l & r; });
542  return *this;
543 }
544 
545 template <typename MaskPixelT>
547  transform_pixels(_getRawView(), _getRawView(),
548  [&val](MaskPixelT const& l) -> MaskPixelT { return l ^ val; });
549  return *this;
550 }
551 
552 template <typename MaskPixelT>
554  checkMaskDictionaries(rhs);
555 
556  if (this->getDimensions() != rhs.getDimensions()) {
558  str(boost::format("Images are of different size, %dx%d v %dx%d") %
559  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
560  }
561  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
562  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l ^ r; });
563  return *this;
564 }
565 
566 template <typename MaskPixelT>
567 void Mask<MaskPixelT>::setMaskPlaneValues(int const planeId, int const x0, int const x1, int const y) {
568  MaskPixelT const bitMask = getBitMask(planeId);
569 
570  for (int x = x0; x <= x1; x++) {
571  operator()(x, y) = operator()(x, y) | bitMask;
572  }
573 }
574 
575 template <typename MaskPixelT>
577  if (!metadata) {
578  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "Null std::shared_ptr<PropertySet>");
579  }
580 
581  // First, clear existing MaskPlane metadata
582  typedef std::vector<std::string> NameList;
583  NameList paramNames = metadata->paramNames(false);
584  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
585  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
586  metadata->remove(*i);
587  }
588  }
589 
590  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
591 
592  // Add new MaskPlane metadata
593  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
594  std::string const& planeName = i->first;
595  int const planeNumber = i->second;
596 
597  if (planeName != "") {
598  metadata->add(maskPlanePrefix + planeName, planeNumber);
599  }
600  }
601 }
602 
603 template <typename MaskPixelT>
606  MaskPlaneDict newDict;
607 
608  // First, clear existing MaskPlane metadata
609  typedef std::vector<std::string> NameList;
610  NameList paramNames = metadata->paramNames(false);
611  int numPlanesUsed = 0; // number of planes used
612 
613  // Iterate over childless properties with names starting with maskPlanePrefix
614  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
615  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
616  // split off maskPlanePrefix to obtain plane name
617  std::string planeName = i->substr(maskPlanePrefix.size());
618  int const planeId = metadata->getAsInt(*i);
619 
620  MaskPlaneDict::const_iterator plane = newDict.find(planeName);
621  if (plane != newDict.end() && planeId != plane->second) {
622  throw LSST_EXCEPT(pexExcept::RuntimeError, "File specifies plane " + planeName + " twice");
623  }
624  for (MaskPlaneDict::const_iterator j = newDict.begin(); j != newDict.end(); ++j) {
625  if (planeId == j->second) {
627  str(boost::format("File specifies plane %s has same value (%d) as %s") %
628  planeName % planeId % j->first));
629  }
630  }
631  // build new entry
632  if (numPlanesUsed >= getNumPlanesMax()) {
633  // Max number of planes already allocated
634  throw LSST_EXCEPT(
636  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
637  }
638  newDict[planeName] = planeId;
639  }
640  }
641  return newDict;
642 }
643 
644 template <typename MaskPixelT>
646  _maskDict->print();
647 }
648 
649 /*
650  * Static members of Mask
651  */
652 template <typename MaskPixelT>
654 
655 template <typename MaskPixelT>
658 }
659 
660 //
661 // Explicit instantiations
662 //
663 template class Mask<MaskPixel>;
664 } // namespace image
665 } // namespace afw
666 } // namespace lsst
py::object result
Definition: _schema.cc:430
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,...)
Create an exception with a given type.
Definition: Exception.h:48
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
LSST DM logging module built on log4cxx.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:504
uint64_t * ptr
Definition: RangeSet.cc:88
ItemVariant const * other
Definition: Schema.cc:56
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:184
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:246
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:133
Mask & operator=(MaskPixelT const rhs)
Definition: Mask.cc:159
friend class MaskFitsReader
Definition: Mask.h:521
void printMaskPlanes() const
print the mask plane dictionary to std::cout
Definition: Mask.cc:645
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:357
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:252
static void removeMaskPlane(const std::string &name)
Definition: Mask.cc:305
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:316
static void clearMaskPlaneDict()
Reset the maskPlane dictionary.
Definition: Mask.cc:393
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:567
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:576
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition: Mask.cc:464
Mask & operator^=(Mask const &rhs)
XOR a Mask into a Mask.
Definition: Mask.cc:553
static int addMaskPlane(const std::string &name)
Definition: Mask.cc:267
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:379
Mask(unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition: Mask.cc:69
MaskPlaneDict const & getMaskPlaneDict() const
Return the Mask's maskPlaneDict.
Definition: Mask.cc:300
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:408
Mask & operator|=(Mask const &rhs)
OR a Mask into a Mask.
Definition: Mask.cc:512
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:604
void clearAllMaskPlanes()
Clear all the pixels.
Definition: Mask.cc:398
static int getNumPlanesUsed()
Definition: Mask.cc:388
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition: Mask.cc:403
Mask & operator&=(Mask const &rhs)
AND a Mask into a Mask.
Definition: Mask.cc:532
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
An integer coordinate rectangle.
Definition: Box.h:55
Reports invalid arguments.
Definition: Runtime.h:66
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
Reports when the result of an operation cannot be represented by the destination type.
Definition: Runtime.h:115
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
T end(T... args)
T find(T... args)
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:456
Extent< int, 2 > ExtentI
Definition: Extent.h:396
def writeFits(filename, stamp_ims, metadata, type_name, write_mask, write_variance)
Definition: stamps.py:40
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
A base class for image defects.
ImageT val
Definition: CR.cc:146
T substr(T... args)
T swap(T... args)