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__) 115 template <
typename T>
207 template <
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>
235 : compression(compression_), scaling(scaling_) {}
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);
332 template <
typename T>
338 template <
typename T>
351 template <
typename T>
356 template <
typename T>
362 template <
typename T>
366 updateColumnKey(prefix, n,
std::string(value), comment);
368 template <
typename T>
369 void updateColumnKey(
std::string const& prefix,
int n,
T const& value);
376 template <
typename T>
380 writeColumnKey(prefix, n,
std::string(value), comment);
382 template <
typename T>
383 void writeColumnKey(
std::string const& prefix,
int n,
T const& value);
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) {
493 template <
typename T>
513 ndarray::Vector<long, N> nAxes(1);
514 getImageShapeImpl(N, nAxes.elems);
515 ndarray::Vector<ndarray::Size, N> shape;
516 for (
int i = 0; i < N; ++i) shape[i] = nAxes[N - i - 1];
526 template <
typename T>
527 bool checkImageType();
540 template <
typename T,
int N>
541 void readImage(ndarray::Array<T, N, N>
const& array, ndarray::Vector<int, N>
const& offset) {
542 ndarray::Vector<long, N> begin(offset.reverse());
543 ndarray::Vector<long, N>
end(begin);
544 end += array.getShape().reverse();
545 ndarray::Vector<long, N> increment(1);
547 readImageImpl(N, array.getData(), begin.elems, end.elems, increment.elems);
559 template <
typename T>
568 template <
typename T>
578 template <
typename T>
582 template <
typename T>
584 writeTableArray(row, col, 1, &value);
590 template <
typename T>
591 void readTableArray(
std::size_t row,
int col,
int nElements,
T* value);
594 template <
typename T>
596 readTableArray(row, col, 1, &value);
603 long getTableArraySize(
int col);
609 Fits() : fptr(0), status(0), behavior(0) {}
635 bool checkCompressedImagePhu();
638 if ((fptr) && (behavior & AUTO_CLOSE)) closeFile();
764 #endif // !LSST_AFW_fits_h_INCLUDED
void createImage(int bitpix, ndarray::Vector< ndarray::Size, N > const &shape)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
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.
std::shared_ptr< daf::base::PropertyList > combineMetadata(std::shared_ptr< const daf::base::PropertyList > first, std::shared_ptr< const daf::base::PropertyList > second)
Combine two sets of metadata in a FITS-appropriate fashion.
ImageCompressionOptions compression
Options controlling compression.
Options for writing an image to FITS.
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.
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.
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.
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.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
The base class for all image classed (Image, Mask, MaskedImage, ...)
FITS BITPIX header value by C++ type.
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.
Reports errors in external input/output operations.
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.
ndarray::Array< T const, N, N > const makeContiguousArray(ndarray::Array< T, N, C > const &array)
Construct a contiguous ndarray.
An exception thrown when problems are found when reading or writing FITS files.
ndarray::Vector< ndarray::Size, N > getImageShape()
Return the shape of the current (image) HDU.
Options for tile compression of image pixels.
A base class for image defects.
void createImage(long x, long y)
Create a 2-d image with pixel type provided by the given explicit PixelT template parameter...
Represent a 2-dimensional array of bitmask pixels.
Lifetime-management for memory that goes into FITS memory files.
void * getData() const
Return the buffer.
Fits()
Default constructor; set all data members to 0.
void reset(void *ptr, std::size_t len)
Set the internal memory buffer to an manually-managed external block.
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.
Options for scaling image pixels.
ImageWriteOptions(ImageScalingOptions const &scaling_)
Construct with specific scaling options.
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.
ImageScalingOptions scaling
Options controlling scaling.
void disable()
Disable the guard, leaving the HDU at its current state at destruction.
std::size_t getLength() const
Return the buffer length.
void setAllowImageCompression(bool allow)
Class for storing generic metadata.
An exception thrown when a FITS file has the wrong type.
void reset()
Return the manager to the same state it would be if default-constructed.
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
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
bool getAllowImageCompression()
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)
Macro used to define new types of exceptions without additional data.
def writeMetadata(self, dataRefList)
No metadata to write, and not sure how to write it for a list of dataRefs.
std::string makeErrorMessage(std::string const &fileName="", int status=0, std::string const &msg="")
Return an error message reflecting FITS I/O errors.
A class to represent a 2-dimensional array of pixels.
RAII scoped guard for moving the HDU in a Fits object.
void writeTableScalar(std::size_t row, int col, T value)
Write a scalar value to a binary table.
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.
const int DEFAULT_HDU
Specify that the default HDU should be read.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.
ImageWriteOptions(image::Image< T > const &image)
Construct with default options for images.