2 #ifndef LSST_AFW_fits_h_INCLUDED
3 #define LSST_AFW_fits_h_INCLUDED
20 #include <boost/format.hpp>
21 #include <boost/scoped_array.hpp>
27 namespace lsst {
namespace afw {
namespace fits {
37 LSST_EXCEPTION_TYPE(FitsTypeError, lsst::afw::fits::FitsError, lsst::afw::fits::FitsTypeError)
39 #ifndef SWIG // only want SWIG to see the exceptions; everything else is too low-level for Python.
51 std::string
const & key,
52 std::string
const & value,
53 std::string
const & comment
91 #define LSST_FITS_EXCEPT(type, fitsObj, ...) \
92 type(LSST_EXCEPT_HERE, lsst::afw::fits::makeErrorMessage((fitsObj).fptr, (fitsObj).status, __VA_ARGS__))
97 #define LSST_FITS_CHECK_STATUS(fitsObj, ...) \
98 if ((fitsObj).status != 0) throw LSST_FITS_EXCEPT(lsst::afw::fits::FitsError, fitsObj, __VA_ARGS__)
149 void reset(std::size_t len);
194 class Fits :
private boost::noncopyable {
196 template <
typename T>
void writeImageImpl(T
const * data,
int nElements);
197 template <
typename T>
void readImageImpl(
int nAxis, T * data,
long * begin,
long * end,
long * increment);
221 void setHdu(
int hdu,
bool relative=
false);
227 template <
typename T>
229 void updateKey(std::string
const & key, T
const & value, std::string
const & comment);
230 void updateKey(std::string
const & key,
char const * value, std::string
const & comment) {
231 updateKey(key, std::string(value), comment);
233 template <
typename T>
234 void updateKey(std::string
const & key, T
const & value);
235 void updateKey(std::string
const & key,
char const * value) {
248 template <
typename T>
249 void writeKey(std::string
const & key, T
const & value, std::string
const & comment);
250 void writeKey(std::string
const & key,
char const * value, std::string
const & comment) {
251 writeKey(key, std::string(value), comment);
253 template <
typename T>
254 void writeKey(std::string
const & key, T
const & value);
255 void writeKey(std::string
const & key,
char const * value) {
261 template <
typename T>
263 void updateColumnKey(std::string
const & prefix,
int n, T
const & value, std::string
const & comment);
264 void updateColumnKey(std::string
const & prefix,
int n,
char const * value, std::string
const & comment) {
267 template <
typename T>
268 void updateColumnKey(std::string
const & prefix,
int n, T
const & value);
275 template <
typename T>
277 void writeColumnKey(std::string
const & prefix,
int n, T
const & value, std::string
const & comment);
278 void writeColumnKey(std::string
const & prefix,
int n,
char const * value, std::string
const & comment) {
281 template <
typename T>
282 void writeColumnKey(std::string
const & prefix,
int n, T
const & value);
311 template <
typename T>
312 void readKey(std::string
const & key, T & value);
342 template <
typename PixelT,
int N>
345 createImageImpl<PixelT>(N, nAxes.elems);
354 template <
typename PixelT>
356 long naxes[2] = {
x, y };
357 createImageImpl<PixelT>(2, naxes);
367 template <
typename T,
int N,
int C>
390 for (
int i = 0; i < N; ++i) shape[i] = nAxes[N-i-1];
400 template <
typename T>
409 template <
typename T,
int N>
431 template <
typename T>
432 int addColumn(std::string
const & ttype,
int size, std::string
const & comment);
440 template <
typename T>
441 int addColumn(std::string
const & ttype,
int size);
444 std::size_t
addRows(std::size_t nRows);
450 template <
typename T>
454 template <
typename T>
461 template <
typename T>
465 template <
typename T>
481 Fits(std::string
const & filename, std::string
const & mode,
int behavior);
500 #endif // !LSST_AFW_fits_h_INCLUDED
int getImageDim()
Return the number of dimensions in the current HDU.
std::size_t countRows()
Return the number of row in a table.
void writeKey(std::string const &key, char const *value)
Add a FITS header key to the bottom of the header.
MemFileManager(std::size_t len)
Construct a MemFileManager with (len) bytes of initial memory.
void updateKey(std::string const &key, char const *value)
Set a FITS header key, editing if it already exists and appending it if not.
void writeColumnKey(std::string const &prefix, int n, char const *value)
Write a key of the form XXXXXnnn, where XXXXX is the prefix and nnn is a column number.
void forEachKey(HeaderIterationFunctor &functor)
Call a polymorphic functor for every key in the header.
ndarray::Vector< int, N > getImageShape()
Return the shape of the current (image) HDU.
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
void writeImageImpl(T const *data, int nElements)
Include files required for standard LSST Exception handling.
void readKey(std::string const &key, T &value)
Read a FITS header key into the given reference.
void updateColumnKey(std::string const &prefix, int n, T const &value, std::string const &comment)
Update a key of the form XXXXXnnn, where XXXXX is the prefix and nnn is a column number.
void writeKey(std::string const &key, char const *value, std::string const &comment)
Add a FITS header key to the bottom of the header.
int getBitPix()
Return the cfitsio integer BITPIX code for the given data type.
Array< T, N, C_ > dynamic_dimension_cast(Array< T, N, C > const &array)
void readTableScalar(std::size_t row, int col, T &value)
Read an array scalar from a binary table.
MemFileManager(void *ptr, std::size_t len)
Construct a MemFileManager that references and does not manage external memory.
bool checkImageType()
Return true if the current HDU has the given pixel type..
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
void writeColumnKey(std::string const &prefix, int n, char const *value, std::string const &comment)
Write a key of the form XXXXXnnn, where XXXXX is the prefix and nnn is a column number.
void writeColumnKey(std::string const &prefix, int n, T const &value, std::string const &comment)
Write a key of the form XXXXXnnn, where XXXXX is the prefix and nnn is a column number.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Vector reverse() const
Return a Vector with the elements reversed.
long getTableArraySize(int col)
Return the size of an array column.
void closeFile()
Close a FITS file.
void updateKey(std::string const &key, char const *value, std::string const &comment)
Set a FITS header key, editing if it already exists and appending it if not.
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
std::size_t getLength() const
Return the buffer length.
void readImageImpl(int nAxis, T *data, long *begin, long *end, long *increment)
void updateKey(std::string const &key, T const &value, std::string const &comment)
Set a FITS header key, editing if it already exists and appending it if not.
void readImage(ndarray::Array< T, N, N > const &array, ndarray::Vector< int, N > const &offset)
Read an array from a FITS image.
MemFileManager()
Construct a MemFileManager with no initial memory buffer.
Index getShape() const
Return a Vector of the sizes of all dimensions.
void createImage(long x, long y)
Create a 2-d image with pixel type provided by the given explicit PixelT template parameter...
int getNumElements() const
Return the total number of elements in the array.
Lifetime-management for memory that goes into FITS memory files.
std::size_t addRows(std::size_t nRows)
Append rows to a table, and return the index of the first new row.
Fits()
Default constructor; set all data members to 0.
void createImageImpl(int nAxis, long *nAxes)
void reset(void *ptr, std::size_t len)
Set the internal memory buffer to an manually-managed external block.
void createTable()
Create a new binary table extension.
void updateColumnKey(std::string const &prefix, int n, char const *value)
Update a key of the form XXXXXnnn, where XXXXX is the prefix and nnn is a column number.
void getImageShapeImpl(int nAxis, long *nAxes)
Element * getData() const
Return a raw pointer to the first element of the array.
void setHdu(int hdu, bool relative=false)
Set the current HDU.
void updateColumnKey(std::string const &prefix, int n, char const *value, std::string const &comment)
Update a key of the form XXXXXnnn, where XXXXX is the prefix and nnn is a column number.
bool empty() const
Return true if the first dimension has no elements.
A multidimensional strided array.
void createImage(ndarray::Vector< int, N > const &shape)
Create an image with pixel type provided by the given explicit PixelT template parameter and shape de...
std::string getFileName() const
Return the file name associated with the FITS object or "<unknown>" if there is none.
Class for storing generic metadata.
void writeTableArray(std::size_t row, int col, int nElements, T const *value)
Write an array value to a binary table.
void reset()
Return the manager to the same state it would be if default-constructed.
void readTableArray(std::size_t row, int col, int nElements, T *value)
Read an array value from a binary table.
void writeKey(std::string const &key, T const &value, std::string const &comment)
Add a FITS header key to the bottom of the header.
int getHdu()
Return the current HDU (1-indexed; 1 is the Primary HDU).
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
#define LSST_EXCEPTION_TYPE(t, b, c)
int addColumn(std::string const &ttype, int size, std::string const &comment)
Add a column to a table.
std::string makeErrorMessage(std::string const &fileName="", int status=0, std::string const &msg="")
Return an error message reflecting FITS I/O errors.
void * getData() const
Return the buffer.
void writeTableScalar(std::size_t row, int col, T value)
Write an scalar value to a binary table.
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
int countHdus()
Return the number of HDUs in the file.