LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
ExposureInfo.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*- // fixed format comment for emacs
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #include "lsst/pex/exceptions.h"
25 #include "lsst/log/Log.h"
29 #include "lsst/afw/geom/SkyWcs.h"
31 #include "lsst/afw/detection/Psf.h"
34 #include "lsst/afw/fits.h"
35 
36 namespace {
37 LOG_LOGGER _log = LOG_GET("afw.image.ExposureInfo");
38 } // namespace
39 
40 namespace lsst {
41 namespace afw {
42 namespace image {
43 
45  // Version history:
46  // unversioned and 0: photometric calibration via Calib, WCS via SkyWcs using AST.
47  // 1: photometric calibration via PhotoCalib
48  static int const version = 1;
49  return version;
50 }
51 
53  static std::string const versionName("EXPINFO_V");
54  return versionName;
55 }
56 
57 // Clone various components; defined here so that we don't have to expose their insides in Exposure.h
58 
60  if (apCorrMap) {
61  return std::make_shared<ApCorrMap>(*apCorrMap);
62  }
64 }
65 
73  std::shared_ptr<ApCorrMap> const& apCorrMap,
76  : _wcs(wcs),
77  _psf(std::const_pointer_cast<detection::Psf>(psf)),
78  _photoCalib(photoCalib),
79  _detector(detector),
80  _validPolygon(polygon),
81  _filter(filter),
82  _metadata(metadata ? metadata
83  : std::shared_ptr<daf::base::PropertySet>(new daf::base::PropertyList())),
84  _coaddInputs(coaddInputs),
85  _apCorrMap(_cloneApCorrMap(apCorrMap)),
86  _visitInfo(visitInfo),
87  _transmissionCurve(transmissionCurve) {}
88 
90  : _wcs(other._wcs),
91  _psf(other._psf),
92  _photoCalib(other._photoCalib),
93  _detector(other._detector),
94  _validPolygon(other._validPolygon),
95  _filter(other._filter),
96  _metadata(other._metadata),
97  _coaddInputs(other._coaddInputs),
98  _apCorrMap(_cloneApCorrMap(other._apCorrMap)),
99  _visitInfo(other._visitInfo),
100  _transmissionCurve(other._transmissionCurve) {}
101 
102 // Delegate to copy-constructor for backwards compatibility
104 
106  : _wcs(other._wcs),
107  _psf(other._psf),
108  _photoCalib(other._photoCalib),
109  _detector(other._detector),
110  _validPolygon(other._validPolygon),
111  _filter(other._filter),
112  _metadata(other._metadata),
113  _coaddInputs(other._coaddInputs),
114  _apCorrMap(_cloneApCorrMap(other._apCorrMap)),
115  _visitInfo(other._visitInfo),
116  _transmissionCurve(other._transmissionCurve) {
117  if (copyMetadata) _metadata = _metadata->deepCopy();
118 }
119 
121  if (&other != this) {
122  _wcs = other._wcs;
123  _psf = other._psf;
124  _photoCalib = other._photoCalib;
125  _detector = other._detector;
126  _validPolygon = other._validPolygon;
127  _filter = other._filter;
128  _metadata = other._metadata;
129  _coaddInputs = other._coaddInputs;
130  _apCorrMap = _cloneApCorrMap(other._apCorrMap);
131  _visitInfo = other._visitInfo;
132  _transmissionCurve = other._transmissionCurve;
133  }
134  return *this;
135 }
136 // Delegate to copy-assignment for backwards compatibility
138 
139 void ExposureInfo::initApCorrMap() { _apCorrMap = std::make_shared<ApCorrMap>(); }
140 
141 ExposureInfo::~ExposureInfo() = default;
142 
143 ExposureInfo::FitsWriteData ExposureInfo::_startWriteFits(lsst::geom::Point2I const& xy0) const {
144  FitsWriteData data;
145 
146  data.metadata.reset(new daf::base::PropertyList());
147  data.imageMetadata.reset(new daf::base::PropertyList());
148  data.maskMetadata = data.imageMetadata;
149  data.varianceMetadata = data.imageMetadata;
150 
151  data.metadata->combine(getMetadata());
152 
154 
155  // In the future, we might not have exactly three image HDUs, but we always do right now,
156  // so 0=primary, 1=image, 2=mask, 3=variance, 4+=archive
157  //
158  // Historically the AR_HDU keyword was 1-indexed (see RFC-304), and to maintain file compatibility
159  // this is still the case so we're setting AR_HDU to 5 == 4 + 1
160  //
161  data.metadata->set("AR_HDU", 5, "HDU (1-indexed) containing the archive used to store ancillary objects");
162  if (hasCoaddInputs()) {
163  int coaddInputsId = data.archive.put(getCoaddInputs());
164  data.metadata->set("COADD_INPUTS_ID", coaddInputsId, "archive ID for coadd inputs catalogs");
165  }
166  if (hasApCorrMap()) {
167  int apCorrMapId = data.archive.put(getApCorrMap());
168  data.metadata->set("AP_CORR_MAP_ID", apCorrMapId, "archive ID for aperture correction map");
169  }
170  if (hasPsf() && getPsf()->isPersistable()) {
171  int psfId = data.archive.put(getPsf());
172  data.metadata->set("PSF_ID", psfId, "archive ID for the Exposure's main Psf");
173  }
174  if (hasWcs() && getWcs()->isPersistable()) {
175  int wcsId = data.archive.put(getWcs());
176  data.metadata->set("SKYWCS_ID", wcsId, "archive ID for the Exposure's main Wcs");
177  }
178  if (hasValidPolygon() && getValidPolygon()->isPersistable()) {
179  int polygonId = data.archive.put(getValidPolygon());
180  data.metadata->set("VALID_POLYGON_ID", polygonId, "archive ID for the Exposure's valid polygon");
181  }
182  if (hasTransmissionCurve() && getTransmissionCurve()->isPersistable()) {
183  int transmissionCurveId = data.archive.put(getTransmissionCurve());
184  data.metadata->set("TRANSMISSION_CURVE_ID", transmissionCurveId,
185  "archive ID for the Exposure's transmission curve");
186  }
187  if (hasDetector() && getDetector()->isPersistable()) {
188  int detectorId = data.archive.put(getDetector());
189  data.metadata->set("DETECTOR_ID", detectorId, "archive ID for the Exposure's Detector");
190  }
191  if (hasPhotoCalib()) {
192  int photoCalibId = data.archive.put(getPhotoCalib());
193  data.metadata->set("PHOTOCALIB_ID", photoCalibId, "archive ID for photometric calibration");
194  }
195 
196  // LSST convention is that Wcs is in pixel coordinates (i.e relative to bottom left
197  // corner of parent image, if any). The Wcs/Fits convention is that the Wcs is in
198  // image coordinates. When saving an image we convert from pixel to index coordinates.
199  // In the case where this image is a parent image, the reference pixels are unchanged
200  // by this transformation
201  if (hasWcs()) {
202  // Try to save the WCS as FITS-WCS metadata; if an exact representation
203  // is not possible then skip it
204  auto shift = lsst::geom::Extent2D(lsst::geom::Point2I(0, 0) - xy0);
205  auto newWcs = getWcs()->copyAtShiftedPixelOrigin(shift);
207  try {
208  wcsMetadata = newWcs->getFitsMetadata(true);
210  // cannot represent this WCS as FITS-WCS; don't write its metadata
211  }
212  if (wcsMetadata) {
213  data.imageMetadata->combine(newWcs->getFitsMetadata(true));
214  }
215  }
216 
217  // For the sake of ds9, store _x0 and _y0 as -LTV1, -LTV2.
218  // This is in addition to saving _x0 and _y0 as WCS A, which is done elsewhere
219  // and is what LSST uses to read _x0 and _y0.
220  // LTV is a convention used by STScI (see \S2.6.2 of HST Data Handbook for STIS, version 5.0
221  // http://www.stsci.edu/hst/stis/documents/handbooks/currentDHB/ch2_stis_data7.html#429287)
222  // and recognized by ds9.
223  data.imageMetadata->set("LTV1", static_cast<double>(-xy0.getX()));
224  data.imageMetadata->set("LTV2", static_cast<double>(-xy0.getY()));
225 
226  data.metadata->set("FILTER", getFilter().getName());
227  if (hasDetector()) {
228  data.metadata->set("DETNAME", getDetector()->getName());
229  data.metadata->set("DETSER", getDetector()->getSerial());
230  }
231 
232  auto visitInfoPtr = getVisitInfo();
233  if (visitInfoPtr) {
234  detail::setVisitInfoMetadata(*(data.metadata), *visitInfoPtr);
235  }
236 
237  return data;
238 }
239 
240 void ExposureInfo::_finishWriteFits(fits::Fits& fitsfile, FitsWriteData const& data) const {
241  data.archive.writeFits(fitsfile);
242 }
243 
244 } // namespace image
245 } // namespace afw
246 } // namespace lsst
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
Definition: ExposureInfo.cc:52
bool hasTransmissionCurve() const
Does this exposure have a transmission curve?
Definition: ExposureInfo.h:207
#define LOG_LOGGER
Definition: Log.h:688
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68
std::shared_ptr< PhotoCalib const > getPhotoCalib() const
Return the exposure&#39;s photometric calibration.
Definition: ExposureInfo.h:118
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Return the exposure&#39;s visit info.
Definition: ExposureInfo.h:198
bool hasPsf() const
Does this exposure have a Psf?
Definition: ExposureInfo.h:147
STL namespace.
std::shared_ptr< ApCorrMap > getApCorrMap()
Return the exposure&#39;s aperture correction map (null pointer if !hasApCorrMap())
Definition: ExposureInfo.h:172
bool hasDetector() const
Does this exposure have Detector information?
Definition: ExposureInfo.h:100
static int getFitsSerializationVersion()
Get the version of FITS serialization that this ExposureInfo understands.
Definition: ExposureInfo.cc:44
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
bool hasWcs() const
Does this exposure have a Wcs?
Definition: ExposureInfo.h:91
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
STL class.
LSST DM logging module built on log4cxx.
ExposureInfo & operator=(ExposureInfo const &other)
Assignment; deep-copies all components except the metadata.
void setVisitInfoMetadata(daf::base::PropertyList &metadata, VisitInfo const &visitInfo)
Set FITS metadata from a VisitInfo.
Definition: VisitInfo.cc:283
bool hasApCorrMap() const
Return true if the exposure has an aperture correction map.
Definition: ExposureInfo.h:169
A base class for image defects.
std::shared_ptr< detection::Psf > getPsf() const
Return the exposure&#39;s point-spread function.
Definition: ExposureInfo.h:150
char * data
Definition: BaseRecord.cc:62
void initApCorrMap()
Set the exposure&#39;s aperture correction map to a new, empty map.
bool hasValidPolygon() const
Does this exposure have a valid Polygon.
Definition: ExposureInfo.h:160
table::Key< int > detector
std::shared_ptr< geom::polygon::Polygon const > getValidPolygon() const
Return the valid Polygon.
Definition: ExposureInfo.h:163
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
std::shared_ptr< cameraGeom::Detector const > getDetector() const
Return the exposure&#39;s Detector information.
Definition: ExposureInfo.h:103
bool hasPhotoCalib() const
Does this exposure have a photometric calibration?
Definition: ExposureInfo.h:115
ItemVariant const * other
Definition: Schema.cc:56
table::Key< int > version
Definition: PhotoCalib.cc:402
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.
Definition: ExposureInfo.cc:66
Extent< double, 2 > Extent2D
Definition: Extent.h:400
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
#define LOG_GET(logger)
Returns a Log object associated with logger.
Definition: Log.h:75
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:88
std::shared_ptr< CoaddInputs > getCoaddInputs() const
Return a pair of catalogs that record the inputs, if this Exposure is a coadd (otherwise null)...
Definition: ExposureInfo.h:195
Implementation of the Photometric Calibration class.
std::shared_ptr< geom::SkyWcs const > getWcs() const
Return the WCS of the exposure.
Definition: ExposureInfo.h:94
Filter getFilter() const
Return the exposure&#39;s filter.
Definition: ExposureInfo.h:109
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
bool hasCoaddInputs() const
Does this exposure have coadd provenance catalogs?
Definition: ExposureInfo.h:189
std::shared_ptr< TransmissionCurve const > getTransmissionCurve() const
Return the exposure&#39;s transmission curve.
Definition: ExposureInfo.h:210