LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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/cstdint.hpp"
28 #include "boost/format.hpp"
29 #include "boost/shared_ptr.hpp"
30 #include "boost/algorithm/string/trim.hpp"
31 
34 #include "lsst/pex/exceptions.h"
35 #include "lsst/pex/logging/Trace.h"
38 #include "lsst/afw/detection/Psf.h"
39 #include "lsst/afw/image/Calib.h"
40 #include "lsst/afw/image/Wcs.h"
42 #include "lsst/afw/fits.h"
43 
44 namespace afwGeom = lsst::afw::geom;
45 namespace afwImage = lsst::afw::image;
46 namespace afwDetection = lsst::afw::detection;
47 namespace cameraGeom = lsst::afw::cameraGeom;
48 
78 // CLASS CONSTRUCTORS and DESTRUCTOR
79 
80 
84 template<typename ImageT, typename MaskT, typename VarianceT>
86  unsigned int width,
87  unsigned int height,
88  CONST_PTR(Wcs) wcs
89 ) :
90  lsst::daf::base::Citizen(typeid(this)),
91  _maskedImage(width, height),
92  _info(new ExposureInfo(wcs))
93 {}
94 
98 template<typename ImageT, typename MaskT, typename VarianceT>
100  afwGeom::Extent2I const & dimensions,
101  CONST_PTR(Wcs) wcs
102 ) :
103  lsst::daf::base::Citizen(typeid(this)),
104  _maskedImage(dimensions),
105  _info(new ExposureInfo(wcs))
106 {}
107 
111 template<typename ImageT, typename MaskT, typename VarianceT>
113  afwGeom::Box2I const & bbox,
114  CONST_PTR(Wcs) wcs
115 ) :
116  lsst::daf::base::Citizen(typeid(this)),
117  _maskedImage(bbox),
118  _info(new ExposureInfo(wcs))
119 {}
120 
123 template<typename ImageT, typename MaskT, typename VarianceT>
125  MaskedImageT &maskedImage,
126  CONST_PTR(Wcs) wcs
127 ) :
128  lsst::daf::base::Citizen(typeid(this)),
129  _maskedImage(maskedImage),
130  _info(new ExposureInfo(wcs))
131 {}
132 
133 
136 template<typename ImageT, typename MaskT, typename VarianceT>
138  Exposure const &src,
139  bool const deep
140 ) :
141  lsst::daf::base::Citizen(typeid(this)),
142  _maskedImage(src.getMaskedImage(), deep),
143  _info(new ExposureInfo(*src.getInfo(), deep))
144 {}
145 
151 template<typename ImageT, typename MaskT, typename VarianceT>
153  Exposure const &src,
154  afwGeom::Box2I const& bbox,
155  ImageOrigin const origin,
156  bool const deep
157 ) :
158  lsst::daf::base::Citizen(typeid(this)),
159  _maskedImage(src.getMaskedImage(), bbox, origin, deep),
160  _info(new ExposureInfo(*src.getInfo(), deep))
161 {}
162 
163 template<typename ImageT, typename MaskT, typename VarianceT>
165  std::string const & fileName, afwGeom::Box2I const& bbox,
166  ImageOrigin origin, bool conformMasks
167 ) :
168  lsst::daf::base::Citizen(typeid(this)),
169  _maskedImage(),
170  _info(new ExposureInfo())
171 {
172  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
173  _readFits(fitsfile, bbox, origin, conformMasks);
174 }
175 
176 template<typename ImageT, typename MaskT, typename VarianceT>
178  fits::MemFileManager & manager, afwGeom::Box2I const & bbox,
179  ImageOrigin origin, bool conformMasks
180 ) :
181  lsst::daf::base::Citizen(typeid(this)),
182  _maskedImage(),
183  _info(new ExposureInfo())
184 {
185  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
186  _readFits(fitsfile, bbox, origin, conformMasks);
187 }
188 
189 template<typename ImageT, typename MaskT, typename VarianceT>
191  fits::Fits & fitsfile, afwGeom::Box2I const & bbox,
192  ImageOrigin origin, bool conformMasks
193 ) :
194  lsst::daf::base::Citizen(typeid(this))
195 {
196  _readFits(fitsfile, bbox, origin, conformMasks);
197 }
198 
199 template<typename ImageT, typename MaskT, typename VarianceT>
201  fits::Fits & fitsfile, afwGeom::Box2I const & bbox,
202  ImageOrigin origin, bool conformMasks
203 ) {
206  _maskedImage = MaskedImageT(fitsfile, metadata, bbox, origin, conformMasks, false, imageMetadata);
207  _info->_readFits(fitsfile, metadata, imageMetadata);
208 }
209 
210 
213 template<typename ImageT, typename MaskT, typename VarianceT>
215 
216 // SET METHODS
217 
220 template<typename ImageT, typename MaskT, typename VarianceT>
222  _maskedImage = maskedImage;
223 }
224 
225 template<typename ImageT, typename MaskT, typename VarianceT>
227  afwGeom::Point2I old(_maskedImage.getXY0());
228  if (_info->hasWcs())
229  _info->getWcs()->shiftReferencePixel(origin.getX() - old.getX(), origin.getY() - old.getY());
230  _maskedImage.setXY0(origin);
231 }
232 
233 
234 // Write FITS
235 
236 template<typename ImageT, typename MaskT, typename VarianceT>
237 void afwImage::Exposure<ImageT, MaskT, VarianceT>::writeFits(std::string const & fileName) const {
238  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
239  writeFits(fitsfile);
240 }
241 
242 template<typename ImageT, typename MaskT, typename VarianceT>
244  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
245  writeFits(fitsfile);
246 }
247 
248 template<typename ImageT, typename MaskT, typename VarianceT>
250  ExposureInfo::FitsWriteData data = _info->_startWriteFits(getXY0());
251  _maskedImage.writeFits(
252  fitsfile, data.metadata,
254  );
255  _info->_finishWriteFits(fitsfile, data);
256 }
257 
258 // Explicit instantiations
261 template class afwImage::Exposure<int>;
262 template class afwImage::Exposure<float>;
263 template class afwImage::Exposure<double>;
boost::shared_ptr< daf::base::PropertyList > imageMetadata
Definition: ExposureInfo.h:229
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
Include files required for standard LSST Exception handling.
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:48
Interface for PropertyList class.
definition of the Trace messaging facilities
void setXY0(geom::Point2I const &origin)
Definition: Exposure.cc:226
#define PTR(...)
Definition: base.h:41
tbl::Key< int > wcs
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:237
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:194
void _readFits(fits::Fits &fitsfile, geom::Box2I const &bbox, ImageOrigin origin, bool conformMasks)
Definition: Exposure.cc:200
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:227
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:221
boost::shared_ptr< daf::base::PropertyList > maskMetadata
Definition: ExposureInfo.h:230
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:85
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
Class for storing generic metadata.
Definition: PropertySet.h:82
#define CONST_PTR(...)
Definition: base.h:47
Interface for PropertySet class.
boost::shared_ptr< daf::base::PropertyList > metadata
Definition: ExposureInfo.h:228
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:80
boost::shared_ptr< daf::base::PropertyList > varianceMetadata
Definition: ExposureInfo.h:231