[299] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // fitsHeader.hh: Information about the FITS file's header. |
---|
| 3 | // ----------------------------------------------------------------------- |
---|
| 4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 5 | // |
---|
| 6 | // This program is free software; you can redistribute it and/or modify it |
---|
| 7 | // under the terms of the GNU General Public License as published by the |
---|
| 8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 9 | // option) any later version. |
---|
| 10 | // |
---|
| 11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 14 | // for more details. |
---|
| 15 | // |
---|
| 16 | // You should have received a copy of the GNU General Public License |
---|
| 17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 19 | // |
---|
| 20 | // Correspondence concerning Duchamp may be directed to: |
---|
| 21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 22 | // Postal address: Dr. Matthew Whiting |
---|
| 23 | // Australia Telescope National Facility, CSIRO |
---|
| 24 | // PO Box 76 |
---|
| 25 | // Epping NSW 1710 |
---|
| 26 | // AUSTRALIA |
---|
| 27 | // ----------------------------------------------------------------------- |
---|
[272] | 28 | #ifndef FITSHEADER_H |
---|
| 29 | #define FITSHEADER_H |
---|
| 30 | |
---|
| 31 | #include <string> |
---|
[394] | 32 | #include <wcslib/wcs.h> |
---|
[377] | 33 | #include <math.h> |
---|
[708] | 34 | #include <duchamp/duchamp.hh> |
---|
[788] | 35 | #include <duchamp/FitsIO/DuchampBeam.hh> |
---|
[272] | 36 | |
---|
[378] | 37 | namespace duchamp |
---|
[272] | 38 | { |
---|
| 39 | |
---|
[378] | 40 | class Param; |
---|
[272] | 41 | |
---|
[528] | 42 | /// |
---|
| 43 | /// @brief Class to store FITS header information. |
---|
| 44 | /// |
---|
| 45 | /// @details Stores information from a FITS header, including WCS information |
---|
| 46 | /// in the form of a wcsprm struct, as well as various keywords. |
---|
| 47 | /// |
---|
[378] | 48 | class FitsHeader |
---|
| 49 | { |
---|
[272] | 50 | |
---|
[378] | 51 | public: |
---|
| 52 | FitsHeader(); |
---|
| 53 | virtual ~FitsHeader(); |
---|
| 54 | FitsHeader(const FitsHeader& h); |
---|
| 55 | FitsHeader& operator= (const FitsHeader& h); |
---|
[291] | 56 | |
---|
[378] | 57 | //-------------------- |
---|
| 58 | // Functions in param.cc |
---|
| 59 | // |
---|
[528] | 60 | /// @brief Assign correct WCS parameters. |
---|
[378] | 61 | void setWCS(struct wcsprm *w); |
---|
[272] | 62 | |
---|
[528] | 63 | /// @brief Return the WCS parameters in a WCSLIB wcsprm struct. |
---|
[378] | 64 | struct wcsprm *getWCS(); |
---|
[272] | 65 | |
---|
[528] | 66 | /// @brief Provides a reference to the WCS parameters |
---|
[378] | 67 | struct wcsprm& WCS(){ struct wcsprm &rwcs = *wcs; return rwcs; }; |
---|
[272] | 68 | |
---|
[378] | 69 | // front ends to WCS functions |
---|
[528] | 70 | /// @brief Convert pixel coords to world coords for a single point. |
---|
[378] | 71 | int wcsToPix(const double *world, double *pix); |
---|
[272] | 72 | |
---|
[528] | 73 | /// @brief Convert pixel coords to world coords for many points. |
---|
[378] | 74 | int wcsToPix(const double *world, double *pix, const int npts); |
---|
[272] | 75 | |
---|
[528] | 76 | /// @brief Convert world coords to pixel coords for a single point. |
---|
[378] | 77 | int pixToWCS(const double *pix, double *world); |
---|
[272] | 78 | |
---|
[528] | 79 | /// @brief Convert world coords to pixel coords for many points. |
---|
[378] | 80 | int pixToWCS(const double *pix, double *world, const int npts); |
---|
[272] | 81 | |
---|
[528] | 82 | /// @brief Convert a (x,y,z) position to a velocity. |
---|
[378] | 83 | double pixToVel(double &x, double &y, double &z); |
---|
[272] | 84 | |
---|
[528] | 85 | /// @brief Convert a set of (x,y,z) positions to a set of velocities. |
---|
[378] | 86 | double *pixToVel(double &x, double &y, double *zarray, int size); |
---|
[272] | 87 | |
---|
[528] | 88 | /// @brief Convert a spectral coordinate to a velocity coordinate. |
---|
[378] | 89 | double specToVel(const double &z); |
---|
| 90 | |
---|
[528] | 91 | /// @brief Convert a velocity coordinate to a spectral coordinate. |
---|
[378] | 92 | double velToSpec(const float &vel); |
---|
| 93 | |
---|
[528] | 94 | /// @brief Get an IAU-style name for an equatorial or galactic coordinates. |
---|
[378] | 95 | std::string getIAUName(double ra, double dec); |
---|
| 96 | |
---|
[528] | 97 | /// @brief Correct the units for the spectral axis |
---|
[378] | 98 | void fixUnits(Param &par); |
---|
[434] | 99 | |
---|
[528] | 100 | /// @brief Define the units for integrated flux |
---|
[434] | 101 | void setIntFluxUnits(); |
---|
| 102 | |
---|
[378] | 103 | //-------------------- |
---|
| 104 | // Functions in FitsIO/headerIO.cc |
---|
| 105 | // |
---|
[528] | 106 | /// @brief Read all header info. |
---|
[698] | 107 | OUTCOME readHeaderInfo(std::string fname, Param &par); |
---|
[272] | 108 | |
---|
[528] | 109 | /// @brief Read BUNIT keyword |
---|
[698] | 110 | OUTCOME readBUNIT(std::string fname); |
---|
[272] | 111 | |
---|
[528] | 112 | /// @brief Read BLANK & related keywords |
---|
[698] | 113 | OUTCOME readBLANKinfo(std::string fname, Param &par); |
---|
[272] | 114 | |
---|
[528] | 115 | /// @brief Read beam-related keywords |
---|
[698] | 116 | OUTCOME readBeamInfo(std::string fname, Param &par); |
---|
[272] | 117 | |
---|
[378] | 118 | //-------------------- |
---|
| 119 | // Function in FitsIO/wcsIO.cc |
---|
| 120 | // |
---|
[528] | 121 | /// @brief Read the WCS information from a file. |
---|
[698] | 122 | OUTCOME defineWCS(std::string fname, Param &par); |
---|
[272] | 123 | |
---|
[378] | 124 | //-------------------- |
---|
| 125 | // Basic inline accessor functions |
---|
| 126 | // |
---|
[528] | 127 | /// @brief Is the WCS good enough to be used? |
---|
[378] | 128 | bool isWCS(){return wcsIsGood;}; |
---|
[528] | 129 | /// @brief Is the spectral axis OK to be used? |
---|
[378] | 130 | bool isSpecOK(){return (wcs->spec >= 0);}; |
---|
[494] | 131 | bool canUseThirdAxis(){return ((wcs->spec >= 0)||(wcs->naxis>2));}; |
---|
[513] | 132 | void set2D(bool b){flag2D = b;}; |
---|
| 133 | bool is2D(){return flag2D;}; |
---|
[378] | 134 | int getNWCS(){return nwcs;}; |
---|
| 135 | void setNWCS(int i){nwcs=i;}; |
---|
[494] | 136 | int getNumAxes(){if(wcs->flag==-1) return 0; else return wcs->naxis;}; |
---|
| 137 | void setNumAxes(int i){wcs->naxis=i;}; |
---|
[378] | 138 | std::string getSpectralUnits(){return spectralUnits;}; |
---|
| 139 | void setSpectralUnits(std::string s){spectralUnits=s;}; |
---|
| 140 | std::string getSpectralDescription(){return spectralDescription;}; |
---|
| 141 | void setSpectralDescription(std::string s){spectralDescription=s;}; |
---|
[757] | 142 | std::string getOrigFluxUnits(){return originalFluxUnits;}; |
---|
| 143 | void setOrigFluxUnits(std::string s){originalFluxUnits=s;}; |
---|
[378] | 144 | std::string getFluxUnits(){return fluxUnits;}; |
---|
| 145 | void setFluxUnits(std::string s){fluxUnits=s;}; |
---|
| 146 | std::string getIntFluxUnits(){return intFluxUnits;}; |
---|
| 147 | void setIntFluxUnits(std::string s){intFluxUnits=s;}; |
---|
[788] | 148 | DuchampBeam getBeam(){return itsBeam;}; |
---|
| 149 | DuchampBeam& beam(){DuchampBeam& rbeam=itsBeam; return rbeam;}; |
---|
| 150 | void setBeam(DuchampBeam &b){itsBeam=b;}; |
---|
[378] | 151 | int getBlankKeyword(){return blankKeyword;}; |
---|
| 152 | void setBlankKeyword(int f){blankKeyword=f;}; |
---|
| 153 | float getBzeroKeyword(){return bzeroKeyword;}; |
---|
| 154 | void setBzeroKeyword(float f){bzeroKeyword=f;}; |
---|
| 155 | float getBscaleKeyword(){return bscaleKeyword;}; |
---|
| 156 | void setBscaleKeyword(float f){bscaleKeyword=f;}; |
---|
[290] | 157 | |
---|
[528] | 158 | /// @brief Return the average pixel scale (eg arcmin/pix) of the two spatial axes. |
---|
[378] | 159 | float getAvPixScale(){ |
---|
| 160 | return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])* |
---|
| 161 | (wcs->pc[wcs->naxis+1]*wcs->cdelt[1]))); |
---|
| 162 | }; |
---|
| 163 | |
---|
| 164 | bool needBeamSize(); |
---|
| 165 | |
---|
| 166 | private: |
---|
[528] | 167 | struct wcsprm *wcs; ///< The WCS parameters for the cube in a struct from the wcslib library. |
---|
| 168 | int nwcs; ///< The number of WCS parameters |
---|
| 169 | bool wcsIsGood; ///< A flag indicating whether there is a valid WCS present. |
---|
| 170 | int naxis; ///< How many axes are in the header? |
---|
| 171 | bool flag2D; ///< Is the image only a 2D one (leaving out redundant dimensions of size 1)? |
---|
| 172 | std::string spectralUnits; ///< The units of the spectral dimension |
---|
| 173 | std::string spectralDescription; ///< The description of the spectral dimension (Frequency, Velocity, ...) |
---|
[757] | 174 | std::string originalFluxUnits; ///< The units of pixel flux in the original image |
---|
| 175 | std::string fluxUnits; ///< The units of pixel flux as used (either from image or from parameter set) |
---|
[528] | 176 | std::string intFluxUnits; ///< The units of integrated flux (from header) |
---|
[788] | 177 | DuchampBeam itsBeam; ///< The beam information |
---|
[528] | 178 | int blankKeyword; ///< The FITS header keyword BLANK. |
---|
| 179 | float bzeroKeyword; ///< The FITS header keyword BZERO. |
---|
| 180 | float bscaleKeyword; ///< The FITS header keyword BSCALE. |
---|
| 181 | double scale; ///< scale parameter for converting spectral coords |
---|
| 182 | double offset; ///< offset parameter for converting spectral coords |
---|
| 183 | double power; ///< power parameter for converting spectral coords |
---|
[272] | 184 | }; |
---|
| 185 | |
---|
[378] | 186 | } |
---|
[272] | 187 | |
---|
| 188 | #endif // FITSHEADER_H |
---|