LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
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)
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>
181  ImageOrigin origin, bool conformMasks, bool allowUnsafe)
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)
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>
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>
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>
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
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
Mask< PixelT > read(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the Mask.
static std::shared_ptr< MaskDict > getDefault()
Definition: MaskDict.cc:115
A FITS reader class for Masks.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:252
uint64_t * ptr
Definition: RangeSet.cc:88
static void clearMaskPlaneDict()
Reset the maskPlane dictionary.
Definition: Mask.cc:393
std::shared_ptr< daf::base::PropertyList > readMetadata()
Read the image&#39;s FITS header.
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:357
T swap(T... args)
int getHeight() const
Return the number of rows in the image.
Definition: ImageBase.h:315
table::Key< int > b
std::map< std::string, int > MaskPlaneDict
Definition: Mask.h:58
Reports attempts to exceed implementation-defined length limits for some classes. ...
Definition: Runtime.h:76
Options for writing an image to FITS.
Definition: fits.h:219
Mask & operator=(MaskPixelT const rhs)
Definition: Mask.cc:159
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:133
int y
Definition: SpanSet.cc:49
static std::shared_ptr< MaskDict > detachDefault()
Definition: MaskDict.cc:123
table::Key< int > a
ImageT val
Definition: CR.cc:146
T end(T... args)
table::Key< int > id
Definition: Detector.cc:162
ItemVariant const * other
Definition: Schema.cc:56
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
static int getNumPlanesUsed()
Definition: Mask.cc:388
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: ImageBase.h:102
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 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
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y&#39;th row.
Definition: ImageBase.h:418
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:504
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition: Mask.cc:464
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:268
STL class.
LSST DM logging module built on log4cxx.
Mask(unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition: Mask.cc:69
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:77
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
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
A class used to request that array accesses be checked.
Definition: ImageBase.h:74
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:379
void swap(ImageBase &rhs)
Definition: Image.cc:246
double x
MaskPlaneDict const & getMaskPlaneDict() const
Return the Mask&#39;s maskPlaneDict.
Definition: Mask.cc:300
T find(T... args)
T size(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
static void removeMaskPlane(const std::string &name)
Definition: Mask.cc:305
static int getNumPlanesMax()
Definition: Mask.h:489
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:313
Extent< int, 2 > ExtentI
Definition: Extent.h:396
Reports invalid arguments.
Definition: Runtime.h:66
Mask & operator|=(Mask const &rhs)
OR a Mask into a Mask.
Definition: Mask.cc:512
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: ImageBase.h:421
T substr(T... args)
table::PointKey< int > pixel
void swap(Mask &rhs)
Definition: Mask.cc:133
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:408
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:373
Mask & operator^=(Mask const &rhs)
XOR a Mask into a Mask.
Definition: Mask.cc:553
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition: Mask.cc:403
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
Definition: fits.h:477
An integer coordinate rectangle.
Definition: Box.h:55
void clearAllMaskPlanes()
Clear all the pixels.
Definition: Mask.cc:398
py::object result
Definition: _schema.cc:429
Reports when the result of an operation cannot be represented by the destination type.
Definition: Runtime.h:115
static int addMaskPlane(const std::string &name)
Definition: Mask.cc:267
PixelReference operator()(int x, int y)
Definition: Image.cc:184
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
void printMaskPlanes() const
print the mask plane dictionary to std::cout
Definition: Mask.cc:645