30 #include "boost/format.hpp" 31 #include "boost/algorithm/string/trim.hpp" 51 template <
typename ImageT,
typename MaskT,
typename VarianceT>
54 : daf::
base::Citizen(typeid(this)), _maskedImage(width, height), _info(new
ExposureInfo(wcs)) {}
56 template <
typename ImageT,
typename MaskT,
typename VarianceT>
59 : daf::
base::Citizen(typeid(this)), _maskedImage(dimensions), _info(new
ExposureInfo(wcs)) {}
61 template <
typename ImageT,
typename MaskT,
typename VarianceT>
64 : daf::
base::Citizen(typeid(this)), _maskedImage(bbox), _info(new
ExposureInfo(wcs)) {}
66 template <
typename ImageT,
typename MaskT,
typename VarianceT>
69 : daf::
base::Citizen(typeid(this)), _maskedImage(maskedImage), _info(new
ExposureInfo(wcs)) {}
71 template <
typename ImageT,
typename MaskT,
typename VarianceT>
73 : daf::
base::Citizen(typeid(this)),
74 _maskedImage(maskedImage),
77 template <
typename ImageT,
typename MaskT,
typename VarianceT>
79 : daf::
base::Citizen(typeid(this)),
80 _maskedImage(src.getMaskedImage(), deep),
83 template <
typename ImageT,
typename MaskT,
typename VarianceT>
86 template <
typename ImageT,
typename MaskT,
typename VarianceT>
89 : daf::
base::Citizen(typeid(this)),
90 _maskedImage(src.getMaskedImage(), bbox, origin, deep),
93 template <
typename ImageT,
typename MaskT,
typename VarianceT>
95 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
96 : daf::
base::Citizen(typeid(this)), _maskedImage(), _info(new
ExposureInfo()) {
98 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
101 template <
typename ImageT,
typename MaskT,
typename VarianceT>
103 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
104 : daf::
base::Citizen(typeid(this)), _maskedImage(), _info(new
ExposureInfo()) {
106 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
109 template <
typename ImageT,
typename MaskT,
typename VarianceT>
111 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
112 : daf::
base::Citizen(typeid(this)) {
114 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
117 template <
typename ImageT,
typename MaskT,
typename VarianceT>
122 template <
typename ImageT,
typename MaskT,
typename VarianceT>
124 _maskedImage = maskedImage;
127 template <
typename ImageT,
typename MaskT,
typename VarianceT>
130 if (_info->hasWcs()) {
132 auto newWcs = _info->getWcs()->copyAtShiftedPixelOrigin(shift);
133 _info->setWcs(newWcs);
135 _maskedImage.setXY0(origin);
138 template <
typename ImageT,
typename MaskT,
typename VarianceT>
140 template <
typename ImageT,
typename MaskT,
typename VarianceT>
145 template <
typename ImageT,
typename MaskT,
typename VarianceT>
147 fits::Fits fitsfile(fileName,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
151 template <
typename ImageT,
typename MaskT,
typename VarianceT>
153 fits::Fits fitsfile(manager,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
157 template <
typename ImageT,
typename MaskT,
typename VarianceT>
164 template <
typename ImageT,
typename MaskT,
typename VarianceT>
169 fits::Fits fitsfile(fileName,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
170 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
173 template <
typename ImageT,
typename MaskT,
typename VarianceT>
178 fits::Fits fitsfile(manager,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
179 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
182 template <
typename ImageT,
typename MaskT,
typename VarianceT>
187 ExposureInfo::FitsWriteData
data = _info->_startWriteFits(getXY0());
188 _maskedImage.writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, data.metadata,
189 data.imageMetadata, data.maskMetadata, data.varianceMetadata);
190 _info->_finishWriteFits(fitsfile, data);
202 template <
class ExposureT>
203 void _copyCommonPixels(ExposureT &destination, ExposureT
const &
source) {
205 overlapBox.
clip(source.getBBox());
209 typename ExposureT::MaskedImageT overlapPixels(source.getMaskedImage(), overlapBox);
210 destination.getMaskedImage().assign(overlapPixels, overlapBox);
215 template <
typename ImageT,
typename MaskT,
typename VarianceT>
225 buffer <<
"Point " << center <<
" lies at pixel " << pixelCenter <<
", which lies outside Exposure " 229 if (size[0] <= 0 || size[1] <= 0) {
231 buffer <<
"Cannot create bounding box with dimensions " << size;
237 auto copyInfo = std::make_shared<ExposureInfo>(*
getInfo());
239 blank = math::edgePixel<MaskedImageT>(
243 _copyCommonPixels(cutout, *
this);
afw::table::PointKey< int > dimensions
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
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...
A base class for image defects.
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.
std::shared_ptr< RecordT > src
#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.