lsst.afw g8f2ba02de7+e31e6a4341
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"
39#include "lsst/afw/table/misc.h" // For table::RecordId
40
41namespace lsst {
42namespace afw {
43
44namespace cameraGeom {
45class Detector;
46}
47
48namespace detection {
49class Psf;
50}
51
52namespace geom {
53namespace polygon {
54class Polygon;
55class SkyWcs;
56} // namespace polygon
57} // namespace geom
58
59namespace fits {
60class Fits;
61}
62
63namespace image {
64
65class PhotoCalib;
66class ApCorrMap;
67class VisitInfo;
68class TransmissionCurve;
69
90public:
111
120 bool hasId() const noexcept;
121
132 table::RecordId getId() const;
133
142 void setId(table::RecordId id);
143
145 void clearId() noexcept;
146
148 bool hasWcs() const;
149
151 std::shared_ptr<geom::SkyWcs const> getWcs() const;
152
154 void setWcs(std::shared_ptr<geom::SkyWcs const> wcs);
155
157 bool hasDetector() const;
158
160 std::shared_ptr<cameraGeom::Detector const> getDetector() const;
161
163 void setDetector(std::shared_ptr<cameraGeom::Detector const> detector);
164
166 // TODO: remove in DM-27177
167 [[deprecated("Replaced with getFilterLabel. Will be removed after v22.")]] Filter getFilter() const;
168
175 // TODO: remove in DM-27177
176 [[deprecated("Replaced with setFilterLabel. Will be removed after v22.")]] void setFilter(
177 Filter const& filter);
178
180 // TODO: deprecate in DM-27177, remove in DM-27811.
181 bool hasFilterLabel() const;
182
184 // TODO: deprecate in DM-27177, remove in DM-27811.
185 std::shared_ptr<FilterLabel const> getFilterLabel() const;
186
188 // TODO: deprecate in DM-27177, remove in DM-27811.
189 void setFilterLabel(std::shared_ptr<FilterLabel const> filterLabel);
190
192 bool hasPhotoCalib() const;
193
195 std::shared_ptr<PhotoCalib const> getPhotoCalib() const;
196
198 void setPhotoCalib(std::shared_ptr<PhotoCalib const> photoCalib);
199
201 std::shared_ptr<daf::base::PropertySet> getMetadata() const { return _metadata; }
202
204 void setMetadata(std::shared_ptr<daf::base::PropertySet> metadata) { _metadata = metadata; }
205
207 bool hasPsf() const;
208
211
214
216 bool hasValidPolygon() const;
217
220
223
225 bool hasApCorrMap() const;
226
229
232
239 void initApCorrMap();
240
242 bool hasCoaddInputs() const;
243
246
249
252
254 bool hasVisitInfo() const { return static_cast<bool>(_visitInfo); }
255
258 _visitInfo = visitInfo;
259 // Ensure consistency with getId() until the VisitInfo::getExposureId() is removed in DM-32138.
260 if (_visitInfo != nullptr && _visitInfo->getExposureId() != 0) {
261 // Do not call setId, to avoid recursion
262 _exposureId = _visitInfo->getExposureId();
263 } else {
264 _exposureId.reset();
265 }
266 }
267
269 bool hasTransmissionCurve() const;
270
273
276
301 template <class T>
303 std::shared_ptr<T> const& object) {
304 static_assert(std::is_base_of<typehandling::Storable, T>::value, "T must be a Storable");
305 // "No data" always represented internally by absent key-value pair, not by mapping to null
306 if (object != nullptr) {
307 _setComponent(key, object);
308 } else {
309 removeComponent(key);
310 }
311 }
312
321 template <class T>
323 return _components->contains(key);
324 }
325
335 template <class T>
337 try {
338 return _components->at(key);
339 } catch (pex::exceptions::OutOfRangeError const& e) {
340 return nullptr;
341 }
342 }
343
353 template <class T>
355 return _components->erase(key);
356 }
357
359 static int getFitsSerializationVersion();
360
363
371 explicit ExposureInfo(
379 Filter const& filter = Filter(),
388
390 ExposureInfo(ExposureInfo const& other);
391 ExposureInfo(ExposureInfo&& other);
392
394 ExposureInfo(ExposureInfo const& other, bool copyMetadata);
395
397 ExposureInfo& operator=(ExposureInfo const& other);
399
400 // Destructor defined in source file because we need access to destructors of forward-declared components
402
403private:
404 template <typename ImageT, typename MaskT, typename VarianceT>
405 friend class Exposure;
406
420 struct FitsWriteData {
426 };
427
444 static int _addToArchive(FitsWriteData& data, table::io::Persistable const& object, std::string key,
445 std::string comment);
446
447 static int _addToArchive(FitsWriteData& data, std::shared_ptr<table::io::Persistable const> const& object,
448 std::string key, std::string comment);
449
460 FitsWriteData _startWriteFits(lsst::geom::Point2I const& xy0 = lsst::geom::Point2I()) const;
461
475 void _finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const;
476
478
479 // Implementation of setComponent
480 template <class T>
481 void _setComponent(typehandling::Key<std::string, std::shared_ptr<T>> const& key,
482 std::shared_ptr<T> const& object) {
483 if (_components->contains(key)) {
484 _components->erase(key);
485 } else if (_components->contains(key.getId())) {
486 std::stringstream buffer;
487 buffer << "Map has a key that conflicts with " << key;
489 }
490 try {
491 bool success = _components->insert(key, object);
492 if (!success) {
493 throw LSST_EXCEPT(
495 "Insertion failed for unknown reasons. There may be something in the logs.");
496 }
497 } catch (std::exception const& e) {
499 LSST_EXCEPT(pex::exceptions::RuntimeError, "Insertion raised an exception."));
500 }
501 }
502
503 std::optional<table::RecordId> _exposureId;
506
507 // Class invariant: all pointers in _components are not null
509};
510} // namespace image
511} // namespace afw
512} // namespace lsst
513
514#endif // !LSST_AFW_IMAGE_ExposureInfo_h_INCLUDED
char * data
Definition: BaseRecord.cc:61
table::Key< int > detector
#define LSST_EXCEPT(type,...)
Fits * fits
Definition: FitsWriter.cc:90
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:66
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
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:89
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?
void setFilterLabel(std::shared_ptr< FilterLabel const > filterLabel)
Set the exposure's filter information.
static typehandling::Key< std::string, std::shared_ptr< geom::SkyWcs const > > const KEY_WCS
Standard key for looking up the Wcs.
Definition: ExposureInfo.h:92
ExposureInfo & operator=(ExposureInfo const &other)
Assignment; shares all components.
void setFilter(Filter const &filter)
Set the exposure's filter.
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:98
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:257
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 >(), Filter const &filter=Filter(), 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.
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:322
std::shared_ptr< ApCorrMap const > getApCorrMap() const
Return the exposure's aperture correction map (null pointer if !hasApCorrMap())
std::shared_ptr< FilterLabel const > getFilterLabel() const
Return the exposure's filter information.
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
Filter getFilter() const
Return the exposure's filter.
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:101
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:302
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:336
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:96
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
bool hasFilterLabel() const
Does this exposure have filter information?
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:204
void setDetector(std::shared_ptr< cameraGeom::Detector const > detector)
Set the exposure's Detector information.
Definition: ExposureInfo.cc:83
bool hasVisitInfo() const
Does this exposure have visit info?
Definition: ExposureInfo.h:254
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:108
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:103
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:94
std::shared_ptr< CoaddInputs const > getCoaddInputs() const
Return a pair of catalogs that record the inputs, if this Exposure is a coadd (otherwise null).
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:201
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:105
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:251
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
Definition: ExposureInfo.h:110
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:354
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
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
class[[deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be " "removed after v22.")]] FilterProperty final
Describe the properties of a Filter (e.g.
Definition: Filter.h:53
std::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:21
A base class for image defects.
STL namespace.
T str(T... args)
Key< int > psf
Definition: Exposure.cc:65
Key< int > visitInfo
Definition: Exposure.cc:70
Key< int > photoCalib
Definition: Exposure.cc:67
Key< int > transmissionCurve
Definition: Exposure.cc:71
Key< int > apCorrMap
Definition: Exposure.cc:68
T throw_with_nested(T... args)