LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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/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"
52 
53 namespace dafBase = lsst::daf::base;
55 
56 namespace lsst {
57 namespace afw {
58 namespace image {
59 
60 namespace {
61 
62 } // namespace
63 
64 template <typename MaskPixelT>
65 void Mask<MaskPixelT>::_initializePlanes(MaskPlaneDict const& planeDefs) {
66  LOGL_DEBUG("afw.image.Mask", "Number of mask planes: %d", getNumPlanesMax());
67 
68  _maskDict = detail::MaskDict::copyOrGetDefault(planeDefs);
69 }
70 
71 template <typename MaskPixelT>
72 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPlaneDict const& planeDefs)
73  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
74  _initializePlanes(planeDefs);
75  *this = 0x0;
76 }
77 
78 template <typename MaskPixelT>
79 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPixelT initialValue,
80  MaskPlaneDict const& planeDefs)
81  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
82  _initializePlanes(planeDefs);
83  *this = initialValue;
84 }
85 
86 template <typename MaskPixelT>
88  : ImageBase<MaskPixelT>(dimensions) {
89  _initializePlanes(planeDefs);
90  *this = 0x0;
91 }
92 
93 template <typename MaskPixelT>
94 Mask<MaskPixelT>::Mask(lsst::geom::Extent2I const& dimensions, MaskPixelT initialValue,
95  MaskPlaneDict const& planeDefs)
96  : ImageBase<MaskPixelT>(dimensions) {
97  _initializePlanes(planeDefs);
98  *this = initialValue;
99 }
100 
101 template <typename MaskPixelT>
103  : ImageBase<MaskPixelT>(bbox) {
104  _initializePlanes(planeDefs);
105  *this = 0x0;
106 }
107 
108 template <typename MaskPixelT>
109 Mask<MaskPixelT>::Mask(lsst::geom::Box2I const& bbox, MaskPixelT initialValue, MaskPlaneDict const& planeDefs)
110  : ImageBase<MaskPixelT>(bbox) {
111  _initializePlanes(planeDefs);
112  *this = initialValue;
113 }
114 
115 template <typename MaskPixelT>
117  bool const deep)
118  : ImageBase<MaskPixelT>(rhs, bbox, origin, deep), _maskDict(rhs._maskDict) {}
119 
120 template <typename MaskPixelT>
121 Mask<MaskPixelT>::Mask(Mask const& rhs, bool deep)
122  : ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {}
123 // Delegate to copy-constructor for backwards compatibility
124 template <typename MaskPixelT>
125 Mask<MaskPixelT>::Mask(Mask&& rhs) : Mask(rhs, false) {}
126 
127 template <typename MaskPixelT>
128 Mask<MaskPixelT>::~Mask() = default;
129 
130 template <typename MaskPixelT>
131 Mask<MaskPixelT>::Mask(ndarray::Array<MaskPixelT, 2, 1> const& array, bool deep,
132  lsst::geom::Point2I const& xy0)
133  : image::ImageBase<MaskPixelT>(array, deep, xy0), _maskDict(detail::MaskDict::getDefault()) {}
134 
135 template <typename PixelT>
137  using std::swap; // See Meyers, Effective C++, Item 25
138 
140  swap(_maskDict, rhs._maskDict);
141 }
142 
143 template <typename PixelT>
145  a.swap(b);
146 }
147 
148 template <typename MaskPixelT>
150  Mask tmp(rhs);
151  swap(tmp); // See Meyers, Effective C++, Item 11
152 
153  return *this;
154 }
155 // Delegate to copy-assignment for backwards compatibility
156 template <typename MaskPixelT>
158  return *this = rhs;
159 }
160 
161 template <typename MaskPixelT>
163  fill_pixels(_getRawView(), rhs);
164 
165  return *this;
166 }
167 
168 #ifndef DOXYGEN // doc for this section is already in header
169 
170 template <typename MaskPixelT>
172  lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool allowUnsafe)
174  MaskFitsReader reader(fileName, hdu);
175  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
176  if (metadata) {
177  metadata->combine(reader.readMetadata());
178  }
179 }
180 
181 template <typename MaskPixelT>
184  ImageOrigin origin, bool conformMasks, bool allowUnsafe)
186  MaskFitsReader reader(manager, hdu);
187  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
188  if (metadata) {
189  metadata->combine(reader.readMetadata());
190  }
191 }
192 
193 template <typename MaskPixelT>
195  lsst::geom::Box2I const& bbox, ImageOrigin const origin, bool const conformMasks,
196  bool allowUnsafe)
198  MaskFitsReader reader(&fitsFile);
199  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
200  if (metadata) {
201  metadata->combine(reader.readMetadata());
202  }
203 }
204 
205 template <typename MaskPixelT>
206 void Mask<MaskPixelT>::writeFits(std::string const& fileName,
208  std::string const& mode) const {
209  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
210  writeFits(fitsfile, metadata_i);
211 }
212 
213 template <typename MaskPixelT>
216  std::string const& mode) const {
217  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
218  writeFits(fitsfile, metadata_i);
219 }
220 
221 template <typename MaskPixelT>
224  writeFits(fitsfile, fits::ImageWriteOptions(*this), metadata);
225 }
226 
227 template <typename MaskPixelT>
229  std::string const& mode,
231  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
232  writeFits(fitsfile, options, header);
233 }
234 
235 template <typename MaskPixelT>
237  std::string const& mode,
239  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
240  writeFits(fitsfile, options, header);
241 }
242 
243 template <typename MaskPixelT>
244 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
247  header ? header->deepCopy() : std::make_shared<dafBase::PropertySet>();
248  addMaskPlanesToMetadata(useHeader);
249  fitsfile.writeImage(*this, options, useHeader);
250 }
251 
252 #endif // !DOXYGEN
253 
254 
255 template <typename MaskPixelT>
257  std::string result = "";
258  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
259  for (MaskPlaneDict::const_iterator iter = mpd.begin(); iter != mpd.end(); ++iter) {
260  if (value & getBitMask(iter->second)) {
261  if (result.size() > 0) {
262  result += ",";
263  }
264  result += iter->first;
265  }
266  }
267  return result;
268 }
269 
270 template <typename MaskPixelT>
272  int id = getMaskPlaneNoThrow(name); // see if the plane is already available
273 
274  if (id < 0) { // doesn't exist
275  id = _maskPlaneDict()->getUnusedPlane();
276  }
277 
278  // build new entry, adding the plane to all Masks where this is no contradiction
279 
280  if (id >= getNumPlanesMax()) { // Max number of planes is already allocated
282  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
283  }
284 
286 
287  return id;
288 }
289 
290 template <typename MaskPixelT>
292  if (planeId < 0 || planeId >= getNumPlanesMax()) {
293  throw LSST_EXCEPT(
295  str(boost::format("mask plane ID must be between 0 and %1%") % (getNumPlanesMax() - 1)));
296  }
297 
298  _maskPlaneDict()->add(name, planeId);
299 
300  return planeId;
301 }
302 
303 template <typename MaskPixelT>
305  return _maskDict->getMaskPlaneDict();
306 }
307 
308 template <typename MaskPixelT>
310  if (detail::MaskDict::getDefault()->getMaskPlane(name) < 0) {
312  str(boost::format("Plane %s doesn't exist in the default Mask") % name));
313  }
314 
315  detail::MaskDict::detachDefault(); // leave current Masks alone
316  _maskPlaneDict()->erase(name);
317 }
318 
319 template <typename MaskPixelT>
320 void Mask<MaskPixelT>::removeAndClearMaskPlane(const std::string& name, bool const removeFromDefault
321 
322 ) {
323  clearMaskPlane(getMaskPlane(name)); // clear this bits in this Mask
324 
325  if (_maskDict == detail::MaskDict::getDefault() && removeFromDefault) { // we are the default
326  ;
327  } else {
328  _maskDict = _maskDict->clone();
329  }
330 
331  _maskDict->erase(name);
332 
333  if (removeFromDefault && detail::MaskDict::getDefault()->getMaskPlane(name) >= 0) {
334  removeMaskPlane(name);
335  }
336 }
337 
338 template <typename MaskPixelT>
339 MaskPixelT Mask<MaskPixelT>::getBitMaskNoThrow(int planeId) {
340  return (planeId >= 0 && planeId < getNumPlanesMax()) ? (1 << planeId) : 0;
341 }
342 
343 template <typename MaskPixelT>
344 MaskPixelT Mask<MaskPixelT>::getBitMask(int planeId) {
345  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
346 
347  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
348  if (planeId == i->second) {
349  MaskPixelT const bitmask = getBitMaskNoThrow(planeId);
350  if (bitmask == 0) { // failed
351  break;
352  }
353  return bitmask;
354  }
355  }
357  str(boost::format("Invalid mask plane ID: %d") % planeId));
358 }
359 
360 template <typename MaskPixelT>
362  int const plane = getMaskPlaneNoThrow(name);
363 
364  if (plane < 0) {
366  str(boost::format("Invalid mask plane name: %s") % name));
367  } else {
368  return plane;
369  }
370 }
371 
372 template <typename MaskPixelT>
374  return _maskPlaneDict()->getMaskPlane(name);
375 }
376 
377 template <typename MaskPixelT>
379  return getBitMask(getMaskPlane(name));
380 }
381 
382 template <typename MaskPixelT>
384  MaskPixelT mpix = 0x0;
385  for (std::vector<std::string>::const_iterator it = name.begin(); it != name.end(); ++it) {
386  mpix |= getBitMask(getMaskPlane(*it));
387  }
388  return mpix;
389 }
390 
391 template <typename MaskPixelT>
393  return _maskPlaneDict()->size();
394 }
395 
396 template <typename MaskPixelT>
398  _maskPlaneDict()->clear();
399 }
400 
401 template <typename MaskPixelT>
403  *this = 0;
404 }
405 
406 template <typename MaskPixelT>
408  *this &= ~getBitMask(planeId);
409 }
410 
411 template <typename MaskPixelT>
412 void Mask<MaskPixelT>::conformMaskPlanes(MaskPlaneDict const& currentPlaneDict) {
414 
415  if (*_maskDict == *currentMD) {
416  if (*detail::MaskDict::getDefault() == *_maskDict) {
417  return; // nothing to do
418  }
419  } else {
420  //
421  // Find out which planes need to be permuted
422  //
423  MaskPixelT keepBitmask = 0; // mask of bits to keep
424  MaskPixelT canonicalMask[sizeof(MaskPixelT) * 8]; // bits in lsst::afw::image::Mask that should be
425  MaskPixelT currentMask[sizeof(MaskPixelT) * 8]; // mapped to these bits
426  int numReMap = 0;
427 
428  for (MaskPlaneDict::const_iterator i = currentPlaneDict.begin(); i != currentPlaneDict.end(); i++) {
429  std::string const name = i->first; // name of mask plane
430  int const currentPlaneNumber = i->second; // plane number currently in use
431  int canonicalPlaneNumber = getMaskPlaneNoThrow(name); // plane number in lsst::afw::image::Mask
432 
433  if (canonicalPlaneNumber < 0) { // no such plane; add it
434  canonicalPlaneNumber = addMaskPlane(name);
435  }
436 
437  if (canonicalPlaneNumber == currentPlaneNumber) {
438  keepBitmask |= getBitMask(canonicalPlaneNumber); // bit is unchanged, so preserve it
439  } else {
440  canonicalMask[numReMap] = getBitMask(canonicalPlaneNumber);
441  currentMask[numReMap] = getBitMaskNoThrow(currentPlaneNumber);
442  numReMap++;
443  }
444  }
445 
446  // Now loop over all pixels in Mask
447  if (numReMap > 0) {
448  for (int r = 0; r != this->getHeight(); ++r) { // "this->": Meyers, Effective C++, Item 43
449  for (typename Mask::x_iterator ptr = this->row_begin(r), end = this->row_end(r); ptr != end;
450  ++ptr) {
451  MaskPixelT const pixel = *ptr;
452 
453  MaskPixelT newPixel = pixel & keepBitmask; // value of invariant mask bits
454  for (int i = 0; i < numReMap; i++) {
455  if (pixel & currentMask[i]) newPixel |= canonicalMask[i];
456  }
457 
458  *ptr = newPixel;
459  }
460  }
461  }
462  }
463  // We've made the planes match the current mask dictionary
464  _maskDict = detail::MaskDict::getDefault();
465 }
466 
467 template <typename MaskPixelT>
469  return this->ImageBase<MaskPixelT>::operator()(x, y);
470 }
471 
472 template <typename MaskPixelT>
474  CheckIndices const& check) {
475  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
476 }
477 
478 template <typename MaskPixelT>
480  return this->ImageBase<MaskPixelT>::operator()(x, y);
481 }
482 
483 template <typename MaskPixelT>
485  int x, int y, CheckIndices const& check) const {
486  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
487 }
488 
489 template <typename MaskPixelT>
490 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId) const {
491  // !! converts an int to a bool
492  return !!(this->ImageBase<MaskPixelT>::operator()(x, y) & getBitMask(planeId));
493 }
494 
495 template <typename MaskPixelT>
496 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId, CheckIndices const& check) const {
497  // !! converts an int to a bool
498  return !!(this->ImageBase<MaskPixelT>::operator()(x, y, check) & getBitMask(planeId));
499 }
500 
501 template <typename MaskPixelT>
503  if (*_maskDict != *other._maskDict) {
504  throw LSST_EXCEPT(pexExcept::RuntimeError, "Mask dictionaries do not match");
505  }
506 }
507 
508 template <typename MaskPixelT>
510  transform_pixels(_getRawView(), _getRawView(),
511  [&val](MaskPixelT const& l) -> MaskPixelT { return l | val; });
512  return *this;
513 }
514 
515 template <typename MaskPixelT>
517  checkMaskDictionaries(rhs);
518 
519  if (this->getDimensions() != rhs.getDimensions()) {
521  str(boost::format("Images are of different size, %dx%d v %dx%d") %
522  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
523  }
524  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
525  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l | r; });
526  return *this;
527 }
528 
529 template <typename MaskPixelT>
531  transform_pixels(_getRawView(), _getRawView(), [&val](MaskPixelT const& l) { return l & val; });
532  return *this;
533 }
534 
535 template <typename MaskPixelT>
537  checkMaskDictionaries(rhs);
538 
539  if (this->getDimensions() != rhs.getDimensions()) {
541  str(boost::format("Images are of different size, %dx%d v %dx%d") %
542  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
543  }
544  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
545  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l & r; });
546  return *this;
547 }
548 
549 template <typename MaskPixelT>
551  transform_pixels(_getRawView(), _getRawView(),
552  [&val](MaskPixelT const& l) -> MaskPixelT { 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>
571 void Mask<MaskPixelT>::setMaskPlaneValues(int const planeId, int const x0, int const x1, int const y) {
572  MaskPixelT const bitMask = getBitMask(planeId);
573 
574  for (int x = x0; x <= x1; x++) {
575  operator()(x, y) = operator()(x, y) | bitMask;
576  }
577 }
578 
579 template <typename MaskPixelT>
581  if (!metadata) {
582  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "Null std::shared_ptr<PropertySet>");
583  }
584 
585  // First, clear existing MaskPlane metadata
586  typedef std::vector<std::string> NameList;
587  NameList paramNames = metadata->paramNames(false);
588  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
589  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
590  metadata->remove(*i);
591  }
592  }
593 
594  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
595 
596  // Add new MaskPlane metadata
597  for (MaskPlaneDict::const_iterator i = mpd.begin(); i != mpd.end(); ++i) {
598  std::string const& planeName = i->first;
599  int const planeNumber = i->second;
600 
601  if (planeName != "") {
602  metadata->add(maskPlanePrefix + planeName, planeNumber);
603  }
604  }
605 }
606 
607 template <typename MaskPixelT>
610  MaskPlaneDict newDict;
611 
612  // First, clear existing MaskPlane metadata
613  typedef std::vector<std::string> NameList;
614  NameList paramNames = metadata->paramNames(false);
615  int numPlanesUsed = 0; // number of planes used
616 
617  // Iterate over childless properties with names starting with maskPlanePrefix
618  for (NameList::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) {
619  if (i->compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
620  // split off maskPlanePrefix to obtain plane name
621  std::string planeName = i->substr(maskPlanePrefix.size());
622  int const planeId = metadata->getAsInt(*i);
623 
624  MaskPlaneDict::const_iterator plane = newDict.find(planeName);
625  if (plane != newDict.end() && planeId != plane->second) {
626  throw LSST_EXCEPT(pexExcept::RuntimeError, "File specifies plane " + planeName + " twice");
627  }
628  for (MaskPlaneDict::const_iterator j = newDict.begin(); j != newDict.end(); ++j) {
629  if (planeId == j->second) {
631  str(boost::format("File specifies plane %s has same value (%d) as %s") %
632  planeName % planeId % j->first));
633  }
634  }
635  // build new entry
636  if (numPlanesUsed >= getNumPlanesMax()) {
637  // Max number of planes already allocated
638  throw LSST_EXCEPT(
640  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
641  }
642  newDict[planeName] = planeId;
643  }
644  }
645  return newDict;
646 }
647 
648 template <typename MaskPixelT>
650  _maskDict->print();
651 }
652 
653 /*
654  * Static members of Mask
655  */
656 template <typename MaskPixelT>
658 
659 template <typename MaskPixelT>
662 }
663 
664 //
665 // Explicit instantiations
666 //
667 template class Mask<MaskPixel>;
668 } // namespace image
669 } // namespace afw
670 } // namespace lsst
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.
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:256
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:49
uint64_t * ptr
Definition: RangeSet.cc:88
static void clearMaskPlaneDict()
Reset the maskPlane dictionary.
Definition: Mask.cc:397
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:361
T swap(T... args)
int getHeight() const
Return the number of rows in the image.
Definition: ImageBase.h:316
table::Key< int > b
std::map< std::string, int > MaskPlaneDict
Definition: Mask.h:59
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:162
py::object result
Definition: schema.cc:418
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:134
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)
tuple options
Definition: lsstimport.py:47
table::Key< int > id
Definition: Detector.cc:166
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:580
static int getNumPlanesUsed()
Definition: Mask.cc:392
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: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:320
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:608
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y&#39;th row.
Definition: ImageBase.h:419
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:489
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition: Mask.cc:468
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:280
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:72
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:121
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168
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:571
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:383
void swap(ImageBase &rhs)
Definition: Image.cc:258
table::Box2IKey bbox
Definition: Detector.cc:169
double x
MaskPlaneDict const & getMaskPlaneDict() const
Return the Mask&#39;s maskPlaneDict.
Definition: Mask.cc:304
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:309
static int getNumPlanesMax()
Definition: Mask.h:492
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:314
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:516
x_iterator row_end(int y) const
Return an x_iterator to the end of the y&#39;th row.
Definition: ImageBase.h:422
T substr(T... args)
table::PointKey< int > pixel
ItemVariant const * other
Definition: Schema.cc:56
void swap(Mask &rhs)
Definition: Mask.cc:136
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:412
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:374
Mask & operator^=(Mask const &rhs)
XOR a Mask into a Mask.
Definition: Mask.cc:557
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:407
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:54
void clearAllMaskPlanes()
Clear all the pixels.
Definition: Mask.cc:402
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:271
PixelReference operator()(int x, int y)
Definition: Image.cc:195
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:649