24 #ifndef LSST_AFW_IMAGE_fits_io_h_INCLUDED 25 #define LSST_AFW_IMAGE_fits_io_h_INCLUDED 29 #include "boost/format.hpp" 40 template <
typename PixelT>
49 ndarray::Vector<ndarray::Size, 2> shape;
52 }
else if (nAxis == 3) {
53 ndarray::Vector<ndarray::Size, 3> shape3 = fitsfile.
getImageShape<3>();
56 boost::str(boost::format(
"3rd dimension %d is not 1") % shape3[0]));
58 shape = shape3.last<2>();
64 const int hdu = fitsfile.
getHdu();
75 if (!bbox.isEmpty()) {
77 bbox.shift(-xyOffset);
81 if (bbox.getMinX() < 0 || bbox.getMinY() < 0 || bbox.getWidth() > dimensions.getX() ||
82 bbox.getHeight() > dimensions.getY()) {
84 (boost::format(
"BBox (%d,%d) %dx%d doesn't fit in image %dx%d") %
85 bbox.getMinX() % bbox.getMinY() % bbox.getWidth() % bbox.getHeight() %
86 dimensions.getX() % dimensions.getY())
89 dimensions = bbox.getDimensions();
92 array = ndarray::allocate(dimensions.getY(), dimensions.getX());
94 fitsfile.
readImage(array, ndarray::makeVector(xy0.getY(), xy0.getX()));
103 #endif // !LSST_AFW_IMAGE_fits_io_h_INCLUDED int getImageDim()
Return the number of dimensions in the current HDU.
bool checkImageType()
Return true if the current HDU is compatible with the given pixel type.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=fits::DEFAULT_HDU, bool strip=false)
Return the metadata (header entries) from a FITS file.
geom::Point2I getImageXY0FromMetadata(daf::base::PropertySet &metadata, std::string const &wcsName, bool strip=false)
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.
A base class for image defects.
virtual void combine(ConstPtr source)
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)
void setHdu(int hdu, bool relative=false)
Set the current HDU.
#define LSST_EXCEPT(type,...)
bool checkCompressedImagePhu()
Go to the first image header in the FITS file.
An exception thrown when a FITS file has the wrong type.
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary 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