LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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 #include "boost/format.hpp"
35 
36 #include "lsst/daf/base.h"
37 #include "lsst/geom.h"
38 #include "lsst/pex/exceptions.h"
39 #include "lsst/log/Log.h"
40 #include "lsst/afw/image/Mask.h"
44 
45 namespace dafBase = lsst::daf::base;
47 
48 namespace lsst {
49 namespace afw {
50 namespace image {
51 
52 namespace {} // namespace
53 
54 template <typename MaskPixelT>
55 void Mask<MaskPixelT>::_initializePlanes(MaskPlaneDict const& planeDefs) {
56  LOGL_DEBUG("afw.image.Mask", "Number of mask planes: %d", getNumPlanesMax());
57 
58  _maskDict = detail::MaskDict::copyOrGetDefault(planeDefs);
59 }
60 
61 template <typename MaskPixelT>
62 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPlaneDict const& planeDefs)
63  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
64  _initializePlanes(planeDefs);
65  *this = 0x0;
66 }
67 
68 template <typename MaskPixelT>
69 Mask<MaskPixelT>::Mask(unsigned int width, unsigned int height, MaskPixelT initialValue,
70  MaskPlaneDict const& planeDefs)
71  : ImageBase<MaskPixelT>(lsst::geom::ExtentI(width, height)) {
72  _initializePlanes(planeDefs);
73  *this = initialValue;
74 }
75 
76 template <typename MaskPixelT>
78  : ImageBase<MaskPixelT>(dimensions) {
79  _initializePlanes(planeDefs);
80  *this = 0x0;
81 }
82 
83 template <typename MaskPixelT>
84 Mask<MaskPixelT>::Mask(lsst::geom::Extent2I const& dimensions, MaskPixelT initialValue,
85  MaskPlaneDict const& planeDefs)
86  : ImageBase<MaskPixelT>(dimensions) {
87  _initializePlanes(planeDefs);
88  *this = initialValue;
89 }
90 
91 template <typename MaskPixelT>
93  : ImageBase<MaskPixelT>(bbox) {
94  _initializePlanes(planeDefs);
95  *this = 0x0;
96 }
97 
98 template <typename MaskPixelT>
99 Mask<MaskPixelT>::Mask(lsst::geom::Box2I const& bbox, MaskPixelT initialValue, MaskPlaneDict const& planeDefs)
100  : ImageBase<MaskPixelT>(bbox) {
101  _initializePlanes(planeDefs);
102  *this = initialValue;
103 }
104 
105 template <typename MaskPixelT>
107  bool const deep)
108  : ImageBase<MaskPixelT>(rhs, bbox, origin, deep), _maskDict(rhs._maskDict) {}
109 
110 template <typename MaskPixelT>
111 Mask<MaskPixelT>::Mask(Mask const& rhs, bool deep)
112  : ImageBase<MaskPixelT>(rhs, deep), _maskDict(rhs._maskDict) {}
113 // Delegate to copy-constructor for backwards compatibility
114 template <typename MaskPixelT>
115 Mask<MaskPixelT>::Mask(Mask&& rhs) : Mask(rhs, false) {}
116 
117 template <typename MaskPixelT>
118 Mask<MaskPixelT>::~Mask() = default;
119 
120 template <typename MaskPixelT>
121 Mask<MaskPixelT>::Mask(ndarray::Array<MaskPixelT, 2, 1> const& array, bool deep,
122  lsst::geom::Point2I const& xy0)
123  : image::ImageBase<MaskPixelT>(array, deep, xy0), _maskDict(detail::MaskDict::getDefault()) {}
124 
125 template <typename PixelT>
127  using std::swap; // See Meyers, Effective C++, Item 25
128 
130  swap(_maskDict, rhs._maskDict);
131 }
132 
133 template <typename PixelT>
135  a.swap(b);
136 }
137 
138 template <typename MaskPixelT>
140  Mask tmp(rhs);
141  swap(tmp); // See Meyers, Effective C++, Item 11
142 
143  return *this;
144 }
145 // Delegate to copy-assignment for backwards compatibility
146 template <typename MaskPixelT>
148  return *this = rhs;
149 }
150 
151 template <typename MaskPixelT>
153  fill_pixels(_getRawView(), rhs);
154 
155  return *this;
156 }
157 
158 #ifndef DOXYGEN // doc for this section is already in header
159 
160 template <typename MaskPixelT>
162  lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool allowUnsafe)
163  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
164  MaskFitsReader reader(fileName, hdu);
165  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
166  if (metadata) {
167  metadata->combine(reader.readMetadata());
168  }
169 }
170 
171 template <typename MaskPixelT>
172 Mask<MaskPixelT>::Mask(fits::MemFileManager& manager, int hdu,
174  ImageOrigin origin, bool conformMasks, bool allowUnsafe)
175  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
176  MaskFitsReader reader(manager, hdu);
177  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
178  if (metadata) {
179  metadata->combine(reader.readMetadata());
180  }
181 }
182 
183 template <typename MaskPixelT>
185  lsst::geom::Box2I const& bbox, ImageOrigin const origin, bool const conformMasks,
186  bool allowUnsafe)
187  : ImageBase<MaskPixelT>(), _maskDict(detail::MaskDict::getDefault()) {
188  MaskFitsReader reader(&fitsFile);
189  *this = reader.read<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
190  if (metadata) {
191  metadata->combine(reader.readMetadata());
192  }
193 }
194 
195 template <typename MaskPixelT>
196 void Mask<MaskPixelT>::writeFits(std::string const& fileName,
198  std::string const& mode) const {
199  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
200  writeFits(fitsfile, metadata_i);
201 }
202 
203 template <typename MaskPixelT>
204 void Mask<MaskPixelT>::writeFits(fits::MemFileManager& manager,
206  std::string const& mode) const {
207  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
208  writeFits(fitsfile, metadata_i);
209 }
210 
211 template <typename MaskPixelT>
212 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile,
214  writeFits(fitsfile, fits::ImageWriteOptions(*this), metadata);
215 }
216 
217 template <typename MaskPixelT>
218 void Mask<MaskPixelT>::writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
219  std::string const& mode,
221  fits::Fits fitsfile(filename, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
222  writeFits(fitsfile, options, header);
223 }
224 
225 template <typename MaskPixelT>
226 void Mask<MaskPixelT>::writeFits(fits::MemFileManager& manager, fits::ImageWriteOptions const& options,
227  std::string const& mode,
229  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
230  writeFits(fitsfile, options, header);
231 }
232 
233 template <typename MaskPixelT>
234 void Mask<MaskPixelT>::writeFits(fits::Fits& fitsfile, fits::ImageWriteOptions const& options,
237  header ? header->deepCopy() : std::make_shared<dafBase::PropertySet>();
238  addMaskPlanesToMetadata(useHeader);
239  fitsfile.writeImage(*this, options, useHeader);
240 }
241 
242 #endif // !DOXYGEN
243 
244 template <typename MaskPixelT>
246  std::string result = "";
247  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
248  for (auto const &iter : mpd) {
249  if (value & getBitMask(iter.second)) {
250  if (result.size() > 0) {
251  result += ",";
252  }
253  result += iter.first;
254  }
255  }
256  return result;
257 }
258 
259 template <typename MaskPixelT>
261  int id = getMaskPlaneNoThrow(name); // see if the plane is already available
262 
263  if (id < 0) { // doesn't exist
264  id = _maskPlaneDict()->getUnusedPlane();
265  }
266 
267  // build new entry, adding the plane to all Masks where this is no contradiction
268 
269  if (id >= getNumPlanesMax()) { // Max number of planes is already allocated
271  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
272  }
273 
275 
276  return id;
277 }
278 
279 template <typename MaskPixelT>
281  if (planeId < 0 || planeId >= getNumPlanesMax()) {
282  throw LSST_EXCEPT(
284  str(boost::format("mask plane ID must be between 0 and %1%") % (getNumPlanesMax() - 1)));
285  }
286 
287  _maskPlaneDict()->add(name, planeId);
288 
289  return planeId;
290 }
291 
292 template <typename MaskPixelT>
294  return _maskDict->getMaskPlaneDict();
295 }
296 
297 template <typename MaskPixelT>
299  if (detail::MaskDict::getDefault()->getMaskPlane(name) < 0) {
301  str(boost::format("Plane %s doesn't exist in the default Mask") % name));
302  }
303 
304  detail::MaskDict::detachDefault(); // leave current Masks alone
305  _maskPlaneDict()->erase(name);
306 }
307 
308 template <typename MaskPixelT>
309 void Mask<MaskPixelT>::removeAndClearMaskPlane(const std::string& name, bool const removeFromDefault
310 
311 ) {
312  clearMaskPlane(getMaskPlane(name)); // clear this bits in this Mask
313 
314  if (_maskDict == detail::MaskDict::getDefault() && removeFromDefault) { // we are the default
315  ;
316  } else {
317  _maskDict = _maskDict->clone();
318  }
319 
320  _maskDict->erase(name);
321 
322  if (removeFromDefault && detail::MaskDict::getDefault()->getMaskPlane(name) >= 0) {
323  removeMaskPlane(name);
324  }
325 }
326 
327 template <typename MaskPixelT>
328 MaskPixelT Mask<MaskPixelT>::getBitMaskNoThrow(int planeId) {
329  return (planeId >= 0 && planeId < getNumPlanesMax()) ? (1 << planeId) : 0;
330 }
331 
332 template <typename MaskPixelT>
333 MaskPixelT Mask<MaskPixelT>::getBitMask(int planeId) {
334  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
335 
336  for (auto const &i : mpd) {
337  if (planeId == i.second) {
338  MaskPixelT const bitmask = getBitMaskNoThrow(planeId);
339  if (bitmask == 0) { // failed
340  break;
341  }
342  return bitmask;
343  }
344  }
346  str(boost::format("Invalid mask plane ID: %d") % planeId));
347 }
348 
349 template <typename MaskPixelT>
351  int const plane = getMaskPlaneNoThrow(name);
352 
353  if (plane < 0) {
355  str(boost::format("Invalid mask plane name: %s") % name));
356  } else {
357  return plane;
358  }
359 }
360 
361 template <typename MaskPixelT>
363  return _maskPlaneDict()->getMaskPlane(name);
364 }
365 
366 template <typename MaskPixelT>
368  return getBitMask(getMaskPlane(name));
369 }
370 
371 template <typename MaskPixelT>
373  MaskPixelT mpix = 0x0;
374  for (auto const &it : name) {
375  mpix |= getBitMask(getMaskPlane(it));
376  }
377  return mpix;
378 }
379 
380 template <typename MaskPixelT>
382  return _maskPlaneDict()->size();
383 }
384 
385 template <typename MaskPixelT>
387  _maskPlaneDict()->clear();
388 }
389 
390 template <typename MaskPixelT>
392  *this = 0;
393 }
394 
395 template <typename MaskPixelT>
397  *this &= ~getBitMask(planeId);
398 }
399 
400 template <typename MaskPixelT>
401 void Mask<MaskPixelT>::conformMaskPlanes(MaskPlaneDict const& currentPlaneDict) {
403 
404  if (*_maskDict == *currentMD) {
405  if (*detail::MaskDict::getDefault() == *_maskDict) {
406  return; // nothing to do
407  }
408  } else {
409  //
410  // Find out which planes need to be permuted
411  //
412  MaskPixelT keepBitmask = 0; // mask of bits to keep
413  MaskPixelT canonicalMask[sizeof(MaskPixelT) * 8]; // bits in lsst::afw::image::Mask that should be
414  MaskPixelT currentMask[sizeof(MaskPixelT) * 8]; // mapped to these bits
415  int numReMap = 0;
416 
417  for (auto const &i : currentPlaneDict) {
418  std::string const name = i.first; // name of mask plane
419  int const currentPlaneNumber = i.second; // plane number currently in use
420  int canonicalPlaneNumber = getMaskPlaneNoThrow(name); // plane number in lsst::afw::image::Mask
421 
422  if (canonicalPlaneNumber < 0) { // no such plane; add it
423  canonicalPlaneNumber = addMaskPlane(name);
424  }
425 
426  if (canonicalPlaneNumber == currentPlaneNumber) {
427  keepBitmask |= getBitMask(canonicalPlaneNumber); // bit is unchanged, so preserve it
428  } else {
429  canonicalMask[numReMap] = getBitMask(canonicalPlaneNumber);
430  currentMask[numReMap] = getBitMaskNoThrow(currentPlaneNumber);
431  numReMap++;
432  }
433  }
434 
435  // Now loop over all pixels in Mask
436  if (numReMap > 0) {
437  for (int r = 0; r != this->getHeight(); ++r) { // "this->": Meyers, Effective C++, Item 43
438  for (typename Mask::x_iterator ptr = this->row_begin(r), end = this->row_end(r); ptr != end;
439  ++ptr) {
440  MaskPixelT const pixel = *ptr;
441 
442  MaskPixelT newPixel = pixel & keepBitmask; // value of invariant mask bits
443  for (int i = 0; i < numReMap; i++) {
444  if (pixel & currentMask[i]) newPixel |= canonicalMask[i];
445  }
446 
447  *ptr = newPixel;
448  }
449  }
450  }
451  }
452  // We've made the planes match the current mask dictionary
453  _maskDict = detail::MaskDict::getDefault();
454 }
455 
456 template <typename MaskPixelT>
458  return this->ImageBase<MaskPixelT>::operator()(x, y);
459 }
460 
461 template <typename MaskPixelT>
463  CheckIndices const& check) {
464  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
465 }
466 
467 template <typename MaskPixelT>
469  return this->ImageBase<MaskPixelT>::operator()(x, y);
470 }
471 
472 template <typename MaskPixelT>
474  int x, int y, CheckIndices const& check) const {
475  return this->ImageBase<MaskPixelT>::operator()(x, y, check);
476 }
477 
478 template <typename MaskPixelT>
479 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId) const {
480  // !! converts an int to a bool
481  return !!(this->ImageBase<MaskPixelT>::operator()(x, y) & getBitMask(planeId));
482 }
483 
484 template <typename MaskPixelT>
485 bool Mask<MaskPixelT>::operator()(int x, int y, int planeId, CheckIndices const& check) const {
486  // !! converts an int to a bool
487  return !!(this->ImageBase<MaskPixelT>::operator()(x, y, check) & getBitMask(planeId));
488 }
489 
490 template <typename MaskPixelT>
492  if (*_maskDict != *other._maskDict) {
493  throw LSST_EXCEPT(pexExcept::RuntimeError, "Mask dictionaries do not match");
494  }
495 }
496 
497 template <typename MaskPixelT>
499  transform_pixels(_getRawView(), _getRawView(),
500  [&val](MaskPixelT const& l) -> MaskPixelT { return l | val; });
501  return *this;
502 }
503 
504 template <typename MaskPixelT>
506  checkMaskDictionaries(rhs);
507 
508  if (this->getDimensions() != rhs.getDimensions()) {
510  str(boost::format("Images are of different size, %dx%d v %dx%d") %
511  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
512  }
513  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
514  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l | r; });
515  return *this;
516 }
517 
518 template <typename MaskPixelT>
520  transform_pixels(_getRawView(), _getRawView(), [&val](MaskPixelT const& l) { return l & val; });
521  return *this;
522 }
523 
524 template <typename MaskPixelT>
526  checkMaskDictionaries(rhs);
527 
528  if (this->getDimensions() != rhs.getDimensions()) {
530  str(boost::format("Images are of different size, %dx%d v %dx%d") %
531  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
532  }
533  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
534  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l & r; });
535  return *this;
536 }
537 
538 template <typename MaskPixelT>
540  transform_pixels(_getRawView(), _getRawView(),
541  [&val](MaskPixelT const& l) -> MaskPixelT { return l ^ val; });
542  return *this;
543 }
544 
545 template <typename MaskPixelT>
547  checkMaskDictionaries(rhs);
548 
549  if (this->getDimensions() != rhs.getDimensions()) {
551  str(boost::format("Images are of different size, %dx%d v %dx%d") %
552  this->getWidth() % this->getHeight() % rhs.getWidth() % rhs.getHeight()));
553  }
554  transform_pixels(_getRawView(), rhs._getRawView(), _getRawView(),
555  [](MaskPixelT const& l, MaskPixelT const& r) -> MaskPixelT { return l ^ r; });
556  return *this;
557 }
558 
559 template <typename MaskPixelT>
560 void Mask<MaskPixelT>::setMaskPlaneValues(int const planeId, int const x0, int const x1, int const y) {
561  MaskPixelT const bitMask = getBitMask(planeId);
562 
563  for (int x = x0; x <= x1; x++) {
564  operator()(x, y) = operator()(x, y) | bitMask;
565  }
566 }
567 
568 template <typename MaskPixelT>
570  if (!metadata) {
571  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "Null std::shared_ptr<PropertySet>");
572  }
573 
574  // First, clear existing MaskPlane metadata
575  using NameList = std::vector<std::string>;
576  NameList paramNames = metadata->paramNames(false);
577  for (auto const &paramName : paramNames) {
578  if (paramName.compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
579  metadata->remove(paramName);
580  }
581  }
582 
583  MaskPlaneDict const& mpd = _maskPlaneDict()->getMaskPlaneDict();
584 
585  // Add new MaskPlane metadata
586  for (auto const &i : mpd) {
587  std::string const& planeName = i.first;
588  int const planeNumber = i.second;
589 
590  if (planeName != "") {
591  metadata->add(maskPlanePrefix + planeName, planeNumber);
592  }
593  }
594 }
595 
596 template <typename MaskPixelT>
599  MaskPlaneDict newDict;
600 
601  // First, clear existing MaskPlane metadata
602  using NameList = std::vector<std::string>;
603  NameList paramNames = metadata->paramNames(false);
604  int numPlanesUsed = 0; // number of planes used
605 
606  // Iterate over childless properties with names starting with maskPlanePrefix
607  for (auto const &paramName : paramNames) {
608  if (paramName.compare(0, maskPlanePrefix.size(), maskPlanePrefix) == 0) {
609  // split off maskPlanePrefix to obtain plane name
610  std::string planeName = paramName.substr(maskPlanePrefix.size());
611  int const planeId = metadata->getAsInt(paramName);
612 
613  MaskPlaneDict::const_iterator plane = newDict.find(planeName);
614  if (plane != newDict.end() && planeId != plane->second) {
615  throw LSST_EXCEPT(pexExcept::RuntimeError, "File specifies plane " + planeName + " twice");
616  }
617  for (MaskPlaneDict::const_iterator j = newDict.begin(); j != newDict.end(); ++j) {
618  if (planeId == j->second) {
620  str(boost::format("File specifies plane %s has same value (%d) as %s") %
621  planeName % planeId % j->first));
622  }
623  }
624  // build new entry
625  if (numPlanesUsed >= getNumPlanesMax()) {
626  // Max number of planes already allocated
627  throw LSST_EXCEPT(
629  str(boost::format("Max number of planes (%1%) already used") % getNumPlanesMax()));
630  }
631  newDict[planeName] = planeId;
632  }
633  }
634  return newDict;
635 }
636 
637 template <typename MaskPixelT>
639  _maskDict->print();
640 }
641 
642 /*
643  * Static members of Mask
644  */
645 template <typename MaskPixelT>
647 
648 template <typename MaskPixelT>
651 }
652 
653 //
654 // Explicit instantiations
655 //
656 template class Mask<MaskPixel>;
657 } // namespace image
658 } // namespace afw
659 } // namespace lsst
py::object result
Definition: _schema.cc:429
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:48
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:515
uint64_t * ptr
Definition: RangeSet.cc:88
int y
Definition: SpanSet.cc:48
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
typename 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:172
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
typename _view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: ImageBase.h:133
_view_t _getRawView() const
Definition: ImageBase.h:465
void swap(ImageBase &rhs)
Definition: Image.cc:234
typename ConstReference< PixelT >::type PixelConstReference
A ConstReference to a PixelT.
Definition: ImageBase.h:119
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:126
Mask & operator=(MaskPixelT const rhs)
Definition: Mask.cc:152
friend class MaskFitsReader
Definition: Mask.h:521
void printMaskPlanes() const
print the mask plane dictionary to std::cout
Definition: Mask.cc:638
static int getMaskPlane(const std::string &name)
Return the mask plane number corresponding to a plane name.
Definition: Mask.cc:350
static std::string interpret(MaskPixelT value)
Interpret a mask value as a comma-separated list of mask plane names.
Definition: Mask.cc:245
static void removeMaskPlane(const std::string &name)
Definition: Mask.cc:298
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:309
static void clearMaskPlaneDict()
Reset the maskPlane dictionary.
Definition: Mask.cc:386
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:560
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:569
ImageBase< MaskPixelT >::PixelReference operator()(int x, int y)
get a reference to the specified pixel
Definition: Mask.cc:457
Mask & operator^=(Mask const &rhs)
XOR a Mask into a Mask.
Definition: Mask.cc:546
static int addMaskPlane(const std::string &name)
Definition: Mask.cc:260
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:372
Mask(unsigned int width, unsigned int height, MaskPlaneDict const &planeDefs=MaskPlaneDict())
Construct a Mask initialized to 0x0.
Definition: Mask.cc:62
MaskPlaneDict const & getMaskPlaneDict() const
Return the Mask's maskPlaneDict.
Definition: Mask.cc:293
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:401
Mask & operator|=(Mask const &rhs)
OR a Mask into a Mask.
Definition: Mask.cc:505
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:597
void clearAllMaskPlanes()
Clear all the pixels.
Definition: Mask.cc:391
static int getNumPlanesUsed()
Definition: Mask.cc:381
void clearMaskPlane(int plane)
Clear the specified bit in all pixels.
Definition: Mask.cc:396
Mask & operator&=(Mask const &rhs)
AND a Mask into a Mask.
Definition: Mask.cc:525
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:444
Extent< int, 2 > ExtentI
Definition: Extent.h:396
def writeFits(filename, stamps, metadata, type_name, write_mask, write_variance, write_archive=False)
Definition: stamps.py:42
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)