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
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.
std::size_t getLength() const
Return the buffer length.
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
void writeTableScalar(std::size_t row, int col, T value)
Write an scalar value to a binary table.
void reset(void *ptr, std::size_t len)
Set the internal memory buffer to an manually-managed external block.
void writeKey(std::string const &key, T const &value, std::string const &comment)
Add a FITS header key to the bottom of the header.
Fits()
Default constructor; set all data members to 0.
void setHdu(int hdu, bool relative=false)
Set the current HDU.
void readKey(std::string const &key, T &value)
Read a FITS header key into the given reference.
MemFileManager()
Construct a MemFileManager with no initial memory buffer.
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
void updateKey(std::string const &key, char const *value)
Set a FITS header key, editing if it already exists and appending it if not.
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 getImageShapeImpl(int nAxis, long *nAxes)
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
void reset()
Return the manager to the same state it would be if default-constructed.
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.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
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.
Vector reverse() const
Return a Vector with the elements reversed.
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.
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
std::string getFileName() const
Return the file name associated with the FITS object or "<unknown>" if there is none.
std::size_t countRows()
Return the number of row in a table.
void readTableScalar(std::size_t row, int col, T &value)
Read an array scalar from a binary table.
Index getShape() const
Return a Vector of the sizes of all dimensions.
int getNumElements() const
Return the total number of elements in the array.
Lifetime-management for memory that goes into FITS memory files.
int getHdu()
Return the current HDU (1-indexed; 1 is the Primary HDU).
MemFileManager(std::size_t len)
Construct a MemFileManager with (len) bytes of initial memory.
void writeImageImpl(T const *data, int nElements)
void readTableArray(std::size_t row, int col, int nElements, T *value)
Read an array value from a binary table.
void writeTableArray(std::size_t row, int col, int nElements, T const *value)
Write an array value to a binary table.
int getImageDim()
Return the number of dimensions in the current HDU.
Element * getData() const
Return a raw pointer to the first element of the array.
int addColumn(std::string const &ttype, int size, std::string const &comment)
Add a column to a table.
std::size_t addRows(std::size_t nRows)
Append rows to a table, and return the index of the first new row.
bool empty() const
Return true if the first dimension has no elements.
A multidimensional strided array.
bool checkImageType()
Return true if the current HDU has the given pixel type..
void closeFile()
Close a FITS file.
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.
ndarray::Vector< int, N > getImageShape()
Return the shape of the current (image) HDU.
void createImageImpl(int nAxis, long *nAxes)
void * getData() const
Return the buffer.
Class for storing generic metadata.
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 readImageImpl(int nAxis, T *data, long *begin, long *end, long *increment)
int countHdus()
Return the number of HDUs in the file.
long getTableArraySize(int col)
Return the size of an array column.
void readImage(ndarray::Array< T, N, N > const &array, ndarray::Vector< int, N > const &offset)
Read an array from a FITS image.
void writeKey(std::string const &key, char const *value)
Add a FITS header key to the bottom of the header.
void forEachKey(HeaderIterationFunctor &functor)
Call a polymorphic functor for every key in the header.
MemFileManager(void *ptr, std::size_t len)
Construct a MemFileManager that references and does not manage external memory.
void createTable()
Create a new binary table extension.
void createImage(long x, long y)
Create a 2-d image with pixel type provided by the given explicit PixelT template parameter...
#define LSST_EXCEPTION_TYPE(t, b, c)
std::string makeErrorMessage(std::string const &fileName="", int status=0, std::string const &msg="")
Return an error message reflecting FITS I/O errors.
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
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...
void writeKey(std::string const &key, char const *value, std::string const &comment)
Add a FITS header key to the bottom of the header.
Include files required for standard LSST Exception handling.
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 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.