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 | // ----------------------------------------------------------------------- |
---|
28 | #ifndef FITSHEADER_H |
---|
29 | #define FITSHEADER_H |
---|
30 | |
---|
31 | #include <string> |
---|
32 | #include <wcslib/wcs.h> |
---|
33 | #include <math.h> |
---|
34 | |
---|
35 | namespace duchamp |
---|
36 | { |
---|
37 | |
---|
38 | |
---|
39 | class Param; |
---|
40 | |
---|
41 | /** |
---|
42 | * Class to store FITS header information. |
---|
43 | * |
---|
44 | * Stores information from a FITS header, including WCS information |
---|
45 | * in the form of a wcsprm struct, as well as various keywords. |
---|
46 | */ |
---|
47 | class FitsHeader |
---|
48 | { |
---|
49 | |
---|
50 | public: |
---|
51 | FitsHeader(); |
---|
52 | virtual ~FitsHeader(); |
---|
53 | FitsHeader(const FitsHeader& h); |
---|
54 | FitsHeader& operator= (const FitsHeader& h); |
---|
55 | |
---|
56 | //-------------------- |
---|
57 | // Functions in param.cc |
---|
58 | // |
---|
59 | /** Assign correct WCS parameters. */ |
---|
60 | void setWCS(struct wcsprm *w); |
---|
61 | |
---|
62 | /** Return the WCS parameters in a WCSLIB wcsprm struct. */ |
---|
63 | struct wcsprm *getWCS(); |
---|
64 | |
---|
65 | /** Provides a reference to the WCS parameters*/ |
---|
66 | struct wcsprm& WCS(){ struct wcsprm &rwcs = *wcs; return rwcs; }; |
---|
67 | |
---|
68 | // front ends to WCS functions |
---|
69 | /** Convert pixel coords to world coords for a single point. */ |
---|
70 | int wcsToPix(const double *world, double *pix); |
---|
71 | |
---|
72 | /** Convert pixel coords to world coords for many points. */ |
---|
73 | int wcsToPix(const double *world, double *pix, const int npts); |
---|
74 | |
---|
75 | /** Convert world coords to pixel coords for a single point. */ |
---|
76 | int pixToWCS(const double *pix, double *world); |
---|
77 | |
---|
78 | /** Convert world coords to pixel coords for many points. */ |
---|
79 | int pixToWCS(const double *pix, double *world, const int npts); |
---|
80 | |
---|
81 | /** Convert a (x,y,z) position to a velocity. */ |
---|
82 | double pixToVel(double &x, double &y, double &z); |
---|
83 | |
---|
84 | /** Convert a set of (x,y,z) positions to a set of velocities. */ |
---|
85 | double *pixToVel(double &x, double &y, double *zarray, int size); |
---|
86 | |
---|
87 | /** Convert a spectral coordinate to a velocity coordinate.*/ |
---|
88 | double specToVel(const double &z); |
---|
89 | |
---|
90 | /** Convert a velocity coordinate to a spectral coordinate.*/ |
---|
91 | double velToSpec(const float &vel); |
---|
92 | |
---|
93 | /** Get an IAU-style name for an equatorial or galactic coordinates. */ |
---|
94 | std::string getIAUName(double ra, double dec); |
---|
95 | |
---|
96 | /** Correct the units for the spectral axis */ |
---|
97 | void fixUnits(Param &par); |
---|
98 | |
---|
99 | /** Define the units for integrated flux */ |
---|
100 | void setIntFluxUnits(); |
---|
101 | |
---|
102 | //-------------------- |
---|
103 | // Functions in FitsIO/headerIO.cc |
---|
104 | // |
---|
105 | /** Read all header info. */ |
---|
106 | int readHeaderInfo(std::string fname, Param &par); |
---|
107 | |
---|
108 | /** Read BUNIT keyword */ |
---|
109 | int readBUNIT(std::string fname); |
---|
110 | |
---|
111 | /** Read BLANK & related keywords */ |
---|
112 | int readBLANKinfo(std::string fname, Param &par); |
---|
113 | |
---|
114 | /** Read beam-related keywords */ |
---|
115 | int readBeamInfo(std::string fname, Param &par); |
---|
116 | |
---|
117 | //-------------------- |
---|
118 | // Function in FitsIO/wcsIO.cc |
---|
119 | // |
---|
120 | /** Read the WCS information from a file. */ |
---|
121 | int defineWCS(std::string fname, Param &par); |
---|
122 | |
---|
123 | //-------------------- |
---|
124 | // Basic inline accessor functions |
---|
125 | // |
---|
126 | /** Is the WCS good enough to be used? */ |
---|
127 | bool isWCS(){return wcsIsGood;}; |
---|
128 | /** Is the spectral axis OK to be used? */ |
---|
129 | bool isSpecOK(){return (wcs->spec >= 0);}; |
---|
130 | bool canUseThirdAxis(){return ((wcs->spec >= 0)||(wcs->naxis>2));}; |
---|
131 | void set2D(bool b){flag2D = b;}; |
---|
132 | bool is2D(){return flag2D;}; |
---|
133 | int getNWCS(){return nwcs;}; |
---|
134 | void setNWCS(int i){nwcs=i;}; |
---|
135 | int getNumAxes(){if(wcs->flag==-1) return 0; else return wcs->naxis;}; |
---|
136 | void setNumAxes(int i){wcs->naxis=i;}; |
---|
137 | std::string getSpectralUnits(){return spectralUnits;}; |
---|
138 | void setSpectralUnits(std::string s){spectralUnits=s;}; |
---|
139 | std::string getSpectralDescription(){return spectralDescription;}; |
---|
140 | void setSpectralDescription(std::string s){spectralDescription=s;}; |
---|
141 | std::string getFluxUnits(){return fluxUnits;}; |
---|
142 | void setFluxUnits(std::string s){fluxUnits=s;}; |
---|
143 | std::string getIntFluxUnits(){return intFluxUnits;}; |
---|
144 | void setIntFluxUnits(std::string s){intFluxUnits=s;}; |
---|
145 | float getBeamSize(){return beamSize;}; |
---|
146 | void setBeamSize(float f){beamSize=f;}; |
---|
147 | float getBmajKeyword(){return bmajKeyword;}; |
---|
148 | void setBmajKeyword(float f){bmajKeyword=f;}; |
---|
149 | float getBminKeyword(){return bminKeyword;}; |
---|
150 | void setBminKeyword(float f){bminKeyword=f;}; |
---|
151 | float getBpaKeyword(){return bpaKeyword;}; |
---|
152 | void setBpaKeyword(float f){bpaKeyword=f;}; |
---|
153 | int getBlankKeyword(){return blankKeyword;}; |
---|
154 | void setBlankKeyword(int f){blankKeyword=f;}; |
---|
155 | float getBzeroKeyword(){return bzeroKeyword;}; |
---|
156 | void setBzeroKeyword(float f){bzeroKeyword=f;}; |
---|
157 | float getBscaleKeyword(){return bscaleKeyword;}; |
---|
158 | void setBscaleKeyword(float f){bscaleKeyword=f;}; |
---|
159 | |
---|
160 | /** Average the pixel scale (eg arcmin/pix) between the two |
---|
161 | spatial axes, and return. */ |
---|
162 | float getAvPixScale(){ |
---|
163 | return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])* |
---|
164 | (wcs->pc[wcs->naxis+1]*wcs->cdelt[1]))); |
---|
165 | }; |
---|
166 | |
---|
167 | bool needBeamSize(); |
---|
168 | |
---|
169 | private: |
---|
170 | struct wcsprm *wcs; ///< The WCS parameters for the cube |
---|
171 | /// in a struct from the wcslib |
---|
172 | /// library. |
---|
173 | int nwcs; ///< The number of WCS parameters |
---|
174 | bool wcsIsGood; ///< A flag indicating whether there |
---|
175 | /// is a valid WCS present. |
---|
176 | int naxis; ///< How many axes are in the header? |
---|
177 | bool flag2D; ///< Is the image only a 2D one (leaving out redundant dimensions of size 1)? |
---|
178 | std::string spectralUnits; ///< The units of the spectral dimension |
---|
179 | std::string spectralDescription; ///< The description of the |
---|
180 | /// spectral dimension (Frequency, |
---|
181 | /// Velocity, ...) |
---|
182 | std::string fluxUnits; ///< The units of pixel flux (from header) |
---|
183 | std::string intFluxUnits; ///< The units of integrated flux (from header) |
---|
184 | float beamSize; ///< The calculated beam size in pixels. |
---|
185 | float bmajKeyword; ///< The FITS header keyword BMAJ. |
---|
186 | float bminKeyword; ///< The FITS header keyword BMIN. |
---|
187 | float bpaKeyword; ///< The FITS header keyword BPA. |
---|
188 | int blankKeyword; ///< The FITS header keyword BLANK. |
---|
189 | float bzeroKeyword; ///< The FITS header keyword BZERO. |
---|
190 | float bscaleKeyword; ///< The FITS header keyword BSCALE. |
---|
191 | double scale; ///< scale parameter for converting |
---|
192 | /// spectral coords |
---|
193 | double offset; ///< offset parameter for converting |
---|
194 | /// spectral coords |
---|
195 | double power; ///< power parameter for converting |
---|
196 | /// spectral coords |
---|
197 | }; |
---|
198 | |
---|
199 | } |
---|
200 | |
---|
201 | #endif // FITSHEADER_H |
---|