2 #ifndef LSST_AFW_fits_h_INCLUDED
3 #define LSST_AFW_fits_h_INCLUDED
20 #include <boost/format.hpp>
26 namespace lsst {
namespace afw {
namespace fits {
36 LSST_EXCEPTION_TYPE(FitsTypeError, lsst::afw::fits::FitsError, lsst::afw::fits::FitsTypeError)
38 #ifndef SWIG // only want SWIG to see the exceptions; everything else is too low-level for Python.
50 std::string
const & key,
51 std::string
const & value,
52 std::string
const & comment
90 #define LSST_FITS_EXCEPT(type, fitsObj, ...) \
91 type(LSST_EXCEPT_HERE, lsst::afw::fits::makeErrorMessage((fitsObj).fptr, (fitsObj).status, __VA_ARGS__))
96 #define LSST_FITS_CHECK_STATUS(fitsObj, ...) \
97 if ((fitsObj).status != 0) throw LSST_FITS_EXCEPT(lsst::afw::fits::FitsError, fitsObj, __VA_ARGS__)
148 void reset(std::size_t len);
203 template <
typename T>
void writeImageImpl(T
const * data,
int nElements);
204 template <
typename T>
void readImageImpl(
int nAxis, T * data,
long * begin,
long * end,
long * increment);
228 void setHdu(
int hdu,
bool relative=
false);
234 template <
typename T>
236 void updateKey(std::string
const & key, T
const & value, std::string
const & comment);
237 void updateKey(std::string
const & key,
char const * value, std::string
const & comment) {
238 updateKey(key, std::string(value), comment);
240 template <
typename T>
241 void updateKey(std::string
const & key, T
const & value);
242 void updateKey(std::string
const & key,
char const * value) {
255 template <
typename T>
256 void writeKey(std::string
const & key, T
const & value, std::string
const & comment);
257 void writeKey(std::string
const & key,
char const * value, std::string
const & comment) {
258 writeKey(key, std::string(value), comment);
260 template <
typename T>
261 void writeKey(std::string
const & key, T
const & value);
262 void writeKey(std::string
const & key,
char const * value) {
268 template <
typename T>
270 void updateColumnKey(std::string
const & prefix,
int n, T
const & value, std::string
const & comment);
271 void updateColumnKey(std::string
const & prefix,
int n,
char const * value, std::string
const & comment) {
274 template <
typename T>
275 void updateColumnKey(std::string
const & prefix,
int n, T
const & value);
282 template <
typename T>
284 void writeColumnKey(std::string
const & prefix,
int n, T
const & value, std::string
const & comment);
285 void writeColumnKey(std::string
const & prefix,
int n,
char const * value, std::string
const & comment) {
288 template <
typename T>
289 void writeColumnKey(std::string
const & prefix,
int n, T
const & value);
318 template <
typename T>
319 void readKey(std::string
const & key, T & value);
349 template <
typename PixelT,
int N>
350 void createImage(ndarray::Vector<ndarray::Size,N>
const & shape) {
351 ndarray::Vector<long,N> nAxes(shape.reverse());
352 createImageImpl<PixelT>(N, nAxes.elems);
361 template <
typename PixelT>
363 long naxes[2] = {
x, y };
364 createImageImpl<PixelT>(2, naxes);
374 template <
typename T,
int N,
int C>
376 ndarray::Array<T const,N,N> contiguous = ndarray::dynamic_dimension_cast<2>(array);
377 if (contiguous.empty()) contiguous = ndarray::copy(array);
378 writeImageImpl(contiguous.getData(), contiguous.getNumElements());
394 ndarray::Vector<long,N> nAxes(1);
396 ndarray::Vector<ndarray::Size,N> shape;
397 for (
int i = 0; i < N; ++i) shape[i] = nAxes[N-i-1];
407 template <
typename T>
416 template <
typename T,
int N>
418 ndarray::Array<T,N,N>
const & array,
419 ndarray::Vector<int,N>
const & offset
421 ndarray::Vector<long,N> begin(offset.reverse());
422 ndarray::Vector<long,N> end(begin);
423 end += array.getShape().reverse();
424 ndarray::Vector<long,N> increment(1);
426 readImageImpl(N, array.getData(), begin.elems, end.elems, increment.elems);
438 template <
typename T>
439 int addColumn(std::string
const & ttype,
int size, std::string
const & comment);
447 template <
typename T>
448 int addColumn(std::string
const & ttype,
int size);
451 std::size_t
addRows(std::size_t nRows);
457 template <
typename T>
461 template <
typename T>
468 template <
typename T>
472 template <
typename T>
488 Fits(std::string
const & filename, std::string
const & mode,
int behavior);
515 #endif // !LSST_AFW_fits_h_INCLUDED
void createTable()
Create a new binary table extension.
void writeKey(std::string const &key, char const *value)
Add a FITS header key to the bottom of the header.
void readTableArray(std::size_t row, int col, int nElements, T *value)
Read an array value from a binary table.
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.
int getHdu()
Return the current HDU (1-indexed; 1 is the Primary HDU).
void readImage(ndarray::Array< T, N, N > const &array, ndarray::Vector< int, N > const &offset)
Read an array from a FITS image.
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
void forEachKey(HeaderIterationFunctor &functor)
Call a polymorphic functor for every key in the header.
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 readTableScalar(std::size_t row, int col, T &value)
Read an array scalar from a binary table.
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.
int getBitPix()
Return the cfitsio integer BITPIX code for the given data type.
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
void createImage(long x, long y)
Create a 2-d image with pixel type provided by the given explicit PixelT template parameter...
MemFileManager(std::size_t len)
Construct a MemFileManager with (len) bytes of initial memory.
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.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
void reset(void *ptr, std::size_t len)
Set the internal memory buffer to an manually-managed external block.
int countHdus()
Return the number of HDUs in the file.
void writeImageImpl(T const *data, int nElements)
Fits()
Default constructor; set all data members to 0.
std::size_t addRows(std::size_t nRows)
Append rows to a table, and return the index of the first new row.
int getImageDim()
Return the number of dimensions in the current HDU.
void createImageImpl(int nAxis, long *nAxes)
void writeKey(std::string const &key, T const &value, std::string const &comment)
Add a FITS header key to the bottom of the header.
ndarray::Vector< ndarray::Size, N > getImageShape()
Return the shape of the current (image) HDU.
Lifetime-management for memory that goes into FITS memory files.
void * getData() const
Return the buffer.
void writeTableArray(std::size_t row, int col, int nElements, T const *value)
Write an array value to a binary table.
void readImageImpl(int nAxis, T *data, long *begin, long *end, long *increment)
Fits & operator=(const Fits &)=delete
void writeKey(std::string const &key, char const *value, std::string const &comment)
Add a FITS header key to the bottom of the header.
std::size_t countRows()
Return the number of row in a table.
void readKey(std::string const &key, T &value)
Read a FITS header key into the given reference.
void setHdu(int hdu, bool relative=false)
Set the current HDU.
bool checkImageType()
Return true if the current HDU has the given pixel 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...
MemFileManager & operator=(const MemFileManager &)=delete
MemFileManager()
Construct a MemFileManager with no initial memory buffer.
void writeTableScalar(std::size_t row, int col, T value)
Write an scalar value to a binary table.
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.
Class for storing generic metadata.
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 readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
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 getImageShapeImpl(int maxDim, long *nAxes)
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 closeFile()
Close a FITS file.
Include files required for standard LSST Exception handling.
void reset()
Return the manager to the same state it would be if default-constructed.
std::string getFileName() const
Return the file name associated with the FITS object or "<unknown>" if there is none.
#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 updateKey(std::string const &key, char const *value)
Set a FITS header key, editing if it already exists and appending it if not.
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.
MemFileManager(void *ptr, std::size_t len)
Construct a MemFileManager that references and does not manage external memory.
long getTableArraySize(int col)
Return the size of an array column.
int addColumn(std::string const &ttype, int size, std::string const &comment)
Add a column to a table.