lsst.afw  21.0.0-11-ga6ea59e8e+47cba9fc36
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 
86 class ExposureInfo final {
87 public:
108 
110  bool hasWcs() const;
111 
114 
117 
119  bool hasDetector() const;
120 
123 
126 
128  // TODO: deprecate in DM-27170, remove in DM-27177
129  Filter getFilter() const;
130 
137  // TODO: deprecate in DM-27170, remove in DM-27177
138  void setFilter(Filter const& filter);
139 
141  // TODO: deprecate in DM-27177, remove in DM-27811.
142  bool hasFilterLabel() const;
143 
145  // TODO: deprecate in DM-27177, remove in DM-27811.
147 
149  // TODO: deprecate in DM-27177, remove in DM-27811.
151 
153  bool hasPhotoCalib() const;
154 
157 
160 
163 
165  void setMetadata(std::shared_ptr<daf::base::PropertySet> metadata) { _metadata = metadata; }
166 
168  bool hasPsf() const;
169 
172 
175 
177  bool hasValidPolygon() const;
178 
181 
184 
186  bool hasApCorrMap() const;
187 
190 
193 
200  void initApCorrMap();
201 
203  bool hasCoaddInputs() const;
204 
207 
210 
213 
215  bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
216 
219 
221  bool hasTransmissionCurve() const;
222 
225 
228 
253  template <class T>
255  std::shared_ptr<T> const& object) {
256  static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
257  // "No data" always represented internally by absent key-value pair, not by mapping to null
258  if (object != nullptr) {
259  _setComponent(key, object);
260  } else {
262  }
263  }
264 
273  template <class T>
275  return _components->contains(key);
276  }
277 
287  template <class T>
289  try {
290  return _components->at(key);
291  } catch (pex::exceptions::OutOfRangeError const& e) {
292  return nullptr;
293  }
294  }
295 
305  template <class T>
307  return _components->erase(key);
308  }
309 
311  static int getFitsSerializationVersion();
312 
315 
323  explicit ExposureInfo(
331  Filter const& filter = Filter(),
340 
344 
346  ExposureInfo(ExposureInfo const& other, bool copyMetadata);
347 
351 
352  // Destructor defined in source file because we need access to destructors of forward-declared components
354 
355 private:
356  template <typename ImageT, typename MaskT, typename VarianceT>
357  friend class Exposure;
358 
372  struct FitsWriteData {
377  table::io::OutputArchive archive;
378  };
379 
396  static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
397  std::string comment);
398 
399  static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
400  std::string key, std::string comment);
401 
412  FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
413 
427  void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
428 
430 
431  // Implementation of setComponent
432  template <class T>
433  void _setComponent(typehandling::Key<std::string, std::shared_ptr<T>> const& key,
434  std::shared_ptr<T> const& object) {
435  if (_components->contains(key)) {
436  _components->erase(key);
437  } else if (_components->contains(key.getId())) {
438  std::stringstream buffer;
439  buffer << "Map has a key that conflicts with " << key;
440  throw LSST_EXCEPT(pex::exceptions::TypeError, buffer.str());
441  }
442  try {
443  bool success = _components->insert(key, object);
444  if (!success) {
445  throw LSST_EXCEPT(
447  "Insertion failed for unknown reasons. There may be something in the logs.");
448  }
449  } catch (std::exception const& e) {
451  LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
452  }
453  }
454 
457 
458  // Class invariant: all pointers in _components are not null
460 };
461 } // namespace image
462 } // namespace afw
463 } // namespace lsst
464 
465 #endif // !LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
CoaddInputs.h
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
lsst::afw::image::ExposureInfo::setVisitInfo
void setVisitInfo(std::shared_ptr< image::VisitInfo const > const visitInfo)
Set the exposure's visit info.
Definition: ExposureInfo.h:218
lsst::afw::image::ExposureInfo::hasVisitInfo
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:215
lsst::afw::image::ExposureInfo::setWcs
void setWcs(std::shared_ptr< geom::SkyWcs const > wcs)
Set the WCS of the exposure.
Definition: ExposureInfo.cc:56
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::image::ExposureInfo::hasValidPolygon
bool hasValidPolygon() const
Does this exposure have a valid Polygon.
Definition: ExposureInfo.cc:91
lsst::afw::image::ExposureInfo::KEY_TRANSMISSION_CURVE
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
std::exception
STL class.
lsst::afw::image::Exposure
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition: Exposure.h:72
wcs
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
lsst::afw::image::ExposureInfo::setTransmissionCurve
void setTransmissionCurve(std::shared_ptr< TransmissionCurve const > tc)
Set the exposure's transmission curve.
Definition: ExposureInfo.cc:127
lsst::afw::fits::Fits
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
transmissionCurve
Key< int > transmissionCurve
Definition: Exposure.cc:71
lsst::afw::image::ExposureInfo::getApCorrMap
std::shared_ptr< ApCorrMap const > getApCorrMap() const
Return the exposure's aperture correction map (null pointer if !hasApCorrMap())
Definition: ExposureInfo.cc:114
lsst::afw::image::ExposureInfo::KEY_COADD_INPUTS
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
lsst::afw::image::Filter
Holds an integer identifier for an LSST filter.
Definition: Filter.h:141
psf
Key< int > psf
Definition: Exposure.cc:65
lsst::afw::image::ExposureInfo::getPhotoCalib
std::shared_ptr< PhotoCalib const > getPhotoCalib() const
Return the exposure's photometric calibration.
Definition: ExposureInfo.cc:69
lsst::afw::image::ExposureInfo::getMetadata
std::shared_ptr< daf::base::PropertySet > getMetadata() const
Return flexible metadata.
Definition: ExposureInfo.h:162
lsst::afw::image::ExposureInfo::hasPsf
bool hasPsf() const
Does this exposure have a Psf?
Definition: ExposureInfo.cc:61
std::stringstream
STL class.
lsst::afw::image::ExposureInfo::getPsf
std::shared_ptr< detection::Psf const > getPsf() const
Return the exposure's point-spread function.
Definition: ExposureInfo.cc:62
lsst::afw::image::ExposureInfo::setComponent
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:254
lsst::afw::image::ExposureInfo::KEY_WCS
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
lsst::afw::image::ExposureInfo::getTransmissionCurve
std::shared_ptr< TransmissionCurve const > getTransmissionCurve() const
Return the exposure's transmission curve.
Definition: ExposureInfo.cc:124
lsst::afw::image::ExposureInfo::setFilter
void setFilter(Filter const &filter)
Set the exposure's filter.
Definition: ExposureInfo.cc:145
lsst::afw::image::ExposureInfo::hasDetector
bool hasDetector() const
Does this exposure have Detector information?
Definition: ExposureInfo.cc:79
Filter.h
lsst::afw::image::ExposureInfo::ExposureInfo
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.
Definition: ExposureInfo.cc:178
lsst::afw::image::ExposureInfo::getFilterLabel
std::shared_ptr< FilterLabel const > getFilterLabel() const
Return the exposure's filter information.
Definition: ExposureInfo.cc:150
base.h
lsst::afw::image::ExposureInfo::getWcs
std::shared_ptr< geom::SkyWcs const > getWcs() const
Return the WCS of the exposure.
Definition: ExposureInfo.cc:55
lsst::afw::image::ExposureInfo::getFitsSerializationVersion
static int getFitsSerializationVersion()
Get the version of FITS serialization that this ExposureInfo understands.
Definition: ExposureInfo.cc:155
lsst::afw::image::ExposureInfo::setCoaddInputs
void setCoaddInputs(std::shared_ptr< CoaddInputs const > coaddInputs)
Set the exposure's coadd provenance catalogs.
Definition: ExposureInfo.cc:103
lsst::afw::image::ExposureInfo::getFilter
Filter getFilter() const
Return the exposure's filter.
Definition: ExposureInfo.cc:135
fits
Fits * fits
Definition: FitsWriter.cc:90
lsst::afw::image::ExposureInfo::hasFilterLabel
bool hasFilterLabel() const
Does this exposure have filter information?
Definition: ExposureInfo.cc:149
data
char * data
Definition: BaseRecord.cc:62
lsst::afw::image::ExposureInfo::getDetector
std::shared_ptr< cameraGeom::Detector const > getDetector() const
Return the exposure's Detector information.
Definition: ExposureInfo.cc:80
lsst::afw::image::ExposureInfo::removeComponent
bool removeComponent(typehandling::Key< std::string, T > const &key)
Clear a generic component from the ExposureInfo.
Definition: ExposureInfo.h:306
lsst::afw::image::ExposureInfo::setPsf
void setPsf(std::shared_ptr< detection::Psf const > psf)
Set the exposure's point-spread function.
Definition: ExposureInfo.cc:63
lsst::afw::image::ExposureInfo
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:86
std::throw_with_nested
T throw_with_nested(T... args)
other
ItemVariant const * other
Definition: Schema.cc:56
Point.h
lsst::afw::image::ExposureInfo::getComponent
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:288
lsst::afw::image::ExposureInfo::getFitsSerializationVersionName
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
Definition: ExposureInfo.cc:164
lsst::afw::image::ExposureInfo::setFilterLabel
void setFilterLabel(std::shared_ptr< FilterLabel const > filterLabel)
Set the exposure's filter information.
Definition: ExposureInfo.cc:151
lsst::afw::image::ExposureInfo::initApCorrMap
void initApCorrMap()
Set the exposure's aperture correction map to a new, empty map.
Definition: ExposureInfo.cc:229
lsst::afw::table::io::OutputArchive
A multi-catalog archive object used to save table::io::Persistable objects.
Definition: OutputArchive.h:34
lsst::afw::image::ExposureInfo::KEY_VALID_POLYGON
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
lsst
A base class for image defects.
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
lsst::afw::image::ExposureInfo::KEY_DETECTOR
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
lsst::afw::typehandling::Key
Key for type-safe lookup in a GenericMap.
Definition: Key.h:52
lsst::afw::table::io::Persistable
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
photoCalib
Key< int > photoCalib
Definition: Exposure.cc:67
lsst::afw::image::ExposureInfo::KEY_PSF
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
lsst::afw::image::ExposureInfo::setMetadata
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
Definition: ExposureInfo.h:165
lsst::afw::image::ExposureInfo::hasTransmissionCurve
bool hasTransmissionCurve() const
Does this exposure have a transmission curve?
Definition: ExposureInfo.cc:123
lsst::afw::image::ExposureInfo::hasCoaddInputs
bool hasCoaddInputs() const
Does this exposure have coadd provenance catalogs?
Definition: ExposureInfo.cc:102
lsst::afw::image::ExposureInfo::hasPhotoCalib
bool hasPhotoCalib() const
Does this exposure have a photometric calibration?
Definition: ExposureInfo.cc:68
lsst::afw::image::ExposureInfo::KEY_FILTER
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
Definition: ExposureInfo.h:107
lsst::afw::image::ExposureInfo::hasComponent
bool hasComponent(typehandling::Key< std::string, T > const &key) const
Test whether a generic component is defined.
Definition: ExposureInfo.h:274
lsst::afw::image::ExposureInfo::setDetector
void setDetector(std::shared_ptr< cameraGeom::Detector const > detector)
Set the exposure's Detector information.
Definition: ExposureInfo.cc:83
StorableMap.h
detector
table::Key< int > detector
Definition: DetectorCollection.cc:172
key
Key< U > key
Definition: Schema.cc:281
lsst::afw::image::ExposureInfo::setValidPolygon
void setValidPolygon(std::shared_ptr< geom::polygon::Polygon const > polygon)
Set the exposure's valid Polygon.
Definition: ExposureInfo.cc:95
Point< int, 2 >
lsst::pex::exceptions::OutOfRangeError
lsst::afw::image::ExposureInfo::setPhotoCalib
void setPhotoCalib(std::shared_ptr< PhotoCalib const > photoCalib)
Set the Exposure's PhotoCalib object.
Definition: ExposureInfo.cc:72
lsst::afw::image::ExposureInfo::KEY_AP_CORR_MAP
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::stringstream::str
T str(T... args)
lsst::afw::image::ExposureInfo::KEY_PHOTO_CALIB
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
lsst::pex::exceptions::TypeError
lsst::afw::image::ExposureInfo::~ExposureInfo
~ExposureInfo()
lsst::afw::image::ExposureInfo::getCoaddInputs
std::shared_ptr< CoaddInputs const > getCoaddInputs() const
Return a pair of catalogs that record the inputs, if this Exposure is a coadd (otherwise null).
Definition: ExposureInfo.cc:106
std::unique_ptr
STL class.
lsst::afw::image::ExposureInfo::hasApCorrMap
bool hasApCorrMap() const
Return true if the exposure has an aperture correction map.
Definition: ExposureInfo.cc:113
lsst::afw::image::ExposureInfo::operator=
ExposureInfo & operator=(ExposureInfo const &other)
Assignment; shares all components.
Definition: ExposureInfo.cc:217
OutputArchive.h
visitInfo
Key< int > visitInfo
Definition: Exposure.cc:70
lsst::afw::image::ExposureInfo::setApCorrMap
void setApCorrMap(std::shared_ptr< ApCorrMap const > apCorrMap)
Set the exposure's aperture correction map (null pointer if !hasApCorrMap())
Definition: ExposureInfo.cc:115
lsst::afw::image::ExposureInfo::hasWcs
bool hasWcs() const
Does this exposure have a Wcs?
Definition: ExposureInfo.cc:54
lsst::pex::exceptions::RuntimeError
FilterLabel.h
lsst::afw::image::ExposureInfo::getValidPolygon
std::shared_ptr< geom::polygon::Polygon const > getValidPolygon() const
Return the valid Polygon.
Definition: ExposureInfo.cc:92
lsst::afw::image::ExposureInfo::getVisitInfo
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure's visit info.
Definition: ExposureInfo.h:212
std::is_base_of
apCorrMap
Key< int > apCorrMap
Definition: Exposure.cc:68
VisitInfo.h