lsst.afw  16.0+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"
36 #include "lsst/afw/geom/SkyWcs.h"
38 #include "lsst/afw/detection/Psf.h"
39 #include "lsst/afw/image/Calib.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>
57  : daf::base::Citizen(typeid(this)), _maskedImage(dimensions), _info(new ExposureInfo(wcs)) {}
58 
59 template <typename ImageT, typename MaskT, typename VarianceT>
62  : daf::base::Citizen(typeid(this)), _maskedImage(bbox), _info(new ExposureInfo(wcs)) {}
63 
64 template <typename ImageT, typename MaskT, typename VarianceT>
67  : daf::base::Citizen(typeid(this)), _maskedImage(maskedImage), _info(new ExposureInfo(wcs)) {}
68 
69 template <typename ImageT, typename MaskT, typename VarianceT>
71  : daf::base::Citizen(typeid(this)),
72  _maskedImage(maskedImage),
73  _info(info ? info : std::make_shared<ExposureInfo>()) {}
74 
75 template <typename ImageT, typename MaskT, typename VarianceT>
77  : daf::base::Citizen(typeid(this)),
78  _maskedImage(src.getMaskedImage(), deep),
79  _info(new ExposureInfo(*src.getInfo(), deep)) {}
80 // Delegate to copy-constructor for backwards compatibility
81 template <typename ImageT, typename MaskT, typename VarianceT>
83 
84 template <typename ImageT, typename MaskT, typename VarianceT>
86  ImageOrigin const origin, bool const deep)
87  : daf::base::Citizen(typeid(this)),
88  _maskedImage(src.getMaskedImage(), bbox, origin, deep),
89  _info(new ExposureInfo(*src.getInfo(), deep)) {}
90 
91 template <typename ImageT, typename MaskT, typename VarianceT>
93  ImageOrigin origin, bool conformMasks)
94  : daf::base::Citizen(typeid(this)), _maskedImage(), _info(new ExposureInfo()) {
95  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
96  _readFits(fitsfile, bbox, origin, conformMasks);
97 }
98 
99 template <typename ImageT, typename MaskT, typename VarianceT>
101  ImageOrigin origin, bool conformMasks)
102  : daf::base::Citizen(typeid(this)), _maskedImage(), _info(new ExposureInfo()) {
103  fits::Fits fitsfile(manager, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
104  _readFits(fitsfile, bbox, origin, conformMasks);
105 }
106 
107 template <typename ImageT, typename MaskT, typename VarianceT>
109  ImageOrigin origin, bool conformMasks)
110  : daf::base::Citizen(typeid(this)) {
111  _readFits(fitsfile, bbox, origin, conformMasks);
112 }
113 
114 template <typename ImageT, typename MaskT, typename VarianceT>
116  ImageOrigin origin, bool conformMasks) {
119  _maskedImage = MaskedImageT(fitsfile, metadata, bbox, origin, conformMasks, false, imageMetadata);
120  _info->_readFits(fitsfile, metadata, imageMetadata);
121 }
122 
123 template <typename ImageT, typename MaskT, typename VarianceT>
125 
126 // SET METHODS
127 
128 template <typename ImageT, typename MaskT, typename VarianceT>
130  _maskedImage = maskedImage;
131 }
132 
133 template <typename ImageT, typename MaskT, typename VarianceT>
135  lsst::geom::Point2I old(_maskedImage.getXY0());
136  if (_info->hasWcs()) {
137  auto shift = lsst::geom::Extent2D(origin - old);
138  auto newWcs = _info->getWcs()->copyAtShiftedPixelOrigin(shift);
139  _info->setWcs(newWcs);
140  }
141  _maskedImage.setXY0(origin);
142 }
143 
144 template <typename ImageT, typename MaskT, typename VarianceT>
146 template <typename ImageT, typename MaskT, typename VarianceT>
148 
149 // Write FITS
150 
151 template <typename ImageT, typename MaskT, typename VarianceT>
153  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
154  writeFits(fitsfile);
155 }
156 
157 template <typename ImageT, typename MaskT, typename VarianceT>
159  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
160  writeFits(fitsfile);
161 }
162 
163 template <typename ImageT, typename MaskT, typename VarianceT>
165  writeFits(fitsfile, fits::ImageWriteOptions(*_maskedImage.getImage()),
166  fits::ImageWriteOptions(*_maskedImage.getMask()),
167  fits::ImageWriteOptions(*_maskedImage.getVariance()));
168 }
169 
170 template <typename ImageT, typename MaskT, typename VarianceT>
172  fits::ImageWriteOptions const &imageOptions,
173  fits::ImageWriteOptions const &maskOptions,
174  fits::ImageWriteOptions const &varianceOptions) const {
175  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
176  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
177 }
178 
179 template <typename ImageT, typename MaskT, typename VarianceT>
181  fits::ImageWriteOptions const &imageOptions,
182  fits::ImageWriteOptions const &maskOptions,
183  fits::ImageWriteOptions const &varianceOptions) const {
184  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
185  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
186 }
187 
188 template <typename ImageT, typename MaskT, typename VarianceT>
190  fits::ImageWriteOptions const &imageOptions,
191  fits::ImageWriteOptions const &maskOptions,
192  fits::ImageWriteOptions const &varianceOptions) 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 } // namespace image
208 } // namespace afw
209 } // namespace lsst
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:1067
Key< int > wcs
Definition: Exposure.cc:61
virtual ~Exposure()
Destructor.
char * data
Definition: BaseTable.cc:205
void setXY0(lsst::geom::Point2I const &origin)
Set the Exposure&#39;s origin (including correcting the Wcs)
Definition: Exposure.cc:134
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:218
std::shared_ptr< ExposureInfo > getInfo()
Get the ExposureInfo that aggregates all the non-image components. Never null.
Definition: Exposure.h:298
STL namespace.
lsst::geom::Point2I getXY0() const
Return the Exposure&#39;s origin.
Definition: Exposure.h:251
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:296
MaskedImage< ImageT, MaskT, VarianceT > MaskedImageT
Definition: Exposure.h:78
lsst::geom::Point2I getXY0() const
Return the image&#39;s origin.
Definition: MaskedImage.h:1098
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:1034
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:208
std::shared_ptr< RecordT > src
Definition: Match.cc:48
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:120
void setMaskedImage(MaskedImageT &maskedImage)
Set the MaskedImage of the Exposure.
Definition: Exposure.cc:129
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
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:1046
Citizen(const std::type_info &)
Exposure(unsigned int width, unsigned int height, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
Construct an Exposure with a blank MaskedImage of specified size (default 0x0) and a SkyWcs (which ma...
Definition: Exposure.cc:50
void setXY0(int const x0, int const y0)
Set the MaskedImage&#39;s origin.
Definition: MaskedImage.h:1108
table::Box2IKey bbox
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:152
Extent< double, 2 > Extent2D
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:87
Exposure & operator=(Exposure const &)