LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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 <optional>
29 
30 #include "lsst/base.h"
31 #include "lsst/daf/base.h"
32 #include "lsst/geom/Point.h"
33 #include "lsst/afw/image/Filter.h"
39 #include "lsst/afw/table/misc.h" // For table::RecordId
40 
41 namespace lsst {
42 namespace afw {
43 
44 namespace cameraGeom {
45 class Detector;
46 }
47 
48 namespace detection {
49 class Psf;
50 }
51 
52 namespace geom {
53 namespace polygon {
54 class Polygon;
55 class SkyWcs;
56 } // namespace polygon
57 } // namespace geom
58 
59 namespace fits {
60 class Fits;
61 }
62 
63 namespace image {
64 
65 class PhotoCalib;
66 class ApCorrMap;
67 class VisitInfo;
68 class TransmissionCurve;
69 
90 public:
111 
120  bool hasId() const noexcept;
121 
132  table::RecordId getId() const;
133 
142  void setId(table::RecordId id);
143 
145  void clearId() noexcept;
146 
148  bool hasWcs() const;
149 
151  std::shared_ptr<geom::SkyWcs const> getWcs() const;
152 
154  void setWcs(std::shared_ptr<geom::SkyWcs const> wcs);
155 
157  bool hasDetector() const;
158 
160  std::shared_ptr<cameraGeom::Detector const> getDetector() const;
161 
163  void setDetector(std::shared_ptr<cameraGeom::Detector const> detector);
164 
166  // TODO: remove in DM-27177
167  [[deprecated("Replaced with getFilterLabel. Will be removed after v22.")]] Filter getFilter() const;
168 
175  // TODO: remove in DM-27177
176  [[deprecated("Replaced with setFilterLabel. Will be removed after v22.")]] void setFilter(
177  Filter const& filter);
178 
180  // TODO: deprecate in DM-27177, remove in DM-27811.
181  bool hasFilterLabel() const;
182 
184  // TODO: deprecate in DM-27177, remove in DM-27811.
185  std::shared_ptr<FilterLabel const> getFilterLabel() const;
186 
188  // TODO: deprecate in DM-27177, remove in DM-27811.
189  void setFilterLabel(std::shared_ptr<FilterLabel const> filterLabel);
190 
192  bool hasPhotoCalib() const;
193 
195  std::shared_ptr<PhotoCalib const> getPhotoCalib() const;
196 
198  void setPhotoCalib(std::shared_ptr<PhotoCalib const> photoCalib);
199 
201  std::shared_ptr<daf::base::PropertySet> getMetadata() const { return _metadata; }
202 
204  void setMetadata(std::shared_ptr<daf::base::PropertySet> metadata) { _metadata = metadata; }
205 
207  bool hasPsf() const;
208 
211 
214 
216  bool hasValidPolygon() const;
217 
220 
223 
225  bool hasApCorrMap() const;
226 
229 
232 
239  void initApCorrMap();
240 
242  bool hasCoaddInputs() const;
243 
246 
249 
252 
254  bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
255 
258  _visitInfo = visitInfo;
259  // Ensure consistency with getId() until the VisitInfo::getExposureId() is removed in DM-32138.
260  if (_visitInfo != nullptr && _visitInfo->getExposureId() != 0) {
261  // Do not call setId, to avoid recursion
262  _exposureId = _visitInfo->getExposureId();
263  } else {
264  _exposureId.reset();
265  }
266  }
267 
269  bool hasTransmissionCurve() const;
270 
273 
276 
301  template <class T>
303  std::shared_ptr<T> const& object) {
304  static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
305  // "No data" always represented internally by absent key-value pair, not by mapping to null
306  if (object != nullptr) {
307  _setComponent(key, object);
308  } else {
309  removeComponent(key);
310  }
311  }
312 
321  template <class T>
323  return _components->contains(key);
324  }
325 
335  template <class T>
337  try {
338  return _components->at(key);
339  } catch (pex::exceptions::OutOfRangeError const& e) {
340  return nullptr;
341  }
342  }
343 
353  template <class T>
355  return _components->erase(key);
356  }
357 
359  static int getFitsSerializationVersion();
360 
363 
371  explicit ExposureInfo(
379  Filter const& filter = Filter(),
388 
390  ExposureInfo(ExposureInfo const& other);
391  ExposureInfo(ExposureInfo&& other);
392 
394  ExposureInfo(ExposureInfo const& other, bool copyMetadata);
395 
397  ExposureInfo& operator=(ExposureInfo const& other);
399 
400  // Destructor defined in source file because we need access to destructors of forward-declared components
402 
403 private:
404  template <typename ImageT, typename MaskT, typename VarianceT>
405  friend class Exposure;
406 
420  struct FitsWriteData {
425  table::io::OutputArchive archive;
426  };
427 
444  static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
445  std::string comment);
446 
447  static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
448  std::string key, std::string comment);
449 
460  FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
461 
475  void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
476 
478 
479  // Implementation of setComponent
480  template <class T>
481  void _setComponent(typehandling::Key<std::string, std::shared_ptr<T>> const& key,
482  std::shared_ptr<T> const& object) {
483  if (_components->contains(key)) {
484  _components->erase(key);
485  } else if (_components->contains(key.getId())) {
486  std::stringstream buffer;
487  buffer << "Map has a key that conflicts with " << key;
488  throw LSST_EXCEPT(pex::exceptions::TypeError, buffer.str());
489  }
490  try {
491  bool success = _components->insert(key, object);
492  if (!success) {
493  throw LSST_EXCEPT(
495  "Insertion failed for unknown reasons. There may be something in the logs.");
496  }
497  } catch (std::exception const& e) {
499  LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
500  }
501  }
502 
503  std::optional<table::RecordId> _exposureId;
506 
507  // Class invariant: all pointers in _components are not null
509 };
510 } // namespace image
511 } // namespace afw
512 } // namespace lsst
513 
514 #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:89
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:201
static typehandling::Key< std::string, std::shared_ptr< geom::SkyWcs const > > const KEY_WCS
Standard key for looking up the Wcs.
Definition: ExposureInfo.h:92
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:98
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:257
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:322
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure's visit info.
Definition: ExposureInfo.h:251
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:302
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:101
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:336
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:96
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 clearId() noexcept
Unset the exposure ID, if any.
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
Definition: ExposureInfo.h:204
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:254
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:108
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:103
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:94
table::RecordId getId() const
Return the exposure ID.
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:105
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:110
void setId(table::RecordId id)
Set the exposure ID.
bool hasId() const noexcept
Does this Exposure have an exposure id?
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:354
A group of labels for a filter in an exposure or coadd.
Definition: FilterLabel.h:58
The photometric calibration of an exposure.
Definition: PhotoCalib.h:114
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
std::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:21
A base class for image defects.
STL namespace.
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)