source: tags/release-1.1.9/src/fitsHeader.hh @ 705

Last change on this file since 705 was 698, checked in by MatthewWhiting, 14 years ago

A bunch of changes aimed at improving the use of OUTCOME to report SUCCESS/FAILURE. When such a value is returned by a function, the returned type is duchamp::OUTCOME.

Also improved the error reporting in saveImage

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