Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+05816baf74,g1ec0fe41b4+f536777771,g1fd858c14a+a9301854fb,g35bb328faa+fcb1d3bbc8,g4af146b050+a5c07d5b1d,g4d2262a081+6e5fcc2a4e,g53246c7159+fcb1d3bbc8,g56a49b3a55+9c12191793,g5a012ec0e7+3632fc3ff3,g60b5630c4e+ded28b650d,g67b6fd64d1+ed4b5058f4,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8352419a5c+fcb1d3bbc8,g87b7deb4dc+7b42cf88bf,g8852436030+e5453db6e6,g89139ef638+ed4b5058f4,g8e3bb8577d+d38d73bdbd,g9125e01d80+fcb1d3bbc8,g94187f82dc+ded28b650d,g989de1cb63+ed4b5058f4,g9d31334357+ded28b650d,g9f33ca652e+50a8019d8c,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+d9fb1f8026,gb58c049af0+f03b321e39,gb665e3612d+2a0c9e9e84,gb89ab40317+ed4b5058f4,gcf25f946ba+e5453db6e6,gd6cbbdb0b4+bb83cc51f8,gdd1046aedd+ded28b650d,gde0f65d7ad+941d412827,ge278dab8ac+d65b3c2b70,ge410e46f29+ed4b5058f4,gf23fb2af72+b7cae620c0,gf5e32f922b+fcb1d3bbc8,gf67bdafdda+ed4b5058f4,w.2025.16
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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;
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
231 void setVisitInfo(std::shared_ptr<image::VisitInfo const> const visitInfo) { _visitInfo = visitInfo; }
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(
350 std::shared_ptr<TransmissionCurve const> const& transmissionCurve =
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
415
424 FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
425
439 void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
440
441 static std::shared_ptr<ApCorrMap> _cloneApCorrMap(std::shared_ptr<ApCorrMap const> apCorrMap);
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;
468 std::shared_ptr<daf::base::PropertySet> _metadata;
469 std::shared_ptr<image::VisitInfo const> _visitInfo;
470
471 // Class invariant: all pointers in _components are not null
472 std::unique_ptr<detail::StorableMap> _components;
473};
474} // namespace image
475} // namespace afw
476} // namespace lsst
477
478#endif // !LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
Basic LSST definitions.
A representation of a detector in a mosaic camera.
Definition Detector.h:185
A polymorphic base class for representing an image's Point Spread Function.
Definition Psf.h:82
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
Cartesian polygons.
Definition Polygon.h:59
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
Definition ApCorrMap.h:45
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 spatially-varying transmission curve as a function of wavelength.
Information about a single exposure of an imaging camera.
Definition VisitInfo.h:68
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
Point< int, 2 > Point2I
Definition Point.h:321
STL namespace.
T str(T... args)
T throw_with_nested(T... args)