24 #ifndef LSST_AFW_IMAGE_fits_io_h_INCLUDED
25 #define LSST_AFW_IMAGE_fits_io_h_INCLUDED
29 #include "boost/format.hpp"
30 #include "lsst/pex/exceptions.h"
40 template <
typename PixelT>
48 ndarray::Vector<ndarray::Size, 2> shape;
51 }
else if (nAxis == 3) {
52 ndarray::Vector<ndarray::Size, 3> shape3 = fitsfile.
getImageShape<3>();
55 boost::str(boost::format(
"3rd dimension %d is not 1") % shape3[0]));
57 shape = shape3.last<2>();
68 if (!bbox.isEmpty()) {
70 bbox.shift(-xyOffset);
74 if (bbox.getMinX() < 0 || bbox.getMinY() < 0 || bbox.getWidth() > dimensions.getX() ||
75 bbox.getHeight() > dimensions.getY()) {
76 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError,
77 (boost::format(
"BBox (%d,%d) %dx%d doesn't fit in image %dx%d") %
78 bbox.getMinX() % bbox.getMinY() % bbox.getWidth() % bbox.getHeight() %
79 dimensions.getX() % dimensions.getY())
82 dimensions = bbox.getDimensions();
85 array = ndarray::allocate(dimensions.getY(), dimensions.getX());
87 fitsfile.
readImage(array, ndarray::makeVector(xy0.getY(), xy0.getX()));
92 template <
typename ImageT>
94 std::shared_ptr<daf::base::PropertySet const> metadata =
95 std::shared_ptr<daf::base::PropertySet const>()) {
96 fitsfile.
createImage<
typename ImageT::Pixel>(image.getArray().getShape());
106 #endif // !LSST_AFW_IMAGE_fits_io_h_INCLUDED
int getImageDim()
Return the number of dimensions in the current HDU.
afw::table::PointKey< int > dimensions
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
void fits_write_image(fits::Fits &fitsfile, const ImageT &image, std::shared_ptr< daf::base::PropertySet const > metadata=std::shared_ptr< daf::base::PropertySet const >())
bool checkImageType()
Return true if the current HDU has the given pixel type.
Extent< int, 2 > Extent2I
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
An integer coordinate rectangle.
void readImage(ndarray::Array< T, N, N > const &array, ndarray::Vector< int, N > const &offset)
Read an array from a FITS image.
An exception thrown when problems are found when reading or writing FITS files.
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)
lsst::daf::base::PropertySet PropertySet
An exception thrown when a FITS file has the wrong 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...
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
#define LSST_FITS_EXCEPT(type, fitsObj,...)
A FITS-related replacement for LSST_EXCEPT that takes an additional Fits object and uses makeErrorMes...
std::string const wcsNameForXY0
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
geom::Point2I getImageXY0FromMetadata(std::string const &wcsName, lsst::daf::base::PropertySet *metadata)