LSSTApplications  20.0.0
LSSTDataManagementBasePackage
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"
36 
37 namespace lsst {
38 namespace afw {
39 
40 namespace cameraGeom {
41 class Detector;
42 }
43 
44 namespace detection {
45 class Psf;
46 }
47 
48 namespace geom {
49 namespace polygon {
50 class Polygon;
51 class SkyWcs;
52 } // namespace polygon
53 } // namespace geom
54 
55 namespace fits {
56 class Fits;
57 }
58 
59 namespace image {
60 
61 class PhotoCalib;
62 class ApCorrMap;
63 class VisitInfo;
64 class TransmissionCurve;
65 
86 class ExposureInfo final {
87 public:
106 
108  bool hasWcs() const;
109 
112 
115 
117  bool hasDetector() const;
118 
121 
124 
126  Filter getFilter() const { return _filter; }
127 
129  void setFilter(Filter const& filter) { _filter = filter; }
130 
132  bool hasPhotoCalib() const;
133 
136 
139 
142 
144  void setMetadata(std::shared_ptr<daf::base::PropertySet> metadata) { _metadata = metadata; }
145 
147  bool hasPsf() const;
148 
151 
154 
156  bool hasValidPolygon() const;
157 
160 
163 
165  bool hasApCorrMap() const;
166 
169 
172 
179  void initApCorrMap();
180 
182  bool hasCoaddInputs() const;
183 
186 
189 
192 
194  bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
195 
198 
200  bool hasTransmissionCurve() const;
201 
204 
207 
232  template <class T>
234  std::shared_ptr<T> const& object) {
235  static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
236  // "No data" always represented internally by absent key-value pair, not by mapping to null
237  if (object != nullptr) {
238  _setComponent(key, object);
239  } else {
241  }
242  }
243 
252  template <class T>
254  return _components->contains(key);
255  }
256 
266  template <class T>
268  try {
269  return _components->at(key);
270  } catch (pex::exceptions::OutOfRangeError const& e) {
271  return nullptr;
272  }
273  }
274 
284  template <class T>
286  return _components->erase(key);
287  }
288 
290  static int getFitsSerializationVersion();
291 
294 
302  explicit ExposureInfo(
310  Filter const& filter = Filter(),
319 
323 
325  ExposureInfo(ExposureInfo const& other, bool copyMetadata);
326 
330 
331  // Destructor defined in source file because we need access to destructors of forward-declared components
333 
334 private:
335  template <typename ImageT, typename MaskT, typename VarianceT>
336  friend class Exposure;
337 
351  struct FitsWriteData {
356  table::io::OutputArchive archive;
357  };
358 
375  static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
376  std::string comment);
377 
378  static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
379  std::string key, std::string comment);
380 
391  FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
392 
406  void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
407 
409 
410  // Implementation of setComponent
411  template <class T>
412  void _setComponent(typehandling::Key<std::string, std::shared_ptr<T>> const& key,
413  std::shared_ptr<T> const& object) {
414  if (_components->contains(key)) {
415  _components->erase(key);
416  } else if (_components->contains(key.getId())) {
417  std::stringstream buffer;
418  buffer << "Map has a key that conflicts with " << key;
419  throw LSST_EXCEPT(pex::exceptions::TypeError, buffer.str());
420  }
421  try {
422  bool success = _components->insert(key, object);
423  if (!success) {
424  throw LSST_EXCEPT(
426  "Insertion failed for unknown reasons. There may be something in the logs.");
427  }
428  } catch (std::exception const& e) {
430  LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
431  }
432  }
433 
434  Filter _filter;
437 
438  // Class invariant: all pointers in _components are not null
440 };
441 } // namespace image
442 } // namespace afw
443 } // namespace lsst
444 
445 #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:197
lsst::afw::image::ExposureInfo::hasVisitInfo
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:194
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.pipe.tasks.assembleCoadd.filter
filter
Definition: assembleCoadd.py:335
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:141
lsst::afw::image::ExposureInfo::hasPsf
bool hasPsf() const
Does this exposure have a Psf?
Definition: ExposureInfo.cc:61
lsst::afw
Definition: imageAlgorithm.dox:1
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:233
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.h:129
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:153
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:131
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.h:126
fits
Fits * fits
Definition: FitsWriter.cc:90
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:285
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
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:267
lsst::afw::image::ExposureInfo::getFitsSerializationVersionName
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
Definition: ExposureInfo.cc:139
lsst::afw::image::ExposureInfo::initApCorrMap
void initApCorrMap()
Set the exposure's aperture correction map to a new, empty map.
Definition: ExposureInfo.cc:205
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
base.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
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::geom
Definition: geomOperators.dox:4
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:144
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::hasComponent
bool hasComponent(typehandling::Key< std::string, T > const &key) const
Test whether a generic component is defined.
Definition: ExposureInfo.h:253
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
lsst::geom::Point< int, 2 >
lsst::pex::exceptions::OutOfRangeError
Reports attempts to access elements outside a valid range of indices.
Definition: Runtime.h:89
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)
Point.h
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
Reports errors from accepting an object of an unexpected or inappropriate type.
Definition: Runtime.h:167
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 except the filter.
Definition: ExposureInfo.cc:192
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
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
base.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:191
std::is_base_of
apCorrMap
Key< int > apCorrMap
Definition: Exposure.cc:68
VisitInfo.h