2#ifndef LSST_AFW_fits_h_INCLUDED
3#define LSST_AFW_fits_h_INCLUDED
20#include <boost/format.hpp>
105#define LSST_FITS_EXCEPT(type, fitsObj, ...) \
106 type(LSST_EXCEPT_HERE, lsst::afw::fits::makeErrorMessage((fitsObj).fptr, (fitsObj).status, __VA_ARGS__))
111#define LSST_FITS_CHECK_STATUS(fitsObj, ...) \
112 if ((fitsObj).status != 0) throw LSST_FITS_EXCEPT(lsst::afw::fits::FitsError, fitsObj, __VA_ARGS__)
207template <
typename T,
int N,
int C>
209 ndarray::Array<T const, N, N> contiguous = ndarray::dynamic_dimension_cast<N>(array);
210 if (contiguous.empty()) contiguous = ndarray::copy(array);
224 template <
typename T>
228 template <
typename T>
298 void createImageImpl(
int bitpix,
int nAxis,
long const* nAxes);
299 template <
typename T>
300 void writeImageImpl(
T const*
data,
int nElements);
301 template <
typename T>
302 void readImageImpl(
int nAxis,
T*
data,
long* begin,
long*
end,
long* increment);
303 void getImageShapeImpl(
int maxDim,
long* nAxes);
326 void setHdu(
int hdu,
bool relative =
false);
333 template <
typename T>
338 template <
typename T>
351 template <
typename T>
356 template <
typename T>
363 template <
typename T>
368 template <
typename T>
377 template <
typename T>
382 template <
typename T>
412 template <
typename T>
443 template <
typename PixelT,
int N>
444 void createImage(ndarray::Vector<ndarray::Size, N>
const& shape) {
445 ndarray::Vector<long, N> nAxes(shape.reverse());
450 void createImage(
int bitpix, ndarray::Vector<ndarray::Size, N>
const& shape) {
451 ndarray::Vector<long, N> nAxes(shape.reverse());
452 createImageImpl(bitpix, N, nAxes.elems);
461 template <
typename PixelT>
463 long naxes[2] = {
x,
y};
476 template <
typename T,
int N,
int C>
477 void writeImage(ndarray::Array<T const, N, C>
const& array) {
494 template <
typename T>
499 template <
typename T>
500 [[deprecated(
"Replaced by a non-shared_ptr overload. Will be removed after v25.")]]
520 ndarray::Vector<long, N> nAxes(1);
521 getImageShapeImpl(N, nAxes.elems);
522 ndarray::Vector<ndarray::Size, N> shape;
523 for (
int i = 0; i < N; ++i) shape[i] = nAxes[N - i - 1];
533 template <
typename T>
547 template <
typename T,
int N>
548 void readImage(ndarray::Array<T, N, N>
const& array, ndarray::Vector<int, N>
const& offset) {
549 ndarray::Vector<long, N> begin(offset.reverse());
550 ndarray::Vector<long, N>
end(begin);
551 end += array.getShape().reverse();
552 ndarray::Vector<long, N> increment(1);
554 readImageImpl(N, array.getData(), begin.elems,
end.elems, increment.elems);
566 template <
typename T>
575 template <
typename T>
585 template <
typename T>
589 template <
typename T>
597 template <
typename T>
601 template <
typename T>
682[[deprecated(
"Replaced by a non-shared_ptr overload. Will be removed after v25.")]]
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
An exception thrown when problems are found when reading or writing FITS files.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
void writeKey(std::string const &key, char const *value)
void updateKey(std::string const &key, char const *value)
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, T const &value, std::string const &comment)
Add a FITS header key to the bottom of the header.
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.
void closeFile()
Close a FITS file.
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.
void writeKey(std::string const &key, char const *value, std::string const &comment)
int getImageDim()
Return the number of dimensions in the current HDU.
void writeColumnKey(std::string const &prefix, int n, char const *value)
void createImage(int bitpix, ndarray::Vector< ndarray::Size, N > const &shape)
std::size_t countRows()
Return the number of row in a table.
ImageCompressionOptions getImageCompression()
Return the current image compression settings.
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
void createImage(long x, long y)
Create a 2-d image with pixel type provided by the given explicit PixelT template parameter.
void readTableArray(std::size_t row, int col, int nElements, T *value)
Read an array value from a binary table.
Fits & operator=(const Fits &)=delete
void writeColumnKey(std::string const &prefix, int n, char const *value, std::string const &comment)
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 setHdu(int hdu, bool relative=false)
Set the current HDU.
void createTable()
Create a new binary table extension.
Fits()
Default constructor; set all data members to 0.
void readTableScalar(std::size_t row, int col, T &value)
Read an array scalar from a binary table.
void updateKey(std::string const &key, char const *value, std::string const &comment)
bool checkCompressedImagePhu()
Go to the first image header in the FITS file.
int countHdus()
Return the number of HDUs in the file.
void writeTableScalar(std::size_t row, int col, T value)
Write a scalar value to a binary table.
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...
void forEachKey(HeaderIterationFunctor &functor)
Call a polymorphic functor for every key in the header.
std::string getFileName() const
Return the file name associated with the FITS object or "<unknown>" if there is none.
int addColumn(std::string const &ttype, int size, std::string const &comment)
Add a column to a table.
void updateColumnKey(std::string const &prefix, int n, char const *value)
Fits(const Fits &)=delete
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 setImageCompression(ImageCompressionOptions const &options)
Set compression options for writing FITS images.
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
void writeTableArray(std::size_t row, int col, int nElements, T const *value)
Write an array value to a binary table.
void readKey(std::string const &key, T &value)
Read a FITS header key into the given reference.
std::string getImageDType()
Return the numpy dtype equivalent of the image pixel type (e.g.
ndarray::Vector< ndarray::Size, N > getImageShape()
Return the shape of the current (image) HDU.
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
void updateColumnKey(std::string const &prefix, int n, char const *value, std::string const &comment)
Fits & operator=(Fits &&)=delete
void writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
long getTableArraySize(int col)
Return the size of an array column.
std::size_t addRows(std::size_t nRows)
Append rows to a table, and return the index of the first new row.
bool checkImageType()
Return true if the current HDU is compatible with the given pixel type.
An exception thrown when a FITS file has the wrong type.
RAII scoped guard for moving the HDU in a Fits object.
HduMoveGuard(HduMoveGuard &&)=delete
HduMoveGuard(HduMoveGuard const &)=delete
void disable()
Disable the guard, leaving the HDU at its current state at destruction.
HduMoveGuard & operator=(HduMoveGuard const &)=delete
HduMoveGuard & operator=(HduMoveGuard &&)=delete
Options for scaling image pixels.
Lifetime-management for memory that goes into FITS memory files.
MemFileManager(MemFileManager &&)=delete
MemFileManager & operator=(MemFileManager &&)=delete
MemFileManager(void *ptr, std::size_t len)
Construct a MemFileManager that references and does not manage external memory.
MemFileManager()
Construct a MemFileManager with no initial memory buffer.
void reset(void *ptr, std::size_t len)
Set the internal memory buffer to an manually-managed external block.
MemFileManager(std::size_t len)
Construct a MemFileManager with (len) bytes of initial memory.
void * getData() const
Return the buffer.
MemFileManager & operator=(const MemFileManager &)=delete
void reset()
Return the manager to the same state it would be if default-constructed.
MemFileManager(const MemFileManager &)=delete
std::size_t getLength() const
Return the buffer length.
The base class for all image classed (Image, Mask, MaskedImage, ...)
A class to represent a 2-dimensional array of pixels.
Represent a 2-dimensional array of bitmask pixels.
Class for storing ordered metadata with comments.
Class for storing generic metadata.
Reports errors in external input/output operations.
std::shared_ptr< daf::base::PropertyList > combineMetadata(daf::base::PropertyList const &first, daf::base::PropertyList const &second)
Combine two sets of metadata in a FITS-appropriate fashion.
const int DEFAULT_HDU
Specify that the default HDU should be read.
int getBitPix()
Return the cfitsio integer BITPIX code for the given data type.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.
void setAllowImageCompression(bool allow)
std::string makeErrorMessage(std::string const &fileName="", int status=0, std::string const &msg="")
Return an error message reflecting FITS I/O errors.
bool getAllowImageCompression()
std::string makeLimitedFitsHeader(lsst::daf::base::PropertySet const &metadata, std::set< std::string > const &excludeNames={})
Format a PropertySet into an FITS header string in a simplistic fashion.
ndarray::Array< T const, N, N > const makeContiguousArray(ndarray::Array< T, N, C > const &array)
Construct a contiguous ndarray.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.
Options for tile compression of image pixels.
Options for writing an image to FITS.
ImageCompressionOptions compression
Options controlling compression.
ImageScalingOptions scaling
Options controlling scaling.
ImageWriteOptions(ImageScalingOptions const &scaling_)
Construct with specific scaling options.
static std::shared_ptr< daf::base::PropertySet > validate(daf::base::PropertySet const &config)
Validate a PropertySet.
ImageWriteOptions(image::Image< T > const &image)
Construct with default options for images.
ImageWriteOptions(ImageCompressionOptions const &compression_=ImageCompressionOptions(ImageCompressionOptions::NONE), ImageScalingOptions const &scaling_=ImageScalingOptions())
Construct with specific compression and scaling options.
ImageWriteOptions(image::Mask< T > const &mask)
Construct with default options for masks.
FITS BITPIX header value by C++ type.