lsst.afw  14.0-42-g99f9a3040+1
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 lsst {
44 namespace afw {
45 namespace image {
46 
47 // CLASS CONSTRUCTORS and DESTRUCTOR
48 
49 template <typename ImageT, typename MaskT, typename VarianceT>
50 Exposure<ImageT, MaskT, VarianceT>::Exposure(unsigned int width, unsigned int height,
52  : daf::base::Citizen(typeid(this)), _maskedImage(width, height), _info(new ExposureInfo(wcs)) {}
53 
54 template <typename ImageT, typename MaskT, typename VarianceT>
56  : daf::base::Citizen(typeid(this)), _maskedImage(dimensions), _info(new ExposureInfo(wcs)) {}
57 
58 template <typename ImageT, typename MaskT, typename VarianceT>
60  : daf::base::Citizen(typeid(this)), _maskedImage(bbox), _info(new ExposureInfo(wcs)) {}
61 
62 template <typename ImageT, typename MaskT, typename VarianceT>
64  : daf::base::Citizen(typeid(this)), _maskedImage(maskedImage), _info(new ExposureInfo(wcs)) {}
65 
66 template <typename ImageT, typename MaskT, typename VarianceT>
68  : daf::base::Citizen(typeid(this)),
69  _maskedImage(maskedImage),
70  _info(info ? info : std::make_shared<ExposureInfo>()) {}
71 
72 template <typename ImageT, typename MaskT, typename VarianceT>
74  : daf::base::Citizen(typeid(this)),
75  _maskedImage(src.getMaskedImage(), deep),
76  _info(new ExposureInfo(*src.getInfo(), deep)) {}
77 // Delegate to copy-constructor for backwards compatibility
78 template <typename ImageT, typename MaskT, typename VarianceT>
80 
81 template <typename ImageT, typename MaskT, typename VarianceT>
83  ImageOrigin const origin, bool const deep)
84  : daf::base::Citizen(typeid(this)),
85  _maskedImage(src.getMaskedImage(), bbox, origin, deep),
86  _info(new ExposureInfo(*src.getInfo(), deep)) {}
87 
88 template <typename ImageT, typename MaskT, typename VarianceT>
90  ImageOrigin origin, bool conformMasks)
91  : daf::base::Citizen(typeid(this)), _maskedImage(), _info(new ExposureInfo()) {
92  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
93  _readFits(fitsfile, bbox, origin, conformMasks);
94 }
95 
96 template <typename ImageT, typename MaskT, typename VarianceT>
98  ImageOrigin origin, bool conformMasks)
99  : daf::base::Citizen(typeid(this)), _maskedImage(), _info(new ExposureInfo()) {
100  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
101  _readFits(fitsfile, bbox, origin, conformMasks);
102 }
103 
104 template <typename ImageT, typename MaskT, typename VarianceT>
106  ImageOrigin origin, bool conformMasks)
107  : daf::base::Citizen(typeid(this)) {
108  _readFits(fitsfile, bbox, origin, conformMasks);
109 }
110 
111 template <typename ImageT, typename MaskT, typename VarianceT>
113  ImageOrigin origin, bool conformMasks) {
116  _maskedImage = MaskedImageT(fitsfile, metadata, bbox, origin, conformMasks, false, imageMetadata);
117  _info->_readFits(fitsfile, metadata, imageMetadata);
118 }
119 
120 template <typename ImageT, typename MaskT, typename VarianceT>
122 
123 // SET METHODS
124 
125 template <typename ImageT, typename MaskT, typename VarianceT>
127  _maskedImage = maskedImage;
128 }
129 
130 template <typename ImageT, typename MaskT, typename VarianceT>
132  geom::Point2I old(_maskedImage.getXY0());
133  if (_info->hasWcs())
134  _info->getWcs()->shiftReferencePixel(origin.getX() - old.getX(), origin.getY() - old.getY());
135  _maskedImage.setXY0(origin);
136 }
137 
138 template <typename ImageT, typename MaskT, typename VarianceT>
140 template <typename ImageT, typename MaskT, typename VarianceT>
142 
143 // Write FITS
144 
145 template <typename ImageT, typename MaskT, typename VarianceT>
147  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
148  writeFits(fitsfile);
149 }
150 
151 template <typename ImageT, typename MaskT, typename VarianceT>
153  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
154  writeFits(fitsfile);
155 }
156 
157 template <typename ImageT, typename MaskT, typename VarianceT>
159  writeFits(fitsfile, fits::ImageWriteOptions(*_maskedImage.getImage()),
160  fits::ImageWriteOptions(*_maskedImage.getMask()),
161  fits::ImageWriteOptions(*_maskedImage.getVariance()));
162 }
163 
164 template <typename ImageT, typename MaskT, typename VarianceT>
166  std::string const& fileName,
167  fits::ImageWriteOptions const& imageOptions,
168  fits::ImageWriteOptions const& maskOptions,
169  fits::ImageWriteOptions const& varianceOptions
170 ) const {
171  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
172  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
173 }
174 
175 template <typename ImageT, typename MaskT, typename VarianceT>
177  fits::MemFileManager& manager,
178  fits::ImageWriteOptions const& imageOptions,
179  fits::ImageWriteOptions const& maskOptions,
180  fits::ImageWriteOptions const& varianceOptions
181 ) const {
182  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
183  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
184 }
185 
186 template <typename ImageT, typename MaskT, typename VarianceT>
188  fits::Fits &fitsfile,
189  fits::ImageWriteOptions const& imageOptions,
190  fits::ImageWriteOptions const& maskOptions,
191  fits::ImageWriteOptions const& varianceOptions
192 ) const {
193  ExposureInfo::FitsWriteData data = _info->_startWriteFits(getXY0());
194  _maskedImage.writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, data.metadata,
195  data.imageMetadata, data.maskMetadata, data.varianceMetadata);
196  _info->_finishWriteFits(fitsfile, data);
197 }
198 
199 // Explicit instantiations
201 template class Exposure<std::uint16_t>;
202 template class Exposure<int>;
203 template class Exposure<float>;
204 template class Exposure<double>;
205 template class Exposure<std::uint64_t>;
207 }
208 }
209 } // end lsst::afw::image
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:1075
virtual ~Exposure()
Destructor.
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:76
Options for writing an image to FITS.
Definition: fits.h:202
std::shared_ptr< ExposureInfo > getInfo()
Get the ExposureInfo that aggregates all the non-image components. Never null.
Definition: Exposure.h:298
void setXY0(geom::Point2I const &origin)
Set the Exposure&#39;s origin (including correcting the Wcs)
Definition: Exposure.cc:131
STL namespace.
Exposure(unsigned int width, unsigned int height, std::shared_ptr< Wcs const > wcs=std::shared_ptr< Wcs const >())
Construct an Exposure with a blank MaskedImage of specified size (default 0x0) and a Wcs (which may b...
Definition: Exposure.cc:50
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:280
MaskedImage< ImageT, MaskT, VarianceT > MaskedImageT
Definition: Exposure.h:78
An integer coordinate rectangle.
Definition: Box.h:55
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:1042
STL class.
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:44
A base class for image defects.
MaskedImageT getMaskedImage()
Return the MaskedImage.
Definition: Exposure.h:209
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:102
void setMaskedImage(MaskedImageT &maskedImage)
Set the MaskedImage of the Exposure.
Definition: Exposure.cc:126
void writeFits(std::string const &fileName, std::shared_ptr< daf::base::PropertySet const > metadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > imageMetadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > maskMetadata=std::shared_ptr< daf::base::PropertySet const >(), std::shared_ptr< daf::base::PropertySet const > varianceMetadata=std::shared_ptr< daf::base::PropertySet const >()) const
Write a MaskedImage to a regular FITS file.
Definition: MaskedImage.cc:486
geom::Point2I getXY0() const
Return the Exposure&#39;s origin.
Definition: Exposure.h:253
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:1054
Citizen(const std::type_info &)
void setXY0(int const x0, int const y0)
Set the MaskedImage&#39;s origin.
Definition: MaskedImage.h:1116
table::Box2IKey bbox
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:146
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:87
Exposure & operator=(Exposure const &)
geom::Point2I getXY0() const
Return the image&#39;s origin.
Definition: MaskedImage.h:1106