LSSTApplications
19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
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>
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>
368 template <
typename T>
376 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) {
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>
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>
590 template <
typename T>
594 template <
typename T>
764 #endif // !LSST_AFW_fits_h_INCLUDED
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
void writeTableArray(std::size_t row, int col, int nElements, T const *value)
Write an array value to a binary table.
std::size_t addRows(std::size_t nRows)
Append rows to a table, and return the index of the first new row.
std::string makeErrorMessage(std::string const &fileName="", int status=0, std::string const &msg="")
Return an error message reflecting FITS I/O errors.
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.
HduMoveGuard & operator=(HduMoveGuard &&)=delete
void disable()
Disable the guard, leaving the HDU at its current state at destruction.
void createTable()
Create a new binary table extension.
Represent a 2-dimensional array of bitmask pixels.
void * getData() const
Return the buffer.
MemFileManager & operator=(const MemFileManager &)=delete
const int DEFAULT_HDU
Specify that the default HDU should be read.
An exception thrown when problems are found when reading or writing FITS files.
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.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
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 writeMetadata(daf::base::PropertySet const &metadata)
Read a FITS header into a PropertySet or PropertyList.
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.
RAII scoped guard for moving the HDU in a Fits object.
void reset(void *ptr, std::size_t len)
Set the internal memory buffer to an manually-managed external block.
void readKey(std::string const &key, T &value)
Read a FITS header key into the given reference.
void writeKey(std::string const &key, T const &value, std::string const &comment)
Add a FITS header key to the bottom of the header.
HduMoveGuard(HduMoveGuard const &)=delete
void writeColumnKey(std::string const &prefix, int n, char const *value, std::string const &comment)
ImageCompressionOptions compression
Options controlling compression.
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 readTableArray(std::size_t row, int col, int nElements, T *value)
Read an array value from a binary table.
Fits()
Default constructor; set all data members to 0.
void forEachKey(HeaderIterationFunctor &functor)
Call a polymorphic functor for every key in the header.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Lifetime-management for memory that goes into FITS memory files.
void createImage(int bitpix, ndarray::Vector< ndarray::Size, N > const &shape)
std::size_t getLength() const
Return the buffer length.
ndarray::Array< T const, N, N > const makeContiguousArray(ndarray::Array< T, N, C > const &array)
Construct a contiguous ndarray.
Options for tile compression of image pixels.
Options for writing an image to FITS.
MemFileManager & operator=(MemFileManager &&)=delete
HduMoveGuard(HduMoveGuard &&)=delete
void updateKey(std::string const &key, char const *value, std::string const &comment)
int getBitPix()
Return the cfitsio integer BITPIX code for the given data type.
ImageWriteOptions(image::Image< T > const &image)
Construct with default options for images.
void writeKey(std::string const &key, char const *value, std::string const &comment)
void writeTableScalar(std::size_t row, int col, T value)
Write a scalar value to a binary table.
void writeKey(std::string const &key, char const *value)
void updateKey(std::string const &key, char const *value)
void createImage(long x, long y)
Create a 2-d image with pixel type provided by the given explicit PixelT template parameter.
HduMoveGuard & operator=(HduMoveGuard const &)=delete
Options for scaling image pixels.
void setHdu(int hdu, bool relative=false)
Set the current HDU.
void reset()
Return the manager to the same state it would be if default-constructed.
Fits & operator=(Fits &&)=delete
ndarray::Vector< ndarray::Size, N > getImageShape()
Return the shape of the current (image) HDU.
std::string getImageDType()
Return the numpy dtype equivalent of the image pixel type (e.g.
void setAllowImageCompression(bool allow)
static std::shared_ptr< daf::base::PropertySet > validate(daf::base::PropertySet const &config)
Validate a PropertySet.
MemFileManager(void *ptr, std::size_t len)
Construct a MemFileManager that references and does not manage external memory.
void updateColumnKey(std::string const &prefix, int n, char const *value)
std::size_t countRows()
Return the number of row in a table.
void readImage(ndarray::Array< T, N, N > const &array, ndarray::Vector< int, N > const &offset)
Read an array from a FITS image.
Fits(const Fits &)=delete
A base class for image defects.
int getHdu()
Return the current HDU (0-indexed; 0 is the Primary HDU).
int addColumn(std::string const &ttype, int size, std::string const &comment)
Add a column to a table.
MemFileManager(const MemFileManager &)=delete
Reports errors in external input/output operations.
void setImageCompression(ImageCompressionOptions const &options)
Set compression options for writing FITS images.
void closeFile()
Close a FITS file.
void readTableScalar(std::size_t row, int col, T &value)
Read an array scalar from a binary table.
bool getAllowImageCompression()
void writeColumnKey(std::string const &prefix, int n, char const *value)
Class for storing generic metadata.
void createEmpty()
Create an empty image HDU with NAXIS=0 at the end of the file.
MemFileManager(MemFileManager &&)=delete
long getTableArraySize(int col)
Return the size of an array column.
ImageScalingOptions scaling
Options controlling scaling.
ImageCompressionOptions getImageCompression()
Return the current image compression settings.
FITS BITPIX header value by C++ type.
int countHdus()
Return the number of HDUs in the file.
ImageWriteOptions(ImageScalingOptions const &scaling_)
Construct with specific scaling options.
int getImageDim()
Return the number of dimensions in the current HDU.
An exception thrown when a FITS file has the wrong type.
A class to represent a 2-dimensional array of pixels.
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.
void updateColumnKey(std::string const &prefix, int n, char const *value, std::string const &comment)
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
MemFileManager(std::size_t len)
Construct a MemFileManager with (len) bytes of initial memory.
The base class for all image classed (Image, Mask, MaskedImage, ...)
bool checkCompressedImagePhu()
Go to the first image header in the FITS file.
Fits & operator=(const Fits &)=delete
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()
Construct a MemFileManager with no initial memory buffer.
std::string getFileName() const
Return the file name associated with the FITS object or "<unknown>" if there is none.
void readMetadata(daf::base::PropertySet &metadata, bool strip=false)
Read a FITS header into a PropertySet or PropertyList.
bool checkImageType()
Return true if the current HDU is compatible with the given pixel type.
void writeImage(ndarray::Array< T const, N, C > const &array)
Write an ndarray::Array to a FITS image HDU.