LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
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 
135  std::shared_ptr<PhotoCalib const> getPhotoCalib() const;
136 
138  void setPhotoCalib(std::shared_ptr<PhotoCalib const> photoCalib);
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 
159  std::shared_ptr<geom::polygon::Polygon const> getValidPolygon() const;
160 
162  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon);
163 
165  bool hasApCorrMap() const;
166 
168  std::shared_ptr<ApCorrMap const> getApCorrMap() const;
169 
171  void setApCorrMap(std::shared_ptr<ApCorrMap const> apCorrMap);
172 
179  void initApCorrMap();
180 
182  bool hasCoaddInputs() const;
183 
185  void setCoaddInputs(std::shared_ptr<CoaddInputs const> coaddInputs);
186 
188  std::shared_ptr<CoaddInputs const> getCoaddInputs() const;
189 
192 
194  bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
195 
198 
200  bool hasTransmissionCurve() const;
201 
203  std::shared_ptr<TransmissionCurve const> getTransmissionCurve() const;
204 
206  void setTransmissionCurve(std::shared_ptr<TransmissionCurve const> tc);
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 {
240  removeComponent(key);
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 
293  static std::string const& getFitsSerializationVersionName();
294 
302  explicit ExposureInfo(
310  Filter const& filter = Filter(),
319 
322  ExposureInfo(ExposureInfo&& other);
323 
325  ExposureInfo(ExposureInfo const& other, bool copyMetadata);
326 
328  ExposureInfo& operator=(ExposureInfo const& other);
329  ExposureInfo& operator=(ExposureInfo&& other);
330 
331  // Destructor defined in source file because we need access to destructors of forward-declared components
332  ~ExposureInfo();
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 
408  static std::shared_ptr<ApCorrMap> _cloneApCorrMap(std::shared_ptr<ApCorrMap const> apCorrMap);
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
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
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 setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
Definition: ExposureInfo.h:144
Basic LSST definitions.
Key< int > visitInfo
Definition: Exposure.cc:70
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< geom::polygon::Polygon const > > const KEY_VALID_POLYGON
Standard key for looking up the valid polygon.
Definition: ExposureInfo.h:98
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:197
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure&#39;s visit info.
Definition: ExposureInfo.h:191
bool removeComponent(typehandling::Key< std::string, T > const &key)
Clear a generic component from the ExposureInfo.
Definition: ExposureInfo.h:285
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
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:89
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
Fits * fits
Definition: FitsWriter.cc:90
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: Key.h:52
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:194
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:129
Key< U > key
Definition: Schema.cc:281
T str(T... args)
table::Key< int > detector
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
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
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:141
Key< int > apCorrMap
Definition: Exposure.cc:68
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Reports attempts to access elements outside a valid range of indices.
Definition: Runtime.h:89
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
STL class.
bool hasComponent(typehandling::Key< std::string, T > const &key) const
Test whether a generic component is defined.
Definition: ExposureInfo.h:253
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
Reports errors from accepting an object of an unexpected or inappropriate type.
Definition: Runtime.h:167
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:86
Filter getFilter() const
Return the exposure&#39;s filter.
Definition: ExposureInfo.h:126
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
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