30 #include "boost/format.hpp" 31 #include "boost/algorithm/string/trim.hpp" 51 template <
typename ImageT,
typename MaskT,
typename VarianceT>
54 : _maskedImage(width, height), _info(new
ExposureInfo(wcs)) {}
56 template <
typename ImageT,
typename MaskT,
typename VarianceT>
59 : _maskedImage(dimensions), _info(new
ExposureInfo(wcs)) {}
61 template <
typename ImageT,
typename MaskT,
typename VarianceT>
66 template <
typename ImageT,
typename MaskT,
typename VarianceT>
69 : _maskedImage(maskedImage), _info(new
ExposureInfo(wcs)) {}
71 template <
typename ImageT,
typename MaskT,
typename VarianceT>
73 : _maskedImage(maskedImage), _info(info ? info :
std::make_shared<
ExposureInfo>()) {}
75 template <
typename ImageT,
typename MaskT,
typename VarianceT>
77 : _maskedImage(src.getMaskedImage(), deep), _info(new
ExposureInfo(*src.
getInfo(), deep)) {}
79 template <
typename ImageT,
typename MaskT,
typename VarianceT>
82 template <
typename ImageT,
typename MaskT,
typename VarianceT>
85 : _maskedImage(src.getMaskedImage(), bbox, origin, deep),
88 template <
typename ImageT,
typename MaskT,
typename VarianceT>
90 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
93 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
96 template <
typename ImageT,
typename MaskT,
typename VarianceT>
98 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
101 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
104 template <
typename ImageT,
typename MaskT,
typename VarianceT>
106 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe) {
108 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
111 template <
typename ImageT,
typename MaskT,
typename VarianceT>
116 template <
typename ImageT,
typename MaskT,
typename VarianceT>
118 _maskedImage = maskedImage;
121 template <
typename ImageT,
typename MaskT,
typename VarianceT>
124 if (_info->hasWcs()) {
126 auto newWcs = _info->getWcs()->copyAtShiftedPixelOrigin(shift);
127 _info->setWcs(newWcs);
129 _maskedImage.setXY0(origin);
132 template <
typename ImageT,
typename MaskT,
typename VarianceT>
134 template <
typename ImageT,
typename MaskT,
typename VarianceT>
139 template <
typename ImageT,
typename MaskT,
typename VarianceT>
141 fits::Fits fitsfile(fileName,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
145 template <
typename ImageT,
typename MaskT,
typename VarianceT>
147 fits::Fits fitsfile(manager,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
151 template <
typename ImageT,
typename MaskT,
typename VarianceT>
158 template <
typename ImageT,
typename MaskT,
typename VarianceT>
163 fits::Fits fitsfile(fileName,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
164 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
167 template <
typename ImageT,
typename MaskT,
typename VarianceT>
172 fits::Fits fitsfile(manager,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
173 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
176 template <
typename ImageT,
typename MaskT,
typename VarianceT>
181 ExposureInfo::FitsWriteData
data = _info->_startWriteFits(getXY0());
182 _maskedImage.writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, data.metadata,
183 data.imageMetadata, data.maskMetadata, data.varianceMetadata);
184 _info->_finishWriteFits(fitsfile, data);
196 template <
class ExposureT>
197 void _copyCommonPixels(ExposureT &destination, ExposureT
const &
source) {
199 overlapBox.
clip(source.getBBox());
203 typename ExposureT::MaskedImageT overlapPixels(source.getMaskedImage(), overlapBox);
204 destination.getMaskedImage().assign(overlapPixels, overlapBox);
209 template <
typename ImageT,
typename MaskT,
typename VarianceT>
219 buffer <<
"Point " << center <<
" lies at pixel " << pixelCenter <<
", which lies outside Exposure " 223 if (size[0] <= 0 || size[1] <= 0) {
225 buffer <<
"Cannot create bounding box with dimensions " << size;
231 auto copyInfo = std::make_shared<ExposureInfo>(*
getInfo());
233 blank = math::edgePixel<MaskedImageT>(
237 _copyCommonPixels(cutout, *
this);
A floating-point coordinate rectangle geometry.
A class to contain the data, WCS, and other information needed to describe an image of the sky...
bool isEmpty() const noexcept
Return true if the box contains no points.
Options for writing an image to FITS.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
afw::table::PointKey< int > dimensions
A base class for image defects.
std::shared_ptr< RecordT > src
Lifetime-management for memory that goes into FITS memory files.
const char * source()
Source function that allows astChannel to source from a Stream.
Reports errors in the logical structure of the program.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Point in an unspecified spherical coordinate system.
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...
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
Reports invalid arguments.
ImageT::image_category image_category
A FITS reader class for Exposures and their components.
static Box2I makeCenteredBox(Point2D const ¢er, Extent const &size)
Create a box centered as closely as possible on a particular point.
Exposure< ImagePixelT, MaskPixelT, VariancePixelT > read(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the full Exposure.
Extent< double, 2 > Extent2D
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
A collection of all the things that make an Exposure different from a MaskedImage.
An integer coordinate rectangle.