30 #include "boost/format.hpp" 31 #include "boost/algorithm/string/trim.hpp" 52 template <
typename ImageT,
typename MaskT,
typename VarianceT>
55 : daf::
base::Citizen(typeid(this)), _maskedImage(width, height), _info(new
ExposureInfo(wcs)) {}
57 template <
typename ImageT,
typename MaskT,
typename VarianceT>
60 : daf::
base::Citizen(typeid(this)), _maskedImage(dimensions), _info(new
ExposureInfo(wcs)) {}
62 template <
typename ImageT,
typename MaskT,
typename VarianceT>
65 : daf::
base::Citizen(typeid(this)), _maskedImage(bbox), _info(new
ExposureInfo(wcs)) {}
67 template <
typename ImageT,
typename MaskT,
typename VarianceT>
70 : daf::
base::Citizen(typeid(this)), _maskedImage(maskedImage), _info(new
ExposureInfo(wcs)) {}
72 template <
typename ImageT,
typename MaskT,
typename VarianceT>
74 : daf::
base::Citizen(typeid(this)),
75 _maskedImage(maskedImage),
78 template <
typename ImageT,
typename MaskT,
typename VarianceT>
80 : daf::
base::Citizen(typeid(this)),
81 _maskedImage(src.getMaskedImage(), deep),
84 template <
typename ImageT,
typename MaskT,
typename VarianceT>
87 template <
typename ImageT,
typename MaskT,
typename VarianceT>
90 : daf::
base::Citizen(typeid(this)),
91 _maskedImage(src.getMaskedImage(), bbox, origin, deep),
94 template <
typename ImageT,
typename MaskT,
typename VarianceT>
96 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
97 : daf::
base::Citizen(typeid(this)), _maskedImage(), _info(new
ExposureInfo()) {
99 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
102 template <
typename ImageT,
typename MaskT,
typename VarianceT>
104 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
105 : daf::
base::Citizen(typeid(this)), _maskedImage(), _info(new
ExposureInfo()) {
107 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
110 template <
typename ImageT,
typename MaskT,
typename VarianceT>
112 ImageOrigin origin,
bool conformMasks,
bool allowUnsafe)
113 : daf::
base::Citizen(typeid(this)) {
115 *
this = reader.
read<ImageT, MaskT, VarianceT>(
bbox, origin, conformMasks, allowUnsafe);
118 template <
typename ImageT,
typename MaskT,
typename VarianceT>
123 template <
typename ImageT,
typename MaskT,
typename VarianceT>
125 _maskedImage = maskedImage;
128 template <
typename ImageT,
typename MaskT,
typename VarianceT>
131 if (_info->hasWcs()) {
133 auto newWcs = _info->getWcs()->copyAtShiftedPixelOrigin(shift);
134 _info->setWcs(newWcs);
136 _maskedImage.setXY0(origin);
139 template <
typename ImageT,
typename MaskT,
typename VarianceT>
141 template <
typename ImageT,
typename MaskT,
typename VarianceT>
146 template <
typename ImageT,
typename MaskT,
typename VarianceT>
148 fits::Fits fitsfile(fileName,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
152 template <
typename ImageT,
typename MaskT,
typename VarianceT>
154 fits::Fits fitsfile(manager,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
158 template <
typename ImageT,
typename MaskT,
typename VarianceT>
165 template <
typename ImageT,
typename MaskT,
typename VarianceT>
170 fits::Fits fitsfile(fileName,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
171 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
174 template <
typename ImageT,
typename MaskT,
typename VarianceT>
179 fits::Fits fitsfile(manager,
"w", fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
180 writeFits(fitsfile, imageOptions, maskOptions, varianceOptions);
183 template <
typename ImageT,
typename MaskT,
typename VarianceT>
188 ExposureInfo::FitsWriteData
data = _info->_startWriteFits(getXY0());
189 _maskedImage.writeFits(fitsfile, imageOptions, maskOptions, varianceOptions, data.metadata,
190 data.imageMetadata, data.maskMetadata, data.varianceMetadata);
191 _info->_finishWriteFits(fitsfile, data);
203 template <
class ExposureT>
204 void _copyCommonPixels(ExposureT &destination, ExposureT
const &
source) {
206 overlapBox.
clip(source.getBBox());
210 typename ExposureT::MaskedImageT overlapPixels(source.getMaskedImage(), overlapBox);
211 destination.getMaskedImage().assign(overlapPixels, overlapBox);
216 template <
typename ImageT,
typename MaskT,
typename VarianceT>
226 buffer <<
"Point " << center <<
" lies at pixel " << pixelCenter <<
", which lies outside Exposure " 230 if (size[0] <= 0 || size[1] <= 0) {
232 buffer <<
"Cannot create bounding box with dimensions " << size;
238 auto copyInfo = std::make_shared<ExposureInfo>(*
getInfo());
240 blank = math::edgePixel<MaskedImageT>(
244 _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
A collection of all the things that make an Exposure different from a MaskedImage.
An integer coordinate rectangle.