mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Class to manage interactions with a FITS file.
This class wraps the functionality of cfitsio.
dataT | is the datatype to use for in-memory storage of the image. This does not have to match the data type stored on disk for reading, but will be the type used for writing. |
Definition at line 53 of file fitsFile.hpp.
#include <ioutils/fits/fitsFile.hpp>
Public Member Functions | |
fitsFile () | |
Default constructor. More... | |
fitsFile (const std::string &fname, bool doopen=true) | |
Constructor with m_fileName, and option to open. More... | |
~fitsFile () | |
Destructor. More... | |
std::string | fileName () |
Get the current value of m_fileName. More... | |
int | fileName (const std::string &fname, bool doopen=true) |
Set the file path, and optionally open the file. More... | |
int | naxis () |
Get the current value of m_naxis. More... | |
long | naxes (int dim) |
Get the current value of m_naxes for the specified dimension. More... | |
int | open () |
Open the file and gets its dimensions. More... | |
int | open (const std::string &fname) |
Open the file, first setting the file path. More... | |
int | close () |
Close the file. More... | |
int | getDimensions () |
Get the number of dimensions (i.e. m_naxis) More... | |
long | getSize () |
Get the total size. More... | |
long | getSize (size_t axis) |
Get the size of a specific dimension. More... | |
Reading Eigen Arrays | |
These methods read FITS data into array types with an Eigen-like interface. | |
template<typename arrT > | |
int | read (arrT &data) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer). More... | |
template<typename arrT > | |
int | read (arrT &data, fitsHeader &head) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer). More... | |
template<typename arrT > | |
int | read (arrT &data, const std::string &fname) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer). More... | |
template<typename arrT > | |
int | read (arrT &data, fitsHeader &head, const std::string &fname) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer). More... | |
template<typename cubeT > | |
int | read (cubeT &cube, const std::vector< std::string > &flist, std::vector< fitsHeader > *heads=0) |
Read data from a vector list of files into an image cube. More... | |
template<typename cubeT > | |
int | read (cubeT &cube, std::vector< fitsHeader > &heads, const std::vector< std::string > &flist) |
Read data from a vector of files into an image cube with individual headers. More... | |
Reading Headers | |
int | readHeader (fitsHeader &head) |
Read the header from the fits file. More... | |
int | readHeader (fitsHeader &head, const std::string &fname) |
Read the header from the fits file. More... | |
int | readHeader (std::vector< fitsHeader > &heads, const std::vector< std::string > &flist) |
Read the headers from a list of FITS files. More... | |
Writing Basic Arrays | |
These methods write basic arrays specified by a pointer to FITS. | |
int | write (const dataT *im, int d1, int d2, int d3, fitsHeader *head) |
Write the contents of a raw array to the FITS file. More... | |
int | write (const dataT *im, int d1, int d2, int d3) |
Write the contents of a raw array to the FITS file. More... | |
int | write (const dataT *im, int d1, int d2, int d3, fitsHeader &head) |
Write the contents of a raw array to the FITS file. More... | |
int | write (const std::string &fname, const dataT *im, int d1, int d2, int d3) |
Write the contents of a raw array to the FITS file. More... | |
int | write (const std::string &fname, const dataT *im, int d1, int d2, int d3, fitsHeader &head) |
Write the contents of a raw array to the FITS file. More... | |
Writing Eigen Arrays | |
These methods write array types with an Eigen-like interface. | |
template<typename arrT > | |
int | write (const std::string &fname, const arrT &im) |
Write the contents of an Eigen-type array to a FITS file. More... | |
template<typename arrT > | |
int | write (const std::string &fname, const arrT &im, fitsHeader &head) |
Write the contents of an Eigen-type array to a FITS file. More... | |
Reading Subsets | |
It is often desirable to read only a subset of an image or images into memory. These methods allow you to specify this. | |
void | setReadSize () |
Set to read all the pixels in the file. More... | |
void | setReadSize (long x0, long y0, long xpix, long ypix) |
Set to read only a subset of the pixels in the file. More... | |
void | setCubeReadSize () |
Set to read all frames from a cube. More... | |
void | setCubeReadSize (long z0, long zframes) |
Set the number of frames to read from a cube. More... | |
Protected Member Functions | |
void | construct () |
One time initialization common to all constructors. More... | |
Protected Attributes | |
std::string | m_fileName |
The path to the file. More... | |
fitsfile * | m_fptr {nullptr} |
The cfitsio data structure. More... | |
int | m_naxis |
The dimensions of the image (1D, 2D, 3D etc) More... | |
long * | m_naxes {nullptr} |
The size of each dimension. More... | |
bool | m_isOpen {false} |
Flag indicating whether the file is open or not. More... | |
dataT | m_nulval {0} |
The value to replace null values with. More... | |
int | m_anynul {0} |
Records whether any null values were replaced. More... | |
int | m_noComment {0} |
Flag to control whether the comment string is read. More... | |
long | m_x0 {-1} |
The starting x-pixel to read from. More... | |
long | m_y0 {-1} |
The starting y-pixel to read from. More... | |
long | m_xpix {-1} |
The number of x-pixels to read. More... | |
long | m_ypix {-1} |
The number of y-pixels to read. More... | |
long | m_z0 {-1} |
The starting frame to read from a cube. More... | |
long | m_zframes {-1} |
The number of frames to read from a cube. More... | |
Reading Basic Arrays | |
These methods read FITS data into basic or raw arrays specified by a pointer. | |
void | pixarrs (long **fpix, long **lpix, long **inc) |
Fill in the read-size arrays for reading a subset (always used) More... | |
int | read (dataT *data) |
Read the contents of the FITS file into an array. More... | |
int | read (dataT *data, fitsHeader &head) |
Read the contents of the FITS file into an array. More... | |
int | read (dataT *data, const std::string &fname) |
Read the contents of the FITS file into an array. More... | |
int | read (dataT *data, fitsHeader &head, const std::string &fname) |
Read the contents of the FITS file into an array and read the header. More... | |
int | read (dataT *im, const std::vector< std::string > &flist) |
Read data from a vector list of files into an image cube. More... | |
int | read (dataT *im, std::vector< fitsHeader > &heads, const std::vector< std::string > &flist) |
Read data from a vector of files into an image cube with individual headers. More... | |
mx::fits::fitsFile< dataT >::fitsFile |
Default constructor.
Definition at line 562 of file fitsFile.hpp.
mx::fits::fitsFile< dataT >::fitsFile | ( | const std::string & | fname, |
bool | doopen = true |
||
) |
Constructor with m_fileName, and option to open.
fname | File name to set on construction |
doopen | If true, then the file is opened (the default). |
Definition at line 568 of file fitsFile.hpp.
mx::fits::fitsFile< dataT >::~fitsFile |
Destructor.
Definition at line 575 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::close |
Close the file.
Definition at line 681 of file fitsFile.hpp.
References mx::fits::fitsErrText().
|
protected |
One time initialization common to all constructors.
Definition at line 557 of file fitsFile.hpp.
std::string mx::fits::fitsFile< dataT >::fileName |
Get the current value of m_fileName.
Definition at line 583 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::fileName | ( | const std::string & | fname, |
bool | doopen = true |
||
) |
Set the file path, and optionally open the file.
fname | The new file name. |
doopen | If true, then the file is opened (the default). |
Definition at line 589 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::getDimensions |
Get the number of dimensions (i.e. m_naxis)
Definition at line 711 of file fitsFile.hpp.
long mx::fits::fitsFile< dataT >::getSize |
Get the total size.
Definition at line 719 of file fitsFile.hpp.
long mx::fits::fitsFile< dataT >::getSize | ( | size_t | axis | ) |
Get the size of a specific dimension.
Definition at line 738 of file fitsFile.hpp.
long mx::fits::fitsFile< dataT >::naxes | ( | int | dim | ) |
Get the current value of m_naxes for the specified dimension.
[in] | dim | the dimension |
Definition at line 614 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::naxis |
Get the current value of m_naxis.
Definition at line 608 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::open |
Open the file and gets its dimensions.
File name needs to already have been set.
If the file has already been opened, this returns immediately with no re-open.
Definition at line 624 of file fitsFile.hpp.
References mx::fits::fitsErrText().
int mx::fits::fitsFile< dataT >::open | ( | const std::string & | fname | ) |
Open the file, first setting the file path.
fname | The name of the file to open. |
Definition at line 675 of file fitsFile.hpp.
|
protected |
Fill in the read-size arrays for reading a subset (always used)
fpix | Populated with the lower left pixel to read. Is allocated. |
lpix | Populated with the upper right pixel to read. Is allocated. |
inc | The increment. Is allocated. |
Definition at line 754 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | arrT & | data | ) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer).
The type arrT can be any type with the following members defined:
arrT | is the type of array, see requirements above. |
[out] | data | is the array, which will be resized as necessary using its resize(int, int) member |
Definition at line 980 of file fitsFile.hpp.
References mx::fits::fitsErrText().
int mx::fits::fitsFile< dataT >::read | ( | arrT & | data, |
const std::string & | fname | ||
) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer).
The type arrT can be any type with the following members defined:
arrT | is the type of array, see requirements above. |
[out] | data | is the array, which will be resized as necessary using its resize(int, int) member |
[in] | fname | is the file path, which is passed to fileName |
Definition at line 1037 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | arrT & | data, |
fitsHeader & | head | ||
) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer).
The type arrT can be any type with the following members defined:
arrT | is the type of array, see requirements above. |
[out] | data | is the array, which will be resized as necessary using its resize(int, int) member |
[out] | head | is a fitsHeader object which is passed to readHeader |
Definition at line 1028 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | arrT & | data, |
fitsHeader & | head, | ||
const std::string & | fname | ||
) |
Read the contents of the FITS file into an Eigen array type (not a simple pointer).
The type arrT can be any type with the following members defined:
arrT | is the type of array, see requirements above. |
[out] | data | the array, which will be resized as necessary using its resize(int, int) member |
[out] | head | a fitsHeader object which is passed to readHeader |
[in] | fname | the file path, which is passed to fileName |
Definition at line 1048 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | cubeT & | cube, |
const std::vector< std::string > & | flist, | ||
std::vector< fitsHeader > * | heads = 0 |
||
) |
Read data from a vector list of files into an image cube.
The type cubeT can be any type with the following members defined:
cubeT | is the type of array, see requirements above. |
[out] | cube | A cube which will be resized using its resize(int, int, int) member. |
[in] | flist | The list of files to read. |
[out] | heads | [optional] A vector of fits headers, allocated to contain one per image. |
Definition at line 1063 of file fitsFile.hpp.
References mx::fits::fitsErrText().
int mx::fits::fitsFile< dataT >::read | ( | cubeT & | cube, |
std::vector< fitsHeader > & | heads, | ||
const std::vector< std::string > & | flist | ||
) |
Read data from a vector of files into an image cube with individual headers.
The type cubeT can be any type with the following members defined:
cubeT | is the type of array, see requirements above. |
[out] | cube | A cube which will be resized using its resize(int, int, int) member. |
[out] | heads | The vector of fits headers, allocated to contain one per image. |
[in] | flist | The list of files to read. |
Definition at line 1150 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | dataT * | data | ) |
Read the contents of the FITS file into an array.
The array pointed to by data must have been allocated.
[out] | data | an allocated arrray large enough to hold the entire image |
Definition at line 828 of file fitsFile.hpp.
References mx::fits::fitsErrText().
Referenced by mx::AO::analysis::calculatedWFS< realT, iosT >::beta_p(), mx::AO::analysis::calculatedWFS< realT, iosT >::beta_r(), mx::AO::sim::turbAtmosphere< _aoSystemT >::genLayers(), mx::AO::ifPInv(), mx::AO::sim::simulatedAOSystem< _realT, _wfsT, _reconT, _filterT, _dmT, _turbSeqT, _coronT >::initSystem(), mx::improc::ADIobservation< _realT, _derotFunctObj >::injectFake(), mx::wfp::lyotCoronagraph< _realT, _fpmaskFloatT >::loadApodizer(), mx::wfp::lyotCoronagraph< _realT, _fpmaskFloatT >::loadFocalMask(), mx::wfp::lyotCoronagraph< _realT, _fpmaskFloatT >::loadLyotStop(), mx::wfp::idealCoronagraph< _realT >::loadPupil(), mx::AO::sim::directPhaseReconstructor< realT >::loadRecon(), mx::AO::modalDMM2cMatrix(), mx::improc::HCIobservation< _realT >::readFiles(), mx::improc::HCIobservation< _realT >::readMask(), mx::improc::ADIobservation< _realT, _derotFunctObj >::readPSFSub(), mx::improc::HCIobservation< _realT >::readPSFSub(), and mx::improc::HCIobservation< _realT >::readRDIFiles().
int mx::fits::fitsFile< dataT >::read | ( | dataT * | data, |
const std::string & | fname | ||
) |
Read the contents of the FITS file into an array.
The array pointed to by data must have been allocated.
[out] | data | is an allocated arrray large enough to hold the entire image |
[in] | fname | is the file path, which is passed to fileName |
Definition at line 874 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | dataT * | data, |
fitsHeader & | head | ||
) |
Read the contents of the FITS file into an array.
The array pointed to by data must have been allocated.
[out] | data | an allocated arrray large enough to hold the entire image |
[out] | head | a fitsHeader object which is passed to readHeader |
Definition at line 863 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | dataT * | data, |
fitsHeader & | head, | ||
const std::string & | fname | ||
) |
Read the contents of the FITS file into an array and read the header.
The array pointed to by data must have been allocated.
[out] | data | an allocated arrray large enough to hold the entire image |
[out] | head | a fitsHeader object which is passed to readHeader |
[in] | fname | the file path, which is passed to fileName |
Definition at line 884 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | dataT * | im, |
const std::vector< std::string > & | flist | ||
) |
Read data from a vector list of files into an image cube.
[out] | im | An allocated array large enough to hold all the images |
[in] | flist | The list of files to read. |
Definition at line 896 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::read | ( | dataT * | im, |
std::vector< fitsHeader > & | heads, | ||
const std::vector< std::string > & | flist | ||
) |
Read data from a vector of files into an image cube with individual headers.
[out] | im | An allocated array large enough to hold all the images |
heads | [in.out] The vector of fits headers, allocated to contain one per image. | |
[in] | flist | The list of files to read. |
Definition at line 922 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::readHeader | ( | fitsHeader & | head | ) |
Read the header from the fits file.
If head is not empty, then only the keywords already in head are updated. Otherwise the complete header is read.
[out] | head | a fitsHeader object |
Definition at line 1159 of file fitsFile.hpp.
References mx::fits::fitsHeader::append(), mx::fits::fitsHeader::begin(), mx::fits::fitsHeader::end(), mx::fits::fitsHeader::erase(), mx::fits::fitsErrText(), and mx::fits::fitsHeader::size().
int mx::fits::fitsFile< dataT >::readHeader | ( | fitsHeader & | head, |
const std::string & | fname | ||
) |
Read the header from the fits file.
If head is not empty, then only the keywords already in head are updated. Otherwise the complete header is read.
[out] | head | a fitsHeader object |
[in] | fname | the file path, which is passed to fileName |
Definition at line 1276 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::readHeader | ( | std::vector< fitsHeader > & | heads, |
const std::vector< std::string > & | flist | ||
) |
Read the headers from a list of FITS files.
In each case, if the header is not empty then only the keywords already in head are updated. Otherwise the complete header is read.
flist | A vector of fitsHeader objects to read into. [in] A list of files, each of which is passed to fileName |
Definition at line 1285 of file fitsFile.hpp.
void mx::fits::fitsFile< dataT >::setCubeReadSize |
Set to read all frames from a cube.
Definition at line 1486 of file fitsFile.hpp.
void mx::fits::fitsFile< dataT >::setCubeReadSize | ( | long | z0, |
long | zframes | ||
) |
Set the number of frames to read from a cube.
z0 | is the starting frame to read |
zframes | is the number of frames to read |
Definition at line 1493 of file fitsFile.hpp.
void mx::fits::fitsFile< dataT >::setReadSize |
Set to read all the pixels in the file.
Definition at line 1464 of file fitsFile.hpp.
Referenced by mx::improc::HCIobservation< _realT >::readFiles(), mx::improc::HCIobservation< _realT >::readPSFSub(), and mx::improc::HCIobservation< _realT >::readRDIFiles().
void mx::fits::fitsFile< dataT >::setReadSize | ( | long | x0, |
long | y0, | ||
long | xpix, | ||
long | ypix | ||
) |
Set to read only a subset of the pixels in the file.
x0 | is the starting x-pixel to read |
y0 | is the starting y-pixel to read |
xpix | is the number of x-pixels to read |
ypix | is the number of y-pixels to read |
Definition at line 1473 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::write | ( | const dataT * | im, |
int | d1, | ||
int | d2, | ||
int | d3 | ||
) |
Write the contents of a raw array to the FITS file.
[in] | im | is the array |
[in] | d1 | is the first dimension |
[in] | d2 | is the second dimension |
[in] | d3 | is the third dimenesion (minimum value is 1) |
Definition at line 1393 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::write | ( | const dataT * | im, |
int | d1, | ||
int | d2, | ||
int | d3, | ||
fitsHeader & | head | ||
) |
Write the contents of a raw array to the FITS file.
Note: the type of the array must match dataT
[in] | im | is the array |
[in] | d1 | is the first dimension |
[in] | d2 | is the second dimension |
[in] | d3 | is the third dimenesion (minimum value is 1) |
[in] | head | is the header |
Definition at line 1403 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::write | ( | const dataT * | im, |
int | d1, | ||
int | d2, | ||
int | d3, | ||
fitsHeader * | head | ||
) |
Write the contents of a raw array to the FITS file.
[in] | im | is the array |
[in] | d1 | is the first dimension |
[in] | d2 | is the second dimension |
[in] | d3 | is the third dimenesion (minimum value is 1) |
[in] | head | a pointer to the header. Set to 0 if not used. |
Definition at line 1301 of file fitsFile.hpp.
References mx::fits::fitsHeader::begin(), mx::fits::fitsHeader::end(), and mx::fits::fitsErrText().
Referenced by mx::AO::sim::simulatedAOSystem< _realT, _wfsT, _reconT, _filterT, _dmT, _turbSeqT, _coronT >::~simulatedAOSystem(), mx::AO::circularPupil(), mx::AO::sim::turbAtmosphere< _aoSystemT >::genLayers(), mx::AO::influenceFunctionsGaussian(), mx::improc::ADIobservation< _realT, _derotFunctObj >::makeMaskCube(), mx::improc::HCIobservation< _realT >::outputPreProcessed(), mx::improc::HCIobservation< _realT >::outputPSFSub(), mx::improc::KLIPreduction< _realT, _derotFunctObj, _evCalcT >::regions(), mx::AO::sim::directPhaseReconstructor< realT >::saveRMat(), mx::improc::KLIPreduction< _realT, _derotFunctObj, _evCalcT >::worker(), and mx::improc::HCIobservation< _realT >::writeFinim().
int mx::fits::fitsFile< dataT >::write | ( | const std::string & | fname, |
const arrT & | im | ||
) |
Write the contents of an Eigen-type array to a FITS file.
The type arrT can be any type with the following members defined:
Note: as with all write methods, the Scalar type of the array must match dataT
arrT | is the type of array, see requirements above. |
[in] | fname | is the name of the file. |
[in] | im | is the array |
Definition at line 1441 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::write | ( | const std::string & | fname, |
const arrT & | im, | ||
fitsHeader & | head | ||
) |
Write the contents of an Eigen-type array to a FITS file.
The type arrT can be any type with the following members defined:
Note: as with all write methods, the Scalar type of the array must match dataT
arrT | is the type of array, see requirements above. |
[in] | fname | is the file path, which is passed to fileName |
[in] | im | is the array |
[in] | head | is a fitsHeader object which is passed to readHeader |
Definition at line 1453 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::write | ( | const std::string & | fname, |
const dataT * | im, | ||
int | d1, | ||
int | d2, | ||
int | d3 | ||
) |
Write the contents of a raw array to the FITS file.
[in] | fname | is the name of the file. |
[in] | im | is the array |
[in] | d1 | is the first dimension |
[in] | d2 | is the second dimension |
[in] | d3 | is the third dimenesion (minimum value is 1) |
Definition at line 1414 of file fitsFile.hpp.
int mx::fits::fitsFile< dataT >::write | ( | const std::string & | fname, |
const dataT * | im, | ||
int | d1, | ||
int | d2, | ||
int | d3, | ||
fitsHeader & | head | ||
) |
Write the contents of a raw array to the FITS file.
[in] | fname | is the name of the file. |
[in] | im | is the array |
[in] | d1 | is the first dimension |
[in] | d2 | is the second dimension |
[in] | d3 | is the third dimenesion (minimum value is 1) |
[in] | head | is the header |
Definition at line 1426 of file fitsFile.hpp.
|
protected |
Records whether any null values were replaced.
Definition at line 79 of file fitsFile.hpp.
|
protected |
The path to the file.
Definition at line 61 of file fitsFile.hpp.
|
protected |
The cfitsio data structure.
Definition at line 64 of file fitsFile.hpp.
|
protected |
Flag indicating whether the file is open or not.
Definition at line 73 of file fitsFile.hpp.
|
protected |
The size of each dimension.
Definition at line 70 of file fitsFile.hpp.
|
protected |
The dimensions of the image (1D, 2D, 3D etc)
Definition at line 67 of file fitsFile.hpp.
|
protected |
Flag to control whether the comment string is read.
Definition at line 82 of file fitsFile.hpp.
|
protected |
The value to replace null values with.
Definition at line 76 of file fitsFile.hpp.
|
protected |
The starting x-pixel to read from.
Definition at line 86 of file fitsFile.hpp.
|
protected |
The number of x-pixels to read.
Definition at line 92 of file fitsFile.hpp.
|
protected |
The starting y-pixel to read from.
Definition at line 89 of file fitsFile.hpp.
|
protected |
The number of y-pixels to read.
Definition at line 95 of file fitsFile.hpp.
|
protected |
The starting frame to read from a cube.
Definition at line 98 of file fitsFile.hpp.
|
protected |
The number of frames to read from a cube.
Definition at line 101 of file fitsFile.hpp.