LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
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"
38#include "lsst/afw/table/misc.h" // For table::RecordId
39
40namespace lsst {
41namespace afw {
42
43namespace cameraGeom {
44class Detector;
45}
46
47namespace detection {
48class Psf;
49}
50
51namespace geom {
52namespace polygon {
53class Polygon;
54class SkyWcs;
55} // namespace polygon
56} // namespace geom
57
58namespace fits {
59class Fits;
60}
61
62namespace image {
63
64class PhotoCalib;
65class ApCorrMap;
66class VisitInfo;
67class TransmissionCurve;
68
88class ExposureInfo final {
89public:
110
119 bool hasId() const noexcept;
120
131 table::RecordId getId() const;
132
141 void setId(table::RecordId id);
142
144 void clearId() noexcept;
145
147 bool hasWcs() const;
148
150 std::shared_ptr<geom::SkyWcs const> getWcs() const;
151
153 void setWcs(std::shared_ptr<geom::SkyWcs const> wcs);
154
156 bool hasDetector() const;
157
159 std::shared_ptr<cameraGeom::Detector const> getDetector() const;
160
162 void setDetector(std::shared_ptr<cameraGeom::Detector const> detector);
163
165 bool hasFilter() const;
166
168 std::shared_ptr<FilterLabel const> getFilter() const;
169
171 void setFilter(std::shared_ptr<FilterLabel const> filter);
172
174 bool hasPhotoCalib() const;
175
177 std::shared_ptr<PhotoCalib const> getPhotoCalib() const;
178
180 void setPhotoCalib(std::shared_ptr<PhotoCalib const> photoCalib);
181
183 std::shared_ptr<daf::base::PropertySet> getMetadata() const { return _metadata; }
184
186 void setMetadata(std::shared_ptr<daf::base::PropertySet> metadata) { _metadata = metadata; }
187
189 bool hasPsf() const;
190
193
196
198 bool hasValidPolygon() const;
199
202
205
207 bool hasApCorrMap() const;
208
211
214
216 bool hasCoaddInputs() const;
217
220
223
226
228 bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
229
232
234 bool hasTransmissionCurve() const;
235
238
241
266 template <class T>
268 std::shared_ptr<T> const& object) {
269 static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
270 // "No data" always represented internally by absent key-value pair, not by mapping to null
271 if (object != nullptr) {
272 _setComponent(key, object);
273 } else {
274 removeComponent(key);
275 }
276 }
277
286 template <class T>
288 return _components->contains(key);
289 }
290
300 template <class T>
302 try {
303 return _components->at(key);
304 } catch (pex::exceptions::OutOfRangeError const& e) {
305 return nullptr;
306 }
307 }
308
318 template <class T>
320 return _components->erase(key);
321 }
322
324 static int getFitsSerializationVersion();
325
328
336 explicit ExposureInfo(
352
354 ExposureInfo(ExposureInfo const& other);
355 ExposureInfo(ExposureInfo&& other);
356
358 ExposureInfo(ExposureInfo const& other, bool copyMetadata);
359
361 ExposureInfo& operator=(ExposureInfo const& other);
363
364 // Destructor defined in source file because we need access to destructors of forward-declared components
366
367private:
368 template <typename ImageT, typename MaskT, typename VarianceT>
369 friend class Exposure;
370
384 struct FitsWriteData {
390 };
391
408 static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
409 std::string comment);
410
411 static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
412 std::string key, std::string comment);
413
424 FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
425
439 void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
440
442
443 // Implementation of setComponent
444 template <class T>
445 void _setComponent(typehandling::Key<std::string, std::shared_ptr<T>> const& key,
446 std::shared_ptr<T> const& object) {
447 if (_components->contains(key)) {
448 _components->erase(key);
449 } else if (_components->contains(key.getId())) {
450 std::stringstream buffer;
451 buffer << "Map has a key that conflicts with " << key;
453 }
454 try {
455 bool success = _components->insert(key, object);
456 if (!success) {
457 throw LSST_EXCEPT(
459 "Insertion failed for unknown reasons. There may be something in the logs.");
460 }
461 } catch (std::exception const& e) {
463 LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
464 }
465 }
466
467 std::optional<table::RecordId> _exposureId;
470
471 // Class invariant: all pointers in _components are not null
473};
474} // namespace image
475} // namespace afw
476} // namespace lsst
477
478#endif // !LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
char * data
Definition BaseRecord.cc:61
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
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.
bool hasWcs() const
Does this exposure have a Wcs?
static int getFitsSerializationVersion()
Get the version of FITS serialization that this ExposureInfo understands.
bool hasCoaddInputs() const
Does this exposure have coadd provenance catalogs?
static typehandling::Key< std::string, std::shared_ptr< geom::SkyWcs const > > const KEY_WCS
Standard key for looking up the Wcs.
ExposureInfo & operator=(ExposureInfo const &other)
Assignment; shares all components.
static typehandling::Key< std::string, std::shared_ptr< cameraGeom::Detector const > > const KEY_DETECTOR
Standard key for looking up the detector information.
bool hasTransmissionCurve() const
Does this exposure have a transmission curve?
bool hasPsf() const
Does this exposure have a Psf?
void setVisitInfo(std::shared_ptr< image::VisitInfo const > const visitInfo)
Set the exposure's visit info.
void setValidPolygon(std::shared_ptr< geom::polygon::Polygon const > polygon)
Set the exposure's valid Polygon.
bool hasPhotoCalib() const
Does this exposure have a photometric calibration?
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.
std::shared_ptr< PhotoCalib const > getPhotoCalib() const
Return the exposure's photometric calibration.
bool hasComponent(typehandling::Key< std::string, T > const &key) const
Test whether a generic component is defined.
std::shared_ptr< ApCorrMap const > getApCorrMap() const
Return the exposure's aperture correction map (null pointer if !hasApCorrMap())
void setApCorrMap(std::shared_ptr< ApCorrMap const > apCorrMap)
Set the exposure's aperture correction map (null pointer if !hasApCorrMap())
void setPhotoCalib(std::shared_ptr< PhotoCalib const > photoCalib)
Set the Exposure's PhotoCalib object.
static typehandling::Key< std::string, std::shared_ptr< geom::polygon::Polygon const > > const KEY_VALID_POLYGON
Standard key for looking up the valid polygon.
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.
bool hasValidPolygon() const
Does this exposure have a valid Polygon.
std::shared_ptr< geom::SkyWcs const > getWcs() const
Return the WCS of the exposure.
std::shared_ptr< T > getComponent(typehandling::Key< std::string, std::shared_ptr< T > > const &key) const
Retrieve a generic component from the ExposureInfo.
std::shared_ptr< FilterLabel const > getFilter() const
Return the exposure's filter information.
static typehandling::Key< std::string, std::shared_ptr< PhotoCalib const > > const KEY_PHOTO_CALIB
Standard key for looking up the photometric calibration.
void setCoaddInputs(std::shared_ptr< CoaddInputs const > coaddInputs)
Set the exposure's coadd provenance catalogs.
std::shared_ptr< cameraGeom::Detector const > getDetector() const
Return the exposure's Detector information.
void clearId() noexcept
Unset the exposure ID, if any.
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
void setDetector(std::shared_ptr< cameraGeom::Detector const > detector)
Set the exposure's Detector information.
void setFilter(std::shared_ptr< FilterLabel const > filter)
Set the exposure's filter information.
bool hasVisitInfo() const
Does this exposure have visit info?
void setPsf(std::shared_ptr< detection::Psf const > psf)
Set the exposure's point-spread function.
static typehandling::Key< std::string, std::shared_ptr< TransmissionCurve const > > const KEY_TRANSMISSION_CURVE
Standard key for looking up the transmission curve.
static typehandling::Key< std::string, std::shared_ptr< CoaddInputs const > > const KEY_COADD_INPUTS
Standard key for looking up coadd provenance catalogs.
static typehandling::Key< std::string, std::shared_ptr< detection::Psf const > > const KEY_PSF
Standard key for looking up the point-spread function.
std::shared_ptr< CoaddInputs const > getCoaddInputs() const
Return a pair of catalogs that record the inputs, if this Exposure is a coadd (otherwise null).
bool hasFilter() const
Does this exposure have filter information?
table::RecordId getId() const
Return the exposure ID.
std::shared_ptr< geom::polygon::Polygon const > getValidPolygon() const
Return the valid Polygon.
std::shared_ptr< daf::base::PropertySet > getMetadata() const
Return flexible metadata.
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 >(), 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.
bool hasDetector() const
Does this exposure have Detector information?
static typehandling::Key< std::string, std::shared_ptr< ApCorrMap const > > const KEY_AP_CORR_MAP
Standard key for looking up the aperture correction map.
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure's visit info.
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
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.
std::shared_ptr< detection::Psf const > getPsf() const
Return the exposure's point-spread function.
std::shared_ptr< TransmissionCurve const > getTransmissionCurve() const
Return the exposure's transmission curve.
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.
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
STL namespace.
T str(T... args)
Key< int > psf
Definition Exposure.cc:65
Key< int > visitInfo
Definition Exposure.cc:70
Key< int > transmissionCurve
Definition Exposure.cc:71
Key< int > apCorrMap
Definition Exposure.cc:68
T throw_with_nested(T... args)