LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
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
221 void initApCorrMap();
222
224 bool hasCoaddInputs() const;
225
228
231
234
236 bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
237
240 _visitInfo = visitInfo;
241 // Ensure consistency with getId() until the VisitInfo::getExposureId() is removed in DM-32138.
242 if (_visitInfo != nullptr && _visitInfo->getExposureId() != 0) {
243 // Do not call setId, to avoid recursion
244 _exposureId = _visitInfo->getExposureId();
245 } else {
246 _exposureId.reset();
247 }
248 }
249
251 bool hasTransmissionCurve() const;
252
255
258
283 template <class T>
285 std::shared_ptr<T> const& object) {
286 static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
287 // "No data" always represented internally by absent key-value pair, not by mapping to null
288 if (object != nullptr) {
289 _setComponent(key, object);
290 } else {
291 removeComponent(key);
292 }
293 }
294
303 template <class T>
305 return _components->contains(key);
306 }
307
317 template <class T>
319 try {
320 return _components->at(key);
321 } catch (pex::exceptions::OutOfRangeError const& e) {
322 return nullptr;
323 }
324 }
325
335 template <class T>
337 return _components->erase(key);
338 }
339
341 static int getFitsSerializationVersion();
342
345
353 explicit ExposureInfo(
369
371 ExposureInfo(ExposureInfo const& other);
372 ExposureInfo(ExposureInfo&& other);
373
375 ExposureInfo(ExposureInfo const& other, bool copyMetadata);
376
378 ExposureInfo& operator=(ExposureInfo const& other);
380
381 // Destructor defined in source file because we need access to destructors of forward-declared components
383
384private:
385 template <typename ImageT, typename MaskT, typename VarianceT>
386 friend class Exposure;
387
401 struct FitsWriteData {
407 };
408
425 static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
426 std::string comment);
427
428 static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
429 std::string key, std::string comment);
430
441 FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
442
456 void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
457
458 static std::shared_ptr<ApCorrMap> _cloneApCorrMap(std::shared_ptr<ApCorrMap const> apCorrMap);
459
460 // Implementation of setComponent
461 template <class T>
462 void _setComponent(typehandling::Key<std::string, std::shared_ptr<T>> const& key,
463 std::shared_ptr<T> const& object) {
464 if (_components->contains(key)) {
465 _components->erase(key);
466 } else if (_components->contains(key.getId())) {
467 std::stringstream buffer;
468 buffer << "Map has a key that conflicts with " << key;
470 }
471 try {
472 bool success = _components->insert(key, object);
473 if (!success) {
474 throw LSST_EXCEPT(
476 "Insertion failed for unknown reasons. There may be something in the logs.");
477 }
478 } catch (std::exception const& e) {
480 LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
481 }
482 }
483
484 std::optional<table::RecordId> _exposureId;
487
488 // Class invariant: all pointers in _components are not null
490};
491} // namespace image
492} // namespace afw
493} // namespace lsst
494
495#endif // !LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
char * data
Definition: BaseRecord.cc:61
table::Key< int > detector
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:66
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.
Definition: ExposureInfo.h:88
bool hasWcs() const
Does this exposure have a Wcs?
Definition: ExposureInfo.cc:54
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.
Definition: ExposureInfo.h:91
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.
Definition: ExposureInfo.h:97
bool hasTransmissionCurve() const
Does this exposure have a transmission curve?
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:239
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
std::shared_ptr< PhotoCalib const > getPhotoCalib() const
Return the exposure's photometric calibration.
Definition: ExposureInfo.cc:69
bool hasComponent(typehandling::Key< std::string, T > const &key) const
Test whether a generic component is defined.
Definition: ExposureInfo.h:304
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.
Definition: ExposureInfo.cc:72
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:100
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:284
bool hasValidPolygon() const
Does this exposure have a valid Polygon.
Definition: ExposureInfo.cc:91
std::shared_ptr< geom::SkyWcs const > getWcs() const
Return the WCS of the exposure.
Definition: ExposureInfo.cc:55
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:318
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.
Definition: ExposureInfo.h:95
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.
Definition: ExposureInfo.cc:80
void clearId() noexcept
Unset the exposure ID, if any.
void setMetadata(std::shared_ptr< daf::base::PropertySet > metadata)
Set the flexible metadata.
Definition: ExposureInfo.h:186
void setDetector(std::shared_ptr< cameraGeom::Detector const > detector)
Set the exposure's Detector information.
Definition: ExposureInfo.cc:83
void setFilter(std::shared_ptr< FilterLabel const > filter)
Set the exposure's filter information.
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:236
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:107
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:102
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:93
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.
Definition: ExposureInfo.cc:92
std::shared_ptr< daf::base::PropertySet > getMetadata() const
Return flexible metadata.
Definition: ExposureInfo.h:183
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:104
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.
Definition: ExposureInfo.h:233
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
Definition: ExposureInfo.h:109
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.
Definition: ExposureInfo.h:336
std::shared_ptr< detection::Psf const > getPsf() const
Return the exposure's point-spread function.
Definition: ExposureInfo.cc:62
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.
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
STL namespace.
T str(T... args)
Key< int > visitInfo
Definition: Exposure.cc:70
Key< int > photoCalib
Definition: Exposure.cc:67
Key< int > transmissionCurve
Definition: Exposure.cc:71
T throw_with_nested(T... args)