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

Last change on this file since 1441 was 709, checked in by MatthewWhiting, 14 years ago

As for [708].

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