LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
Exposure.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*- // fixed format comment for emacs
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #include <stdexcept>
26 
27 #include "boost/format.hpp"
28 #include <memory>
29 #include <cstdint>
30 #include "boost/algorithm/string/trim.hpp"
31 
34 #include "lsst/pex/exceptions.h"
37 #include "lsst/afw/detection/Psf.h"
38 #include "lsst/afw/image/Calib.h"
39 #include "lsst/afw/image/Wcs.h"
41 #include "lsst/afw/fits.h"
42 
43 namespace afwGeom = lsst::afw::geom;
44 namespace afwImage = lsst::afw::image;
45 namespace afwDetection = lsst::afw::detection;
46 namespace cameraGeom = lsst::afw::cameraGeom;
47 
77 // CLASS CONSTRUCTORS and DESTRUCTOR
78 
79 
83 template<typename ImageT, typename MaskT, typename VarianceT>
85  unsigned int width,
86  unsigned int height,
87  CONST_PTR(Wcs) wcs
88 ) :
89  lsst::daf::base::Citizen(typeid(this)),
90  _maskedImage(width, height),
91  _info(new ExposureInfo(wcs))
92 {}
93 
97 template<typename ImageT, typename MaskT, typename VarianceT>
100  CONST_PTR(Wcs) wcs
101 ) :
102  lsst::daf::base::Citizen(typeid(this)),
103  _maskedImage(dimensions),
104  _info(new ExposureInfo(wcs))
105 {}
106 
110 template<typename ImageT, typename MaskT, typename VarianceT>
112  afwGeom::Box2I const & bbox,
113  CONST_PTR(Wcs) wcs
114 ) :
115  lsst::daf::base::Citizen(typeid(this)),
116  _maskedImage(bbox),
117  _info(new ExposureInfo(wcs))
118 {}
119 
122 template<typename ImageT, typename MaskT, typename VarianceT>
124  MaskedImageT &maskedImage,
125  CONST_PTR(Wcs) wcs
126 ) :
127  lsst::daf::base::Citizen(typeid(this)),
128  _maskedImage(maskedImage),
129  _info(new ExposureInfo(wcs))
130 {}
131 
136 template<typename ImageT, typename MaskT, typename VarianceT>
138  MaskedImageT & maskedImage,
140 ) :
141  lsst::daf::base::Citizen(typeid(this)),
142  _maskedImage(maskedImage),
143  _info(info ? info : std::make_shared<ExposureInfo>())
144 {}
145 
148 template<typename ImageT, typename MaskT, typename VarianceT>
150  Exposure const &src,
151  bool const deep
152 ) :
153  lsst::daf::base::Citizen(typeid(this)),
154  _maskedImage(src.getMaskedImage(), deep),
155  _info(new ExposureInfo(*src.getInfo(), deep))
156 {}
157 
163 template<typename ImageT, typename MaskT, typename VarianceT>
165  Exposure const &src,
166  afwGeom::Box2I const& bbox,
167  ImageOrigin const origin,
168  bool const deep
169 ) :
170  lsst::daf::base::Citizen(typeid(this)),
171  _maskedImage(src.getMaskedImage(), bbox, origin, deep),
172  _info(new ExposureInfo(*src.getInfo(), deep))
173 {}
174 
175 template<typename ImageT, typename MaskT, typename VarianceT>
177  std::string const & fileName, afwGeom::Box2I const& bbox,
178  ImageOrigin origin, bool conformMasks
179 ) :
180  lsst::daf::base::Citizen(typeid(this)),
181  _maskedImage(),
182  _info(new ExposureInfo())
183 {
184  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
185  _readFits(fitsfile, bbox, origin, conformMasks);
186 }
187 
188 template<typename ImageT, typename MaskT, typename VarianceT>
190  fits::MemFileManager & manager, afwGeom::Box2I const & bbox,
191  ImageOrigin origin, bool conformMasks
192 ) :
193  lsst::daf::base::Citizen(typeid(this)),
194  _maskedImage(),
195  _info(new ExposureInfo())
196 {
197  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
198  _readFits(fitsfile, bbox, origin, conformMasks);
199 }
200 
201 template<typename ImageT, typename MaskT, typename VarianceT>
203  fits::Fits & fitsfile, afwGeom::Box2I const & bbox,
204  ImageOrigin origin, bool conformMasks
205 ) :
206  lsst::daf::base::Citizen(typeid(this))
207 {
208  _readFits(fitsfile, bbox, origin, conformMasks);
209 }
210 
211 template<typename ImageT, typename MaskT, typename VarianceT>
213  fits::Fits & fitsfile, afwGeom::Box2I const & bbox,
214  ImageOrigin origin, bool conformMasks
215 ) {
218  _maskedImage = MaskedImageT(fitsfile, metadata, bbox, origin, conformMasks, false, imageMetadata);
219  _info->_readFits(fitsfile, metadata, imageMetadata);
220 }
221 
222 
225 template<typename ImageT, typename MaskT, typename VarianceT>
227 
228 // SET METHODS
229 
232 template<typename ImageT, typename MaskT, typename VarianceT>
234  _maskedImage = maskedImage;
235 }
236 
237 template<typename ImageT, typename MaskT, typename VarianceT>
239  afwGeom::Point2I old(_maskedImage.getXY0());
240  if (_info->hasWcs())
241  _info->getWcs()->shiftReferencePixel(origin.getX() - old.getX(), origin.getY() - old.getY());
242  _maskedImage.setXY0(origin);
243 }
244 
245 
246 // Write FITS
247 
248 template<typename ImageT, typename MaskT, typename VarianceT>
249 void afwImage::Exposure<ImageT, MaskT, VarianceT>::writeFits(std::string const & fileName) const {
250  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
251  writeFits(fitsfile);
252 }
253 
254 template<typename ImageT, typename MaskT, typename VarianceT>
256  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
257  writeFits(fitsfile);
258 }
259 
260 template<typename ImageT, typename MaskT, typename VarianceT>
262  ExposureInfo::FitsWriteData data = _info->_startWriteFits(getXY0());
263  _maskedImage.writeFits(
264  fitsfile, data.metadata,
266  );
267  _info->_finishWriteFits(fitsfile, data);
268 }
269 
270 // Explicit instantiations
272 template class afwImage::Exposure<std::uint16_t>;
273 template class afwImage::Exposure<int>;
274 template class afwImage::Exposure<float>;
275 template class afwImage::Exposure<double>;
276 template class afwImage::Exposure<std::uint64_t>;
virtual ~Exposure()
Destructor.
Definition: Exposure.cc:226
boost::shared_ptr< daf::base::PropertyList > imageMetadata
Definition: ExposureInfo.h:242
Class for storing ordered metadata with comments.
Definition: PropertyList.h:82
Include files required for standard LSST Exception handling.
def info
Definition: log.py:95
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:46
Interface for PropertyList class.
void setXY0(geom::Point2I const &origin)
Set the Exposure&#39;s origin (including correcting the Wcs)
Definition: Exposure.cc:238
tbl::Key< int > wcs
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:249
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:202
void _readFits(fits::Fits &fitsfile, geom::Box2I const &bbox, ImageOrigin origin, bool conformMasks)
Definition: Exposure.cc:212
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:42
A struct passed back and forth between Exposure and ExposureInfo when writing FITS files...
Definition: ExposureInfo.h:240
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:106
void setMaskedImage(MaskedImageT &maskedImage)
Set the MaskedImage of the Exposure.
Definition: Exposure.cc:233
boost::shared_ptr< daf::base::PropertyList > maskMetadata
Definition: ExposureInfo.h:243
Exposure(unsigned int width, unsigned int height, boost::shared_ptr< Wcs const > wcs=boost::shared_ptr< Wcs const >())
Exposure Class Implementation for LSST: a templated framework class for creating an Exposure from a M...
Definition: Exposure.cc:84
Classes to support calibration (e.g.
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
Utilities for working with FITS files.
#define PTR(...)
Definition: base.h:41
Class for storing generic metadata.
Definition: PropertySet.h:82
Interface for PropertySet class.
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
boost::shared_ptr< daf::base::PropertyList > metadata
Definition: ExposureInfo.h:241
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:83
boost::shared_ptr< daf::base::PropertyList > varianceMetadata
Definition: ExposureInfo.h:244