24 #ifndef LSST_AFW_IMAGE_fits_io_h_INCLUDED
25 #define LSST_AFW_IMAGE_fits_io_h_INCLUDED
29 #include "boost/format.hpp"
36 namespace lsst {
namespace afw {
namespace image {
38 template <
typename PixelT>
41 ndarray::Array<PixelT,2,2> & array,
51 "Incorrect image type for FITS image"
55 ndarray::Vector<ndarray::Size,2> shape;
58 }
else if (nAxis == 3) {
59 ndarray::Vector<ndarray::Size,3> shape3 = fitsfile.
getImageShape<3>();
63 boost::str(
boost::format(
"3rd dimension %d is not 1") % shape3[0])
66 shape = shape3.last<2>();
77 if (!bbox.isEmpty()) {
79 bbox.shift(-xyOffset);
83 if (bbox.getMinX() < 0 || bbox.getMinY() < 0 ||
84 bbox.getWidth() > dimensions.getX() || bbox.getHeight() > dimensions.getY()
87 lsst::pex::exceptions::LengthError,
88 (
boost::format(
"BBox (%d,%d) %dx%d doesn't fit in image %dx%d") %
89 bbox.getMinX() % bbox.getMinY() % bbox.getWidth() % bbox.getHeight() %
90 dimensions.getX() % dimensions.getY()).str()
93 dimensions = bbox.getDimensions();
96 array = ndarray::allocate(dimensions.getY(), dimensions.getX());
98 fitsfile.
readImage(array, ndarray::makeVector(xy0.getY(), xy0.getX()));
103 template <
typename ImageT>
108 fitsfile.
createImage<
typename ImageT::Pixel>(image.getArray().getShape());
117 #endif // !LSST_AFW_IMAGE_fits_io_h_INCLUDED
An include file to include the header files for lsst::afw::geom.
void readImage(ndarray::Array< T, N, N > const &array, ndarray::Vector< int, N > const &offset)
Read an array from a FITS image.
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Extent< int, 2 > Extent2I
An integer coordinate rectangle.
table::Key< table::Array< Kernel::Pixel > > image
afw::table::PointKey< int > dimensions
int getImageDim()
Return the number of dimensions in the current HDU.
afwGeom::Point2I getImageXY0FromMetadata(std::string const &wcsName, lsst::daf::base::PropertySet *metadata)
ndarray::Vector< ndarray::Size, N > getImageShape()
Return the shape of the current (image) HDU.
void fits_read_array(fits::Fits &fitsfile, ndarray::Array< PixelT, 2, 2 > &array, geom::Point2I &xy0, lsst::daf::base::PropertySet &metadata, geom::Box2I bbox=geom::Box2I(), ImageOrigin origin=PARENT)
bool checkImageType()
Return true if the current HDU has the given pixel type..
#define LSST_EXCEPT(type,...)
void createImage(ndarray::Vector< ndarray::Size, N > const &shape)
Create an image with pixel type provided by the given explicit PixelT template parameter and shape de...
Class for storing generic metadata.
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
Include files required for standard LSST Exception handling.
#define LSST_FITS_EXCEPT(type, fitsObj,...)
void fits_write_image(fits::Fits &fitsfile, const ImageT &image, boost::shared_ptr< daf::base::PropertySet const > metadata=boost::shared_ptr< daf::base::PropertySet const >())
std::string const wcsNameForXY0