LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
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 {
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 
345 
347  ExposureInfo(ExposureInfo const& other, bool copyMetadata);
348 
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:62
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
ItemVariant const * other
Definition: Schema.cc:56
Key< U > key
Definition: Schema.cc:281
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
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)