lsst.afw  13.0-73-gb2a4e38
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
32 #include "lsst/daf/base/PropertySet.h"
33 #include "lsst/daf/base/PropertyList.h"
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,
51  std::shared_ptr<Wcs const> wcs)
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>
59 Exposure<ImageT, MaskT, VarianceT>::Exposure(geom::Box2I const &bbox, std::shared_ptr<Wcs const> wcs)
60  : daf::base::Citizen(typeid(this)), _maskedImage(bbox), _info(new ExposureInfo(wcs)) {}
61 
62 template <typename ImageT, typename MaskT, typename VarianceT>
63 Exposure<ImageT, MaskT, VarianceT>::Exposure(MaskedImageT &maskedImage, std::shared_ptr<Wcs const> wcs)
64  : daf::base::Citizen(typeid(this)), _maskedImage(maskedImage), _info(new ExposureInfo(wcs)) {}
65 
66 template <typename ImageT, typename MaskT, typename VarianceT>
67 Exposure<ImageT, MaskT, VarianceT>::Exposure(MaskedImageT &maskedImage, std::shared_ptr<ExposureInfo> info)
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>
86 Exposure<ImageT, MaskT, VarianceT>::Exposure(std::string const &fileName, geom::Box2I const &bbox,
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) {
111  std::shared_ptr<daf::base::PropertySet> metadata(new daf::base::PropertyList());
112  std::shared_ptr<daf::base::PropertySet> imageMetadata(new daf::base::PropertyList());
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>
138 void Exposure<ImageT, MaskT, VarianceT>::writeFits(std::string const &fileName) const {
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  ExposureInfo::FitsWriteData data = _info->_startWriteFits(getXY0());
152  _maskedImage.writeFits(fitsfile, data.metadata, data.imageMetadata, data.maskMetadata,
153  data.varianceMetadata);
154  _info->_finishWriteFits(fitsfile, data);
155 }
156 
157 // Explicit instantiations
159 template class Exposure<std::uint16_t>;
160 template class Exposure<int>;
161 template class Exposure<float>;
162 template class Exposure<double>;
163 template class Exposure<std::uint64_t>;
165 }
166 }
167 } // end lsst::afw::image
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:44
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
void setXY0(geom::Point2I const &origin)
Set the Exposure&#39;s origin (including correcting the Wcs)
Definition: Exposure.cc:128
void writeFits(std::string const &fileName) const
Write an Exposure to a regular multi-extension FITS file.
Definition: Exposure.cc:138
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:199
An integer coordinate rectangle.
Definition: Box.h:55
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:100
void setMaskedImage(MaskedImageT &maskedImage)
Set the MaskedImage of the Exposure.
Definition: Exposure.cc:123
afw::table::Key< afw::table::Array< ImagePixelT > > image
A collection of all the things that make an Exposure different from a MaskedImage.
Definition: ExposureInfo.h:86
lsst::daf::base::PropertyList PropertyList
Definition: Wcs.cc:56