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
ExposureInfo.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*- // fixed format comment for emacs
2 /*
3  * This file is part of afw.
4  *
5  * Developed for the LSST Data Management System.
6  * This product includes software developed by the LSST Project
7  * (https://www.lsst.org).
8  * See the COPYRIGHT file at the top-level directory of this distribution
9  * for details of code ownership.
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
26 #define LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
27 
28 #include "lsst/base.h"
29 #include "lsst/daf/base.h"
30 #include "lsst/geom/Point.h"
31 #include "lsst/afw/image/Filter.h"
37 
38 namespace lsst {
39 namespace afw {
40 
41 namespace cameraGeom {
42 class Detector;
43 }
44 
45 namespace detection {
46 class Psf;
47 }
48 
49 namespace geom {
50 namespace polygon {
51 class Polygon;
52 class SkyWcs;
53 } // namespace polygon
54 } // namespace geom
55 
56 namespace fits {
57 class Fits;
58 }
59 
60 namespace image {
61 
62 class PhotoCalib;
63 class ApCorrMap;
64 class VisitInfo;
65 class TransmissionCurve;
66 
87 public:
108 
110  bool hasWcs() const;
111 
114 
117 
119  bool hasDetector() const;
120 
123 
126 
128  // TODO: remove in DM-27177
129  [[deprecated("Replaced with getFilterLabel. Will be removed after v22.")]] Filter getFilter() const;
130 
137  // TODO: remove in DM-27177
138  [[deprecated("Replaced with setFilterLabel. Will be removed after v22.")]] void setFilter(
139  Filter const& filter);
140 
142  // TODO: deprecate in DM-27177, remove in DM-27811.
143  bool hasFilterLabel() const;
144 
146  // TODO: deprecate in DM-27177, remove in DM-27811.
148 
150  // TODO: deprecate in DM-27177, remove in DM-27811.
152 
154  bool hasPhotoCalib() const;
155 
158 
161 
164 
166  void setMetadata(std::shared_ptr<daf::base::PropertySet> metadata) { _metadata = metadata; }
167 
169  bool hasPsf() const;
170 
173 
176 
178  bool hasValidPolygon() const;
179 
182 
185 
187  bool hasApCorrMap() const;
188 
191 
194 
201  void initApCorrMap();
202 
204  bool hasCoaddInputs() const;
205 
208 
211 
214 
216  bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
217 
220 
222  bool hasTransmissionCurve() const;
223 
226 
229 
254  template <class T>
256  std::shared_ptr<T> const& object) {
257  static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
258  // "No data" always represented internally by absent key-value pair, not by mapping to null
259  if (object != nullptr) {
260  _setComponent(key, object);
261  } else {
262  removeComponent(key);
263  }
264  }
265 
274  template <class T>
276  return _components->contains(key);
277  }
278 
288  template <class T>
290  try {
291  return _components->at(key);
292  } catch (pex::exceptions::OutOfRangeError const& e) {
293  return nullptr;
294  }
295  }
296 
306  template <class T>
308  return _components->erase(key);
309  }
310 
312  static int getFitsSerializationVersion();
313 
316 
324  explicit ExposureInfo(
332  Filter const& filter = Filter(),
341 
343  ExposureInfo(ExposureInfo const& other);
344  ExposureInfo(ExposureInfo&& other);
345 
347  ExposureInfo(ExposureInfo const& other, bool copyMetadata);
348 
350  ExposureInfo& operator=(ExposureInfo const& other);
352 
353  // Destructor defined in source file because we need access to destructors of forward-declared components
355 
356 private:
357  template <typename ImageT, typename MaskT, typename VarianceT>
358  friend class Exposure;
359 
373  struct FitsWriteData {
378  table::io::OutputArchive archive;
379  };
380 
397  static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
398  std::string comment);
399 
400  static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
401  std::string key, std::string comment);
402 
413  FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
414 
428  void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
429 
431 
432  // Implementation of setComponent
433  template <class T>
434  void _setComponent(typehandling::Key<std::string, std::shared_ptr<T>> const& key,
435  std::shared_ptr<T> const& object) {
436  if (_components->contains(key)) {
437  _components->erase(key);
438  } else if (_components->contains(key.getId())) {
439  std::stringstream buffer;
440  buffer << "Map has a key that conflicts with " << key;
441  throw LSST_EXCEPT(pex::exceptions::TypeError, buffer.str());
442  }
443  try {
444  bool success = _components->insert(key, object);
445  if (!success) {
446  throw LSST_EXCEPT(
448  "Insertion failed for unknown reasons. There may be something in the logs.");
449  }
450  } catch (std::exception const& e) {
452  LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
453  }
454  }
455 
458 
459  // Class invariant: all pointers in _components are not null
461 };
462 } // namespace image
463 } // namespace afw
464 } // namespace lsst
465 
466 #endif // !LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
char * data
Definition: BaseRecord.cc:61
table::Key< int > detector
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Fits * fits
Definition: FitsWriter.cc:90
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:66
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition: Exposure.h:72
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:86
bool hasWcs() const
Does this exposure have a Wcs?
Definition: ExposureInfo.cc:54
std::shared_ptr< ApCorrMap const > getApCorrMap() const
Return the exposure's aperture correction map (null pointer if !hasApCorrMap())
static int getFitsSerializationVersion()
Get the version of FITS serialization that this ExposureInfo understands.
std::shared_ptr< geom::polygon::Polygon const > getValidPolygon() const
Return the valid Polygon.
Definition: ExposureInfo.cc:92
bool hasCoaddInputs() const
Does this exposure have coadd provenance catalogs?
std::shared_ptr< CoaddInputs const > getCoaddInputs() const
Return a pair of catalogs that record the inputs, if this Exposure is a coadd (otherwise null).
void setFilterLabel(std::shared_ptr< FilterLabel const > filterLabel)
Set the exposure's filter information.
std::shared_ptr< daf::base::PropertySet > getMetadata() const
Return flexible metadata.
Definition: ExposureInfo.h:163
static typehandling::Key< std::string, std::shared_ptr< geom::SkyWcs const > > const KEY_WCS
Standard key for looking up the Wcs.
Definition: ExposureInfo.h:89
ExposureInfo & operator=(ExposureInfo const &other)
Assignment; shares all components.
void setFilter(Filter const &filter)
Set the exposure's filter.
static typehandling::Key< std::string, std::shared_ptr< cameraGeom::Detector const > > const KEY_DETECTOR
Standard key for looking up the detector information.
Definition: ExposureInfo.h:95
bool hasTransmissionCurve() const
Does this exposure have a transmission curve?
std::shared_ptr< detection::Psf const > getPsf() const
Return the exposure's point-spread function.
Definition: ExposureInfo.cc:62
bool hasPsf() const
Does this exposure have a Psf?
Definition: ExposureInfo.cc:61
void setVisitInfo(std::shared_ptr< image::VisitInfo const > const visitInfo)
Set the exposure's visit info.
Definition: ExposureInfo.h:219
ExposureInfo(std::shared_ptr< geom::SkyWcs const > const &wcs=std::shared_ptr< geom::SkyWcs const >(), std::shared_ptr< detection::Psf const > const &psf=std::shared_ptr< detection::Psf const >(), std::shared_ptr< PhotoCalib const > const &photoCalib=std::shared_ptr< PhotoCalib const >(), std::shared_ptr< cameraGeom::Detector const > const &detector=std::shared_ptr< cameraGeom::Detector const >(), std::shared_ptr< geom::polygon::Polygon const > const &polygon=std::shared_ptr< geom::polygon::Polygon const >(), Filter const &filter=Filter(), std::shared_ptr< daf::base::PropertySet > const &metadata=std::shared_ptr< daf::base::PropertySet >(), std::shared_ptr< CoaddInputs > const &coaddInputs=std::shared_ptr< CoaddInputs >(), std::shared_ptr< ApCorrMap > const &apCorrMap=std::shared_ptr< ApCorrMap >(), std::shared_ptr< image::VisitInfo const > const &visitInfo=std::shared_ptr< image::VisitInfo const >(), std::shared_ptr< TransmissionCurve const > const &transmissionCurve=std::shared_ptr< TransmissionCurve >())
Construct an ExposureInfo from its various components.
void setValidPolygon(std::shared_ptr< geom::polygon::Polygon const > polygon)
Set the exposure's valid Polygon.
Definition: ExposureInfo.cc:95
bool hasPhotoCalib() const
Does this exposure have a photometric calibration?
Definition: ExposureInfo.cc:68
bool hasApCorrMap() const
Return true if the exposure has an aperture correction map.
void setWcs(std::shared_ptr< geom::SkyWcs const > wcs)
Set the WCS of the exposure.
Definition: ExposureInfo.cc:56
bool hasComponent(typehandling::Key< std::string, T > const &key) const
Test whether a generic component is defined.
Definition: ExposureInfo.h:275
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure's visit info.
Definition: ExposureInfo.h:213
void setApCorrMap(std::shared_ptr< ApCorrMap const > apCorrMap)
Set the exposure's aperture correction map (null pointer if !hasApCorrMap())
void setComponent(typehandling::Key< std::string, std::shared_ptr< T >> const &key, std::shared_ptr< T > const &object)
Add a generic component to the ExposureInfo.
Definition: ExposureInfo.h:255
std::shared_ptr< cameraGeom::Detector const > getDetector() const
Return the exposure's Detector information.
Definition: ExposureInfo.cc:80
void setPhotoCalib(std::shared_ptr< PhotoCalib const > photoCalib)
Set the Exposure's PhotoCalib object.
Definition: ExposureInfo.cc:72
Filter getFilter() const
Return the exposure's filter.
static typehandling::Key< std::string, std::shared_ptr< geom::polygon::Polygon const > > const KEY_VALID_POLYGON
Standard key for looking up the valid polygon.
Definition: ExposureInfo.h:98
bool hasValidPolygon() const
Does this exposure have a valid Polygon.
Definition: ExposureInfo.cc:91
std::shared_ptr< T > getComponent(typehandling::Key< std::string, std::shared_ptr< T >> const &key) const
Retrieve a generic component from the ExposureInfo.
Definition: ExposureInfo.h:289
static typehandling::Key< std::string, std::shared_ptr< PhotoCalib const > > const KEY_PHOTO_CALIB
Standard key for looking up the photometric calibration.
Definition: ExposureInfo.h:93
void setCoaddInputs(std::shared_ptr< CoaddInputs const > coaddInputs)
Set the exposure's coadd provenance catalogs.
std::shared_ptr< FilterLabel const > getFilterLabel() const
Return the exposure's filter information.
bool hasFilterLabel() const
Does this exposure have filter information?
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
Definition: ExposureInfo.h:166
void setDetector(std::shared_ptr< cameraGeom::Detector const > detector)
Set the exposure's Detector information.
Definition: ExposureInfo.cc:83
std::shared_ptr< TransmissionCurve const > getTransmissionCurve() const
Return the exposure's transmission curve.
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:216
void setPsf(std::shared_ptr< detection::Psf const > psf)
Set the exposure's point-spread function.
Definition: ExposureInfo.cc:63
static typehandling::Key< std::string, std::shared_ptr< TransmissionCurve const > > const KEY_TRANSMISSION_CURVE
Standard key for looking up the transmission curve.
Definition: ExposureInfo.h:105
void initApCorrMap()
Set the exposure's aperture correction map to a new, empty map.
static typehandling::Key< std::string, std::shared_ptr< CoaddInputs const > > const KEY_COADD_INPUTS
Standard key for looking up coadd provenance catalogs.
Definition: ExposureInfo.h:100
static typehandling::Key< std::string, std::shared_ptr< detection::Psf const > > const KEY_PSF
Standard key for looking up the point-spread function.
Definition: ExposureInfo.h:91
std::shared_ptr< geom::SkyWcs const > getWcs() const
Return the WCS of the exposure.
Definition: ExposureInfo.cc:55
bool hasDetector() const
Does this exposure have Detector information?
Definition: ExposureInfo.cc:79
static typehandling::Key< std::string, std::shared_ptr< ApCorrMap const > > const KEY_AP_CORR_MAP
Standard key for looking up the aperture correction map.
Definition: ExposureInfo.h:102
std::shared_ptr< PhotoCalib const > getPhotoCalib() const
Return the exposure's photometric calibration.
Definition: ExposureInfo.cc:69
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
Definition: ExposureInfo.h:107
void setTransmissionCurve(std::shared_ptr< TransmissionCurve const > tc)
Set the exposure's transmission curve.
bool removeComponent(typehandling::Key< std::string, T > const &key)
Clear a generic component from the ExposureInfo.
Definition: ExposureInfo.h:307
A multi-catalog archive object used to save table::io::Persistable objects.
Definition: OutputArchive.h:34
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
Key for type-safe lookup in a GenericMap.
Definition: Key.h:52
Reports attempts to access elements outside a valid range of indices.
Definition: Runtime.h:89
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
Reports errors from accepting an object of an unexpected or inappropriate type.
Definition: Runtime.h:167
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
class[[deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be " "removed after v22.")]] FilterProperty final
Describe the properties of a Filter (e.g.
Definition: Filter.h:53
A base class for image defects.
T str(T... args)
Key< int > psf
Definition: Exposure.cc:65
Key< int > visitInfo
Definition: Exposure.cc:70
Key< int > photoCalib
Definition: Exposure.cc:67
Key< int > transmissionCurve
Definition: Exposure.cc:71
Key< int > apCorrMap
Definition: Exposure.cc:68
T throw_with_nested(T... args)