24 #ifndef LSST_AFW_IMAGE_fits_io_mpl_h_INCLUDED
25 #define LSST_AFW_IMAGE_fits_io_mpl_h_INCLUDED
27 #include "boost/mpl/for_each.hpp"
28 #include "boost/mpl/vector.hpp"
40 struct found_type :
public std::exception {};
42 template <
typename ImageT,
typename ExceptionT>
43 class try_fits_read_array {
45 try_fits_read_array(fits::Fits& fitsfile, ndarray::Array<typename ImageT::Pixel, 2, 2>& array,
56 void operator()(
typename ImageT::Pixel) {
60 }
catch (fits::FitsTypeError
const&) {
65 template <
typename OtherPixel>
66 void operator()(OtherPixel) {
68 ndarray::Array<OtherPixel, 2, 2> array;
71 _array = ndarray::allocate(array.getShape());
74 }
catch (fits::FitsTypeError
const&) {
81 ndarray::Array<typename ImageT::Pixel, 2, 2>&
_array;
90 template <
typename supported_fits_types,
typename ImageT>
93 ndarray::Array<typename ImageT::Pixel, 2, 2> array;
97 try_fits_read_array<ImageT, found_type> reader{fitsfile, array, xy0, metadata, bbox, origin};
98 reader.operator()(
typename ImageT::Pixel());
99 boost::mpl::for_each<supported_fits_types>(reader);
100 }
catch (found_type&) {
101 img = ImageT(array,
false, xy0);
107 template <
typename supported_fits_types,
typename ImageT>
109 std::shared_ptr<lsst::daf::base::PropertySet> metadata =
110 std::shared_ptr<lsst::daf::base::PropertySet>(),
113 fits_read_image<supported_fits_types, ImageT>(fitsfile, img, (metadata ? *metadata : metadata_s), bbox,
119 #endif // !LSST_AFW_IMAGE_fits_io_mpl_h_INCLUDED
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
An integer coordinate rectangle.
An exception thrown when problems are found when reading or writing FITS files.
ndarray::Array< typename ImageT::Pixel, 2, 2 > & _array
geom::Box2I const & _bbox
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 checkCompressedImagePhu()
Go to the first image header in the FITS file.
void fits_read_image(fits::Fits &fitsfile, ImageT &img, lsst::daf::base::PropertySet &metadata, geom::Box2I const &bbox=geom::Box2I(), ImageOrigin const origin=PARENT)
lsst::daf::base::PropertySet PropertySet
daf::base::PropertySet & _metadata
#define LSST_FITS_EXCEPT(type, fitsObj,...)
A FITS-related replacement for LSST_EXCEPT that takes an additional Fits object and uses makeErrorMes...