2 #ifndef LSST_AFW_fits_h_INCLUDED
3 #define LSST_AFW_fits_h_INCLUDED
20 #include <boost/format.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);
204 template <
typename T>
void writeImageImpl(T
const * data,
int nElements);
205 template <
typename T>
void readImageImpl(
int nAxis, T * data,
long * begin,
long * end,
long * increment);
229 void setHdu(
int hdu,
bool relative=
false);
235 template <
typename T>
237 void updateKey(std::string
const & key, T
const & value, std::string
const & comment);
238 void updateKey(std::string
const & key,
char const * value, std::string
const & comment) {
239 updateKey(key, std::string(value), comment);
241 template <
typename T>
242 void updateKey(std::string
const & key, T
const & value);
243 void updateKey(std::string
const & key,
char const * value) {
256 template <
typename T>
257 void writeKey(std::string
const & key, T
const & value, std::string
const & comment);
258 void writeKey(std::string
const & key,
char const * value, std::string
const & comment) {
259 writeKey(key, std::string(value), comment);
261 template <
typename T>
262 void writeKey(std::string
const & key, T
const & value);
263 void writeKey(std::string
const & key,
char const * value) {
269 template <
typename T>
271 void updateColumnKey(std::string
const & prefix,
int n, T
const & value, std::string
const & comment);
272 void updateColumnKey(std::string
const & prefix,
int n,
char const * value, std::string
const & comment) {
275 template <
typename T>
283 template <
typename T>
285 void writeColumnKey(std::string
const & prefix,
int n, T
const & value, std::string
const & comment);
286 void writeColumnKey(std::string
const & prefix,
int n,
char const * value, std::string
const & comment) {
289 template <
typename T>
290 void writeColumnKey(std::string
const & prefix,
int n, T
const & value);
319 template <
typename T>
320 void readKey(std::string
const & key, T & value);
350 template <
typename PixelT,
int N>
351 void createImage(ndarray::Vector<ndarray::Size,N>
const & shape) {
352 ndarray::Vector<long,N> nAxes(shape.reverse());
353 createImageImpl<PixelT>(N, nAxes.elems);
362 template <
typename PixelT>
364 long naxes[2] = {
x, y };
365 createImageImpl<PixelT>(2, naxes);
375 template <
typename T,
int N,
int C>
377 ndarray::Array<T const,N,N> contiguous = ndarray::dynamic_dimension_cast<2>(array);
378 if (contiguous.empty()) contiguous = ndarray::copy(array);
379 writeImageImpl(contiguous.getData(), contiguous.getNumElements());
395 ndarray::Vector<long,N> nAxes(1);
397 ndarray::Vector<ndarray::Size,N> shape;
398 for (
int i = 0; i < N; ++i) shape[i] = nAxes[N-i-1];
408 template <
typename T>
417 template <
typename T,
int N>
419 ndarray::Array<T,N,N>
const & array,
420 ndarray::Vector<int,N>
const & offset
422 ndarray::Vector<long,N> begin(offset.reverse());
423 ndarray::Vector<long,N> end(begin);
424 end += array.getShape().reverse();
425 ndarray::Vector<long,N> increment(1);
427 readImageImpl(N, array.getData(), begin.elems, end.elems, increment.elems);
439 template <
typename T>
440 int addColumn(std::string
const & ttype,
int size, std::string
const & comment);
448 template <
typename T>
449 int addColumn(std::string
const & ttype,
int size);
452 std::size_t
addRows(std::size_t nRows);
458 template <
typename T>
462 template <
typename T>
469 template <
typename T>
473 template <
typename T>
489 Fits(std::string
const & filename, std::string
const & mode,
int behavior);
529 #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.
Class for storing ordered metadata with comments.
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.
Include files required for standard LSST Exception handling.
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.
boost::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=0, bool strip=false)
Read FITS header.
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.
metadata import lsst afw display as afwDisplay n
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.
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)
Macro used to define new types of exceptions without additional data.
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.