source: branches/OptimisedGrowerTesting/src/fitsHeader.hh @ 1441

Last change on this file since 1441 was 1296, checked in by MatthewWhiting, 11 years ago

New wcs-pix conversion functions, that don't require you to provide C-arrays when converting a single location.

File size: 9.1 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#include <duchamp/duchamp.hh>
35#include <duchamp/FitsIO/DuchampBeam.hh>
36
37namespace duchamp
38{
39
40  class Param;
41
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  ///
48  class FitsHeader
49  {
50
51  public:
52    FitsHeader();
53    virtual ~FitsHeader();
54    FitsHeader(const FitsHeader& h);
55    FitsHeader& operator= (const FitsHeader& h);
56
57    //--------------------
58    // Functions in param.cc
59    //
60    /// @brief Assign correct WCS parameters. 
61    void    setWCS(struct wcsprm *w);
62
63    /// @brief Return the WCS parameters in a WCSLIB wcsprm struct.
64    struct wcsprm *getWCS();
65
66    /// @brief Provides a reference to the WCS parameters
67    struct wcsprm& WCS(){ struct wcsprm &rwcs = *wcs; return rwcs; };
68
69    // front ends to WCS functions
70    /// @brief Convert pixel coords to world coords for a single point.
71    int     wcsToPix(double xWorld, double yWorld, double zWorld, double &xPix, double &yPix, double &zPix);
72
73    /// @brief Convert pixel coords to world coords for a single point.
74    int     wcsToPix(const double *world, double *pix);
75
76    /// @brief Convert pixel coords to world coords for many points.
77    int     wcsToPix(const double *world, double *pix, const int npts);
78
79    /// @brief Convert world coords to pixel coords for a single point.
80    int     pixToWCS(double xPix, double yPix, double zPix, double &xWorld, double &yWorld, double &zWorld);
81
82    /// @brief Convert world coords to pixel coords for a single point.
83    int     pixToWCS(const double *pix, double *world);
84
85    /// @brief Convert world coords to pixel coords for many points.
86    int     pixToWCS(const double *pix, double *world, const int npts);
87
88    /// @brief Convert a (x,y,z) position to a velocity.
89    double  pixToVel(double &x, double &y, double &z);
90
91    /// @brief Convert a set of  (x,y,z) positions to a set of velocities.
92    double *pixToVel(double &x, double &y, double *zarray, int size);
93
94    /// @brief Convert a spectral coordinate to a velocity coordinate.
95    double  specToVel(const double &z);
96
97    /// @brief Convert a velocity coordinate to a spectral coordinate.
98    double  velToSpec(const float &vel);
99
100    /// @brief Get an IAU-style name for an equatorial or galactic coordinates.
101    std::string  getIAUName(double ra, double dec);
102
103    /// @brief Correct the units for the spectral axis
104    void    fixSpectralUnits(std::string units);
105   
106    /// @brief Define the units for integrated flux
107    void    setIntFluxUnits();
108
109    //--------------------
110    // Functions in FitsIO/headerIO.cc
111    //
112    /// @brief Read all header info.
113    OUTCOME     readHeaderInfo(std::string fname, Param &par);
114    OUTCOME     readHeaderInfo(Param &par);
115    OUTCOME     readHeaderInfo(fitsfile *fptr, Param &par);
116
117    /// @brief Read BUNIT keyword
118    // OUTCOME     readBUNIT(std::string fname);
119    OUTCOME     readBUNIT(fitsfile *fptr);
120
121    /// @brief Read BLANK & related keywords
122    // OUTCOME     readBLANKinfo(std::string fname, Param &par);
123    OUTCOME     readBLANKinfo(fitsfile *fptr, Param &par);
124
125    /// @brief Read beam-related keywords
126    // OUTCOME     readBeamInfo(std::string fname, Param &par);
127    OUTCOME     readBeamInfo(fitsfile *fptr, Param &par);
128 
129    //--------------------
130    // Function in FitsIO/wcsIO.cc
131    //
132    /// @brief Read the WCS information from a file.
133    OUTCOME     defineWCS(std::string fname, Param &par);
134    OUTCOME     defineWCS(Param &par);
135    OUTCOME     defineWCS(fitsfile *fptr, Param &par);
136    OUTCOME     defineWCS(wcsprm *theWCS, int nWCS, size_t *dimAxes, Param &par);
137
138    //--------------------
139    // Basic inline accessor functions
140    //
141    fitsfile *FPTR(){return fptr;};
142    int     openFITS(std::string name);
143    int     closeFITS();
144    /// @brief Is the WCS good enough to be used?
145    bool    isWCS(){return wcsIsGood;};
146    /// @brief Is the spectral axis OK to be used?
147    bool    isSpecOK(){return (wcs->spec >= 0);};
148    bool    canUseThirdAxis(){return ((wcs->spec >= 0)||(wcs->naxis>2));};
149    void    set2D(bool b){flag2D = b;};
150    bool    is2D(){return flag2D;};
151    int     getNWCS(){return nwcs;};
152    void    setNWCS(int i){nwcs=i;};
153    int     getNumAxes(){if(wcs->flag==-1) return 0; else return wcs->naxis;};
154    void    setNumAxes(int i){wcs->naxis=i;};
155    std::string  getSpectralUnits(){return spectralUnits;};
156    void    setSpectralUnits(std::string s){spectralUnits=s;};
157    std::string  getSpectralType(){return spectralType;};
158    void    setSpectralType(std::string s){spectralType=s;};
159    std::string  getSpectralDescription(){return spectralDescription;};
160    void    setSpectralDescription(std::string s){spectralDescription=s;};
161    std::string  getOrigFluxUnits(){return originalFluxUnits;};
162    void    setOrigFluxUnits(std::string s){originalFluxUnits=s;};
163    std::string  getFluxUnits(){return fluxUnits;};
164    void    setFluxUnits(std::string s){fluxUnits=s;};
165    std::string  getIntFluxUnits(){return intFluxUnits;};
166    void    setIntFluxUnits(std::string s){intFluxUnits=s;};
167    DuchampBeam getBeam(){return itsBeam;};
168    DuchampBeam& beam(){DuchampBeam& rbeam=itsBeam; return rbeam;};
169    void    setBeam(DuchampBeam &b){itsBeam=b;};
170    int     getBlankKeyword(){return blankKeyword;};
171    void    setBlankKeyword(int f){blankKeyword=f;};
172    float   getBzeroKeyword(){return bzeroKeyword;};
173    void    setBzeroKeyword(float f){bzeroKeyword=f;};
174    float   getBscaleKeyword(){return bscaleKeyword;};
175    void    setBscaleKeyword(float f){bscaleKeyword=f;};
176    std::string lngtype();
177    std::string lattype();
178
179    /// @brief Return the average pixel scale (eg deg/pix) of the two spatial axes.
180    float   getAvPixScale(){
181      return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])*
182                          (wcs->pc[wcs->naxis+1]*wcs->cdelt[1])));
183    };
184
185    float getShapeScale();
186    std::string getShapeUnits();
187
188    bool    needBeamSize();
189
190  private:
191    fitsfile      *fptr;                ///< A pointer to the FITS file that can be used by the cftisio library.
192    struct wcsprm *wcs;                 ///< The WCS parameters for the cube in a struct from the wcslib library.
193    int            nwcs;                ///< The number of WCS parameters
194    bool           wcsIsGood;           ///< A flag indicating whether there is a valid WCS present.
195    bool           flag2D;              ///< Is the image only a 2D one (leaving out redundant dimensions of size 1)?
196    std::string    spectralUnits;       ///< The units of the spectral dimension
197    std::string    spectralType;        ///< The spectral type - first 4 letters of the WCS ctype code. Used for the results output.
198    std::string    spectralDescription; ///< The description of the spectral dimension (Frequency, Velocity, ...)
199    std::string    originalFluxUnits;   ///< The units of pixel flux in the original image
200    std::string    fluxUnits;           ///< The units of pixel flux as used (either from image or from parameter set)
201    std::string    intFluxUnits;        ///< The units of integrated flux (from header)
202    DuchampBeam    itsBeam;             ///< The beam information
203    int            blankKeyword;        ///< The FITS header keyword BLANK.
204    float          bzeroKeyword;        ///< The FITS header keyword BZERO.
205    float          bscaleKeyword;       ///< The FITS header keyword BSCALE.
206    double         scale;               ///< scale parameter for converting spectral coords
207    double         offset;              ///< offset parameter for converting spectral coords
208    double         power;               ///< power parameter for converting spectral coords
209  };
210
211}
212
213#endif // FITSHEADER_H
Note: See TracBrowser for help on using the repository browser.