lsst.afw  14.0-25-g0e8fc950e+5
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 
78 template <typename ImageT, typename MaskT, typename VarianceT>
80  ImageOrigin const origin, bool const deep)
81  : daf::base::Citizen(typeid(this)),
82  _maskedImage(src.getMaskedImage(), bbox, origin, deep),
83  _info(new ExposureInfo(*src.getInfo(), deep)) {}
84 
85 template <typename ImageT, typename MaskT, typename VarianceT>
87  ImageOrigin origin, bool conformMasks)
88  : daf::base::Citizen(typeid(this)), _maskedImage(), _info(new ExposureInfo()) {
89  fits::Fits fitsfile(fileName, "r", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
90  _readFits(fitsfile, bbox, origin, conformMasks);
91 }
92 
93 template <typename ImageT, typename MaskT, typename VarianceT>
95  ImageOrigin origin, bool conformMasks)
96  : daf::base::Citizen(typeid(this)), _maskedImage(), _info(new ExposureInfo()) {
98  _readFits(fitsfile, bbox, origin, conformMasks);
99 }
100 
101 template <typename ImageT, typename MaskT, typename VarianceT>
103  ImageOrigin origin, bool conformMasks)
104  : daf::base::Citizen(typeid(this)) {
105  _readFits(fitsfile, bbox, origin, conformMasks);
106 }
107 
108 template <typename ImageT, typename MaskT, typename VarianceT>
110  ImageOrigin origin, bool conformMasks) {
113  _maskedImage = MaskedImageT(fitsfile, metadata, bbox, origin, conformMasks, false, imageMetadata);
114  _info->_readFits(fitsfile, metadata, imageMetadata);
115 }
116 
117 template <typename ImageT, typename MaskT, typename VarianceT>
119 
120 // SET METHODS
121 
122 template <typename ImageT, typename MaskT, typename VarianceT>
124  _maskedImage = maskedImage;
125 }
126 
127 template <typename ImageT, typename MaskT, typename VarianceT>
129  geom::Point2I old(_maskedImage.getXY0());
130  if (_info->hasWcs())
131  _info->getWcs()->shiftReferencePixel(origin.getX() - old.getX(), origin.getY() - old.getY());
132  _maskedImage.setXY0(origin);
133 }
134 
135 // Write FITS
136 
137 template <typename ImageT, typename MaskT, typename VarianceT>
139  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
140  writeFits(fitsfile);
141 }
142 
143 template <typename ImageT, typename MaskT, typename VarianceT>
145  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
146  writeFits(fitsfile);
147 }
148 
149 template <typename ImageT, typename MaskT, typename VarianceT>
151  writeFits(fitsfile, fits::ImageWriteOptions(*_maskedImage.getImage()),
152  fits::ImageWriteOptions(*_maskedImage.getMask()),
153  fits::ImageWriteOptions(*_maskedImage.getVariance()));
154 }
155 
156 template <typename ImageT, typename MaskT, typename VarianceT>
158  std::string const& fileName,
159  fits::ImageWriteOptions const& imageOptions,
160  fits::ImageWriteOptions const& maskOptions,
161  fits::ImageWriteOptions const& varianceOptions
162 ) const {
163  fits::Fits fitsfile(fileName, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
164  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
165 }
166 
167 template <typename ImageT, typename MaskT, typename VarianceT>
169  fits::MemFileManager& manager,
170  fits::ImageWriteOptions const& imageOptions,
171  fits::ImageWriteOptions const& maskOptions,
172  fits::ImageWriteOptions const& varianceOptions
173 ) const {
174  fits::Fits fitsfile(manager, "w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
175  writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
176 }
177 
178 template <typename ImageT, typename MaskT, typename VarianceT>
180  fits::Fits &fitsfile,
181  fits::ImageWriteOptions const& imageOptions,
182  fits::ImageWriteOptions const& maskOptions,
183  fits::ImageWriteOptions const& varianceOptions
184 ) const {
185  ExposureInfo::FitsWriteData data = _info->_startWriteFits(getXY0());
186  _maskedImage.writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, data.metadata,
187  data.imageMetadata, data.maskMetadata, data.varianceMetadata);
188  _info->_finishWriteFits(fitsfile, data);
189 }
190 
191 // Explicit instantiations
193 template class Exposure<std::uint16_t>;
194 template class Exposure<int>;
195 template class Exposure<float>;
196 template class Exposure<double>;
197 template class Exposure<std::uint64_t>;
199 }
200 }
201 } // end lsst::afw::image
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:1074
virtual ~Exposure()
Destructor.
Definition: Exposure.cc:118
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:201
std::shared_ptr< ExposureInfo > getInfo()
Get the ExposureInfo that aggregates all the non-image components. Never null.
Definition: Exposure.h:294
void setXY0(geom::Point2I const &origin)
Set the Exposure&#39;s origin (including correcting the Wcs)
Definition: Exposure.cc:128
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:279
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:1041
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:205
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:101
void setMaskedImage(MaskedImageT &maskedImage)
Set the MaskedImage of the Exposure.
Definition: Exposure.cc:123
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:481
geom::Point2I getXY0() const
Return the Exposure&#39;s origin.
Definition: Exposure.h:249
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:1053
Citizen(const std::type_info &)
void setXY0(int const x0, int const y0)
Set the MaskedImage&#39;s origin.
Definition: MaskedImage.h:1115
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:138
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:86
geom::Point2I getXY0() const
Return the image&#39;s origin.
Definition: MaskedImage.h:1105