lsst.afw  18.1.0-14-gac42dcd43+2
ExposureInfo.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*- // fixed format comment for emacs
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2013 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
25 #define LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
26 
27 #include "lsst/base.h"
28 #include "lsst/daf/base.h"
29 #include "lsst/geom/Point.h"
30 #include "lsst/afw/image/Filter.h"
35 
36 namespace lsst {
37 namespace afw {
38 
39 namespace cameraGeom {
40 class Detector;
41 }
42 
43 namespace detection {
44 class Psf;
45 }
46 
47 namespace geom {
48 namespace polygon {
49 class Polygon;
50 class SkyWcs;
51 } // namespace polygon
52 } // namespace geom
53 
54 namespace fits {
55 class Fits;
56 }
57 
58 namespace image {
59 
60 class PhotoCalib;
61 class ApCorrMap;
62 class VisitInfo;
63 class TransmissionCurve;
64 
85 class ExposureInfo final {
86 public:
105 
107  bool hasWcs() const;
108 
111 
114 
116  bool hasDetector() const;
117 
120 
123 
125  Filter getFilter() const { return _filter; }
126 
128  void setFilter(Filter const& filter) { _filter = filter; }
129 
131  bool hasPhotoCalib() const;
132 
134  std::shared_ptr<PhotoCalib const> getPhotoCalib() const;
135 
137  void setPhotoCalib(std::shared_ptr<PhotoCalib const> photoCalib);
138 
140  [[deprecated("Replaced with hasPhotoCalib (will be removed in 18.0)")]] bool hasCalib() const {
141  return hasPhotoCalib();
142  }
143 
145  [[deprecated("Replaced with getPhotoCalib (will be removed in 18.0)")]] std::shared_ptr<PhotoCalib const>
146  getCalib() const {
147  return getPhotoCalib();
148  }
149 
151  [[deprecated("Replaced with setPhotoCalib (will be removed in 18.0)")]] void setCalib(
153  setPhotoCalib(photoCalib);
154  }
155 
158 
160  void setMetadata(std::shared_ptr<daf::base::PropertySet> metadata) { _metadata = metadata; }
161 
163  bool hasPsf() const;
164 
167 
170 
172  bool hasValidPolygon() const;
173 
175  std::shared_ptr<geom::polygon::Polygon const> getValidPolygon() const;
176 
178  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon);
179 
181  bool hasApCorrMap() const;
182 
184  std::shared_ptr<ApCorrMap const> getApCorrMap() const;
185 
187  void setApCorrMap(std::shared_ptr<ApCorrMap const> apCorrMap);
188 
195  void initApCorrMap();
196 
198  bool hasCoaddInputs() const;
199 
201  void setCoaddInputs(std::shared_ptr<CoaddInputs const> coaddInputs);
202 
204  std::shared_ptr<CoaddInputs const> getCoaddInputs() const;
205 
208 
210  bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
211 
214 
216  bool hasTransmissionCurve() const;
217 
219  std::shared_ptr<TransmissionCurve const> getTransmissionCurve() const;
220 
222  void setTransmissionCurve(std::shared_ptr<TransmissionCurve const> tc);
223 
248  // non-shared_ptr components are incompatible with table::io,
249  // they may be supported later
250  template <class T>
252  std::shared_ptr<T> const& object) {
253  static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
254  // "No data" always represented internally by absent key-value pair, not by mapping to null
255  if (object != nullptr) {
256  _setStorableComponent(key, object);
257  } else {
258  removeComponent(key);
259  }
260  }
261 
270  template <class T>
272  return _components->contains(key);
273  }
274 
284  template <class T>
286  try {
287  return _components->at(key);
288  } catch (pex::exceptions::OutOfRangeError const& e) {
289  return nullptr;
290  }
291  }
292 
302  template <class T>
304  return _components->erase(key);
305  }
306 
308  static int getFitsSerializationVersion();
309 
311  static std::string const& getFitsSerializationVersionName();
312 
320  explicit ExposureInfo(
328  Filter const& filter = Filter(),
337 
340  ExposureInfo(ExposureInfo&& other);
341 
343  ExposureInfo(ExposureInfo const& other, bool copyMetadata);
344 
346  ExposureInfo& operator=(ExposureInfo const& other);
347  ExposureInfo& operator=(ExposureInfo&& other);
348 
349  // Destructor defined in source file because we need access to destructors of forward-declared components
350  ~ExposureInfo();
351 
352 private:
353  template <typename ImageT, typename MaskT, typename VarianceT>
354  friend class Exposure;
355 
369  struct FitsWriteData {
374  table::io::OutputArchive archive;
375  };
376 
393  static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
394  std::string comment);
395 
396  static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
397  std::string key, std::string comment);
398 
409  FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
410 
424  void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
425 
432  class StorablePersister;
433 
434  static std::shared_ptr<ApCorrMap> _cloneApCorrMap(std::shared_ptr<ApCorrMap const> apCorrMap);
435 
436  // Implementation of setComponent, assumes T extends Storable or T = shared_ptr<? extends Storable>
437  template <class T>
438  void _setStorableComponent(typehandling::Key<std::string, T> const& key, T const& object) {
439  if (_components->contains(key)) {
440  _components->erase(key);
441  } else if (_components->contains(key.getId())) {
442  std::stringstream buffer;
443  buffer << "Map has a key that conflicts with " << key;
444  throw LSST_EXCEPT(pex::exceptions::TypeError, buffer.str());
445  }
446  try {
447  bool success = _components->insert(key, object);
448  if (!success) {
449  throw LSST_EXCEPT(
451  "Insertion failed for unknown reasons. There may be something in the logs.");
452  }
453  } catch (std::exception const& e) {
455  LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
456  }
457  }
458 
459  Filter _filter;
462 
463  // Class invariant: all values in _components are shared_ptr<Storable>
464  // This is required for table::io persistence to work correctly;
465  // other persistence frameworks may let us support other types
466  // Class invariant: all pointers in _components are not null
468 };
469 } // namespace image
470 } // namespace afw
471 } // namespace lsst
472 
473 #endif // !LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
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:285
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:104
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
Definition: ExposureInfo.h:160
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:99
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:97
void setCalib(std::shared_ptr< PhotoCalib const > photoCalib)
Set the Exposure&#39;s PhotoCalib object.
Definition: ExposureInfo.h:151
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:72
void setVisitInfo(std::shared_ptr< image::VisitInfo const > const visitInfo)
Set the exposure&#39;s visit info.
Definition: ExposureInfo.h:213
table::Key< int > detector
bool hasCalib() const
Does this exposure have a photometric calibration?
Definition: ExposureInfo.h:140
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure&#39;s visit info.
Definition: ExposureInfo.h:207
bool removeComponent(typehandling::Key< std::string, T > const &key)
Clear a generic component from the ExposureInfo.
Definition: ExposureInfo.h:303
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:251
Key< int > apCorrMap
Definition: Exposure.cc:68
Key< int > psf
Definition: Exposure.cc:65
ItemVariant const * other
Definition: Schema.cc:56
static typehandling::Key< std::string, std::shared_ptr< geom::SkyWcs const > > const KEY_WCS
Standard key for looking up the Wcs.
Definition: ExposureInfo.h:88
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Fits * fits
Definition: FitsWriter.cc:90
std::shared_ptr< PhotoCalib const > getCalib() const
Return the exposure&#39;s photometric calibration.
Definition: ExposureInfo.h:146
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
A multi-catalog archive object used to save table::io::Persistable objects.
Definition: OutputArchive.h:34
Key for type-safe lookup in a GenericMap.
Definition: GenericMap.h:63
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:210
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
A base class for image defects.
char * data
Definition: BaseRecord.cc:62
T throw_with_nested(T... args)
void setFilter(Filter const &filter)
Set the exposure&#39;s filter.
Definition: ExposureInfo.h:128
Key< U > key
Definition: Schema.cc:281
T str(T... args)
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:92
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:101
STL class.
Holds an integer identifier for an LSST filter.
Definition: Filter.h:141
std::shared_ptr< daf::base::PropertySet > getMetadata() const
Return flexible metadata.
Definition: ExposureInfo.h:157
Key< int > visitInfo
Definition: Exposure.cc:70
#define LSST_EXCEPT(type,...)
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:90
STL class.
bool hasComponent(typehandling::Key< std::string, T > const &key) const
Test whether a generic component is defined.
Definition: ExposureInfo.h:271
constexpr K const & getId() const noexcept
Return the identifier of this field.
Definition: GenericMap.h:94
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:85
Filter getFilter() const
Return the exposure&#39;s filter.
Definition: ExposureInfo.h:125
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:94