LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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 
132 
135 template<typename ImageT, typename MaskT, typename VarianceT>
137  Exposure const &src,
138  bool const deep
139 ) :
140  lsst::daf::base::Citizen(typeid(this)),
141  _maskedImage(src.getMaskedImage(), deep),
142  _info(new ExposureInfo(*src.getInfo(), deep))
143 {}
144 
150 template<typename ImageT, typename MaskT, typename VarianceT>
152  Exposure const &src,
153  afwGeom::Box2I const& bbox,
154  ImageOrigin const origin,
155  bool const deep
156 ) :
157  lsst::daf::base::Citizen(typeid(this)),
158  _maskedImage(src.getMaskedImage(), bbox, origin, deep),
159  _info(new ExposureInfo(*src.getInfo(), deep))
160 {}
161 
162 template<typename ImageT, typename MaskT, typename VarianceT>
164  std::string const & fileName, afwGeom::Box2I const& bbox,
165  ImageOrigin origin, bool conformMasks
166 ) :
167  lsst::daf::base::Citizen(typeid(this)),
168  _maskedImage(),
169  _info(new ExposureInfo())
170 {
171  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
172  _readFits(fitsfile, bbox, origin, conformMasks);
173 }
174 
175 template<typename ImageT, typename MaskT, typename VarianceT>
177  fits::MemFileManager & manager, 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(manager, "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::Fits & fitsfile, afwGeom::Box2I const & bbox,
191  ImageOrigin origin, bool conformMasks
192 ) :
193  lsst::daf::base::Citizen(typeid(this))
194 {
195  _readFits(fitsfile, bbox, origin, conformMasks);
196 }
197 
198 template<typename ImageT, typename MaskT, typename VarianceT>
200  fits::Fits & fitsfile, afwGeom::Box2I const & bbox,
201  ImageOrigin origin, bool conformMasks
202 ) {
205  _maskedImage = MaskedImageT(fitsfile, metadata, bbox, origin, conformMasks, false, imageMetadata);
206  _info->_readFits(fitsfile, metadata, imageMetadata);
207 }
208 
209 
212 template<typename ImageT, typename MaskT, typename VarianceT>
214 
215 // SET METHODS
216 
219 template<typename ImageT, typename MaskT, typename VarianceT>
221  _maskedImage = maskedImage;
222 }
223 
224 template<typename ImageT, typename MaskT, typename VarianceT>
226  afwGeom::Point2I old(_maskedImage.getXY0());
227  if (_info->hasWcs())
228  _info->getWcs()->shiftReferencePixel(origin.getX() - old.getX(), origin.getY() - old.getY());
229  _maskedImage.setXY0(origin);
230 }
231 
232 
233 // Write FITS
234 
235 template<typename ImageT, typename MaskT, typename VarianceT>
236 void afwImage::Exposure<ImageT, MaskT, VarianceT>::writeFits(std::string const & fileName) const {
237  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
238  writeFits(fitsfile);
239 }
240 
241 template<typename ImageT, typename MaskT, typename VarianceT>
243  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
244  writeFits(fitsfile);
245 }
246 
247 template<typename ImageT, typename MaskT, typename VarianceT>
249  ExposureInfo::FitsWriteData data = _info->_startWriteFits(getXY0());
250  _maskedImage.writeFits(
251  fitsfile, data.metadata,
253  );
254  _info->_finishWriteFits(fitsfile, data);
255 }
256 
257 // Explicit instantiations
259 template class afwImage::Exposure<std::uint16_t>;
260 template class afwImage::Exposure<int>;
261 template class afwImage::Exposure<float>;
262 template class afwImage::Exposure<double>;
263 template class afwImage::Exposure<std::uint64_t>;
boost::shared_ptr< daf::base::PropertyList > imageMetadata
Definition: ExposureInfo.h:229
Class for storing ordered metadata with comments.
Definition: PropertyList.h:82
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)
Definition: Exposure.cc:225
tbl::Key< int > wcs
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:236
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
#define CONST_PTR(...)
Definition: base.h:47
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:201
void _readFits(fits::Fits &fitsfile, geom::Box2I const &bbox, ImageOrigin origin, bool conformMasks)
Definition: Exposure.cc:199
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
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:105
void setMaskedImage(MaskedImageT &maskedImage)
Set the MaskedImage of the Exposure.
Definition: Exposure.cc:220
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:84
Class for storing generic metadata.
Definition: PropertySet.h:82
#define PTR(...)
Definition: base.h:41
Interface for PropertySet class.
Include files required for standard LSST Exception handling.
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