source: trunk/src/param.hh @ 187

Last change on this file since 187 was 187, checked in by Matthew Whiting, 18 years ago

Large suite of edits, mostly due to testing with valgrind, which clear up bad memory allocations and so on.
Improved the printing of progress bars in some routines by introducing a new ProgressBar? class, with associated functions to do the printing (now much cleaner).

File size: 16.6 KB
Line 
1#ifndef PARAM_H
2#define PARAM_H
3
4#include <iostream>
5#include <string>
6#include <vector>
7#include <math.h>
8#include <wcs.h>
9
10using std::string;
11using std::vector;
12
13/**
14 * Param class.
15 *   Used for storing parameters used by all functions.
16 */
17
18class FitsHeader; // foreshadow this so that Param knows it exists
19
20class Param
21{
22public:
23  Param();
24  virtual ~Param(){};
25  Param& operator= (const Param& p);
26  int    verifySubsection();              // in FitsIO/subsection.cc
27  void   setOffsets(wcsprm *wcs);         // in FitsIO/subsection.cc
28  int    readParams(string paramfile);    // in param.cc
29  void   copyHeaderInfo(FitsHeader &head);// in param.cc
30  bool   isBlank(float &value);           // in param.cc
31  bool   isInMW(int z){return ( flagMW && (z>=minMW) && (z<=maxMW) );};
32  string outputReconFile();             // in param.cc
33  string outputResidFile();             // in param.cc
34  friend std::ostream& operator<< ( std::ostream& theStream, Param& par);
35  friend class Image;
36 
37  //
38  string getImageFile(){return imageFile;};
39  void   setImageFile(string fname){imageFile = fname;};
40  string getFullImageFile(){
41    if(flagSubsection) return imageFile+subsection;
42    else return imageFile;
43  };
44  bool   getFlagSubsection(){return flagSubsection;};
45  void   setFlagSubsection(bool flag){flagSubsection=flag;};
46  string getSubsection(){return subsection;};
47  void   setSubsection(string range){subsection = range;};
48  bool   getFlagReconExists(){return flagReconExists;};
49  void   setFlagReconExists(bool flag){flagReconExists=flag;};
50  string getReconFile(){return reconFile;};
51  void   setReconFile(string file){reconFile = file;};
52  //
53  bool   getFlagLog(){return flagLog;};
54  void   setFlagLog(bool flag){flagLog=flag;};
55  string getLogFile(){return logFile;};
56  void   setLogFile(string fname){logFile = fname;};
57  string getOutFile(){return outFile;};
58  void   setOutFile(string fname){outFile = fname;};
59  string getSpectraFile(){return spectraFile;};
60  void   setSpectraFile(string fname){spectraFile = fname;};
61  bool   getFlagOutputRecon(){return flagOutputRecon;};
62  void   setFlagOutputRecon(bool flag){flagOutputRecon=flag;};
63  bool   getFlagOutputResid(){return flagOutputResid;};
64  void   setFlagOutputResid(bool flag){flagOutputResid=flag;};
65  bool   getFlagVOT(){return flagVOT;};
66  void   setFlagVOT(bool flag){flagVOT=flag;};
67  string getVOTFile(){return votFile;};
68  void   setVOTFile(string fname){votFile = fname;};
69  bool   getFlagKarma(){return flagKarma;};
70  void   setFlagKarma(bool flag){flagKarma=flag;};
71  string getKarmaFile(){return karmaFile;};
72  void   setKarmaFile(string fname){karmaFile = fname;};
73  bool   getFlagMaps(){return flagMaps;};
74  void   setFlagMaps(bool flag){flagMaps=flag;};
75  string getDetectionMap(){return detectionMap;};
76  void   setDetectionMap(string fname){detectionMap = fname;};
77  string getMomentMap(){return momentMap;};
78  void   setMomentMap(string fname){momentMap = fname;};
79  //
80  bool   getFlagNegative(){return flagNegative;};
81  void   setFlagNegative(bool flag){flagNegative=flag;};
82  bool   getFlagBlankPix(){return flagBlankPix;};
83  void   setFlagBlankPix(bool flag){flagBlankPix=flag;};
84  float  getBlankPixVal(){return blankPixValue;};
85  void   setBlankPixVal(float v){blankPixValue=v;};
86  int    getBlankKeyword(){return blankKeyword;};
87  void   setBlankKeyword(int v){blankKeyword=v;};
88  float  getBscaleKeyword(){return bscaleKeyword;};
89  void   setBscaleKeyword(float v){bscaleKeyword=v;};
90  float  getBzeroKeyword(){return bzeroKeyword;};
91  void   setBzeroKeyword(float v){bzeroKeyword=v;};
92  bool   getFlagUsingBlank(){return flagUsingBlank;};
93  void   setFlagUsingBlank(bool b){flagUsingBlank=b;};
94  bool   getFlagMW(){return flagMW;};
95  bool   setFlagMW(bool flag){flagMW=flag;};
96  int    getMaxMW(){return maxMW;};
97  void   setMaxMW(int m){maxMW=m;};
98  int    getMinMW(){return minMW;};
99  void   setMinMW(int m){minMW=m;};
100  void   setBeamSize(float s){numPixBeam = s;};
101  float  getBeamSize(){return numPixBeam;};
102  bool   getFlagUsingBeam(){return flagUsingBeam;};
103  void   setFlagUsingBeam(bool b){flagUsingBeam=b;};
104  //
105  bool   getFlagCubeTrimmed(){return flagTrimmed;};
106  void   setFlagCubeTrimmed(bool flag){flagTrimmed = flag;};
107  long   getBorderLeft(){return borderLeft;};
108  void   setBorderLeft(long b){borderLeft = b;};
109  long   getBorderRight(){return borderRight;};
110  void   setBorderRight(long b){borderRight = b;};
111  long   getBorderBottom(){return borderBottom;};
112  void   setBorderBottom(long b){borderBottom = b;};
113  long   getBorderTop(){return borderTop;};
114  void   setBorderTop(long b){borderTop = b;};
115  //
116  long   getXOffset(){return xSubOffset;};
117  void   setXOffset(long o){xSubOffset = o;};
118  long   getYOffset(){return ySubOffset;};
119  void   setYOffset(long o){ySubOffset = o;};
120  long   getZOffset(){return zSubOffset;};
121  void   setZOffset(long o){zSubOffset = o;};
122  //
123  int    getMinPix(){return minPix;};
124  void   setMinPix(int m){minPix=m;};
125  //     
126  bool   getFlagGrowth(){return flagGrowth;};
127  void   setFlagGrowth(bool flag){flagGrowth=flag;};
128  float  getGrowthCut(){return growthCut;};
129  void   setGrowthCut(float c){growthCut=c;};
130  //     
131  bool   getFlagFDR(){return flagFDR;};
132  void   setFlagFDR(bool flag){flagFDR=flag;};
133  float  getAlpha(){return alphaFDR;};
134  void   setAlpha(float a){alphaFDR=a;};
135  //
136  bool   getFlagBaseline(){return flagBaseline;};
137  void   setFlagBaseline(bool flag){flagBaseline = flag;};
138  //
139  float  getCut(){return snrCut;};
140  void   setCut(float c){snrCut=c;};
141  //     
142  bool   getFlagATrous(){return flagATrous;};
143  void   setFlagATrous(bool flag){flagATrous=flag;};
144  int    getReconDim(){return reconDim;};
145  void   setReconDim(int i){reconDim=i;};
146  int    getMinScale(){return scaleMin;};
147  void   setMinScale(int s){scaleMin=s;};
148  float  getAtrousCut(){return snrRecon;};
149  void   setAtrousCut(float c){snrRecon=c;};
150  int    getFilterCode(){return filterCode;};
151  void   setFilterCode(int c){filterCode=c;};
152  string getFilterName(){return filterName;};
153  void   setFilterName(string s){filterName=s;};
154  //     
155  bool   getFlagAdjacent(){return flagAdjacent;};
156  void   setFlagAdjacent(bool flag){flagAdjacent=flag;};
157  float  getThreshS(){return threshSpatial;};
158  void   setThreshS(float t){threshSpatial=t;};
159  float  getThreshV(){return threshVelocity;};
160  void   setThreshV(float t){threshVelocity=t;};
161  int    getMinChannels(){return minChannels;};
162  void   setMinChannels(int n){minChannels=n;};
163  //
164  string getSpectralMethod(){return spectralMethod;};
165  void   setSpectralMethod(string s){spectralMethod=s;};
166  string getSpectralUnits(){return spectralUnits;};
167  void   setSpectralUnits(string s){spectralUnits=s;};
168  bool   drawBorders(){return borders;};
169  void   setDrawBorders(bool f){borders=f;};
170  bool   drawBlankEdge(){return blankEdge;};
171  void   setDrawBlankEdge(bool f){blankEdge=f;};
172  bool   isVerbose(){return verbose;};
173  void   setVerbosity(bool f){verbose=f;};
174 
175private:
176  // Input files
177  string imageFile;       // The image to be analysed.
178  bool   flagSubsection;  // Whether we just want a subsection of the image
179  string subsection;      // The subsection requested, taking the form
180                          //  [x1:x2,y1:y2,z1:z2]
181                          //  If you want the full range of one index, use *
182  bool   flagReconExists; // The reconstructed array is in a FITS file on disk.
183  string reconFile;       // The FITS file containing the reconstructed array.
184
185  // Output files
186  bool   flagLog;         // Should we do the intermediate logging?
187  string logFile;         // Where the intermediate logging goes.
188  string outFile;         // Where the final results get put.
189  string spectraFile;     // Where the spectra are displayed
190  bool   flagOutputRecon; // Should the reconstructed cube be written?
191  bool   flagOutputResid; // Should the reconstructed cube be written?
192  bool   flagVOT;         // Should we save results in VOTable format?
193  string votFile;         // Where the VOTable goes.
194  bool   flagKarma;       // Should we save results in Karma annotation format?
195  string karmaFile;       // Where the Karma annotation file goes.
196  bool   flagMaps;        // Should we produce detection and moment maps
197                          //  in postscript form?
198  string detectionMap;    // The name of the detection map (ps file).
199  string momentMap;       // The name of the 0th moment map (ps file).
200
201  // Cube related parameters
202  bool   flagNegative;    // Are we going to search for negative features?
203  bool   flagBlankPix;    // A flag that indicates whether there are pixels
204                          //   defined as BLANK and whether we need to remove
205                          //   & ignore them in processing.
206  float  blankPixValue;   // Pixel value that is considered BLANK.
207  int    blankKeyword;    // The FITS header keyword BLANK.
208  float  bscaleKeyword;   // The FITS header keyword BSCALE.
209  float  bzeroKeyword;    // The FITS header keyword BZERO.
210  bool   flagUsingBlank;  // If true, we are using the blankPixValue keyword,
211                          // otherwise we use the value in the FITS header.
212  bool   flagMW;          // A flag that indicates whether to ignore the
213                          //  Milky Way channels.
214  int    maxMW;           // Last  Galactic velocity plane for HIPASS cubes
215  int    minMW;           // First Galactic velocity plane for HIPASS cubes
216  float  numPixBeam;      // Size (area) of the beam in pixels.
217  bool   flagUsingBeam;   // If true, we are using the numPixBeam parameter,
218                          // otherwise we use the value in the FITS header.
219  // Trim-related         
220  bool   flagTrimmed;     // Has the cube been trimmed of excess BLANKs
221                          //  around the edge?
222  long   borderLeft;      // The number of BLANK pixels trimmed from the
223                          //   Left of the cube;
224  long   borderRight;     // The number trimmed from the Right of the cube;
225  long   borderBottom;    // The number trimmed from the Bottom of the cube;
226  long   borderTop;       // The number trimmed from the Top of the cube;
227  // Subsection offsets
228  long  *offsets;         // The array of offsets for each FITS axis.
229  long   xSubOffset;      // The offset in the x-direction from the subsection
230  long   ySubOffset;      // The offset in the y-direction from the subsection
231  long   zSubOffset;      // The offset in the z-direction from the subsection
232  // Baseline related;
233  bool   flagBaseline;    // Whether to do baseline subtraction before
234                          //  reconstruction and/or searching.
235  // Detection-related   
236  int    minPix;          // Minimum number of pixels for a detected object
237                          //   to be counted
238  // Object growth       
239  bool   flagGrowth;      // Are we growing objects once they are found?
240  float  growthCut;       // The SNR that we are growing objects down to.
241  // FDR analysis         
242  bool   flagFDR;         // Should the FDR method be used?
243  float  alphaFDR;        // Alpha value for FDR detection algorithm
244  // Other detection     
245  float  snrCut;          // How many sigma above mean is a detection
246                          //   when sigma-clipping
247  // A trous reconstruction parameters
248  bool   flagATrous;      // Are we using the a trous reconstruction?
249  int    reconDim;        // How many dimensions to use for the reconstruction?
250  int    scaleMin;        // Min scale used in a trous reconstruction
251  float  snrRecon;        // SNR cutoff used in a trous reconstruction
252                          //   (only wavelet coefficients that survive this
253                          //    threshold are kept)
254  int    filterCode;      // The code number for the filter to be used
255                          //  (saves having to parse names)
256  string filterName;      // The code number converted into a name,
257                          //  for outputting purposes.
258
259  // Volume-merging parameters
260  bool   flagAdjacent;    // Whether to use the adjacent criterion for
261                          //    judging if objects are to be merged.
262  float  threshSpatial;   // Maximum spatial separation between objects
263  float  threshVelocity;  // Maximum channels separation between objects
264  int    minChannels;     // Minimum no. of channels to make an object
265  // Input-Output related
266  string spectralMethod;  // A string indicating choice of spectral plotting
267                          //  method: choices are "peak" (default) or "sum"
268  string spectralUnits;   // A string indicating what units the spectral
269                          //  axis should be quoted in.
270  bool   borders;         // Whether to draw a border around the individual
271                          //  pixels of a detection in the spectral display
272  bool   blankEdge;       // Whether to draw a border around the BLANK pixel
273                          //  region in the moment maps and cutout images
274  bool   verbose;         // Whether to use maximum verbosity -- use progress
275                          //  indicators in the reconstruction & merging steps.
276
277};
278
279class FitsHeader
280{
281  /**
282   *  FitsHeader Class
283   *
284   *   Stores information from a FITS header, including WCS information
285   *    in the form of a wcsprm struct, as well as various keywords.
286   */
287
288public:
289  FitsHeader();
290  ~FitsHeader(){};
291  FitsHeader(const FitsHeader& h);
292  FitsHeader& operator= (const FitsHeader& h);
293
294  wcsprm *getWCS();             // in param.cc
295  void    setWCS(wcsprm *w);    // in param.cc
296  bool    isWCS(){return wcsIsGood;};
297  int     getNWCS(){return nwcs;};
298  void    setNWCS(int i){nwcs=i;};
299  int     readHeaderInfo(string fname, Param &par);
300  int     defineWCS(string fname, Param &par);
301  int     getBUNIT(string fname);
302  int     getBLANKinfo(string fname, Param &par);
303  int     getBeamInfo(string fname, Param &par);
304  string  getSpectralUnits(){return spectralUnits;};
305  void    setSpectralUnits(string s){spectralUnits=s;};
306  string  getSpectralDescription(){return spectralDescription;};
307  void    setSpectralDescription(string s){spectralDescription=s;};
308  string  getFluxUnits(){return fluxUnits;};
309  void    setFluxUnits(string s){fluxUnits=s;};
310  string  getIntFluxUnits(){return intFluxUnits;};
311  void    setIntFluxUnits(string s){intFluxUnits=s;};
312  float   getBeamSize(){return beamSize;};
313  void    setBeamSize(float f){beamSize=f;};
314  float   getBmajKeyword(){return bmajKeyword;};
315  void    setBmajKeyword(float f){bmajKeyword=f;};
316  float   getBminKeyword(){return bminKeyword;};
317  void    setBminKeyword(float f){bminKeyword=f;};
318  int     getBlankKeyword(){return blankKeyword;};
319  void    setBlankKeyword(int f){blankKeyword=f;};
320  float   getBzeroKeyword(){return bzeroKeyword;};
321  void    setBzeroKeyword(float f){bzeroKeyword=f;};
322  float   getBscaleKeyword(){return bscaleKeyword;};
323  void    setBscaleKeyword(float f){bscaleKeyword=f;};
324  float   getAvPixScale(){
325    return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])*
326                        (wcs->pc[wcs->naxis+1]*wcs->cdelt[1])));
327  };
328
329  // front ends to WCS functions
330  int     wcsToPix(const double *world, double *pix);
331  int     pixToWCS(const double *pix, double *world);
332  int     wcsToPix(const double *world, double *pix, const int npts);
333  int     pixToWCS(const double *pix, double *world, const int npts);
334  double  pixToVel(double &x, double &y, double &z);
335  double *pixToVel(double &x, double &y, double *zarray, int size);
336  double  specToVel(const double &z);
337  double  velToSpec(const float &vel);
338  string  getIAUName(double ra, double dec);
339
340  void    fixUnits(Param &par);
341 
342private:
343  wcsprm *wcs;                  // The WCS parameters for the cube in a
344                                //  struct from the wcslib library.
345  int     nwcs;                 // The number of WCS parameters
346  bool    wcsIsGood;            // A flag indicating whether there is a
347                                //  valid WCS present.
348  string  spectralUnits;        // The units of the spectral dimension
349  string  spectralDescription;  // The description of the spectral dimension
350                                //   (Frequency, Velocity, ...)
351  string  fluxUnits;            // The units of pixel flux (from header)
352  string  intFluxUnits;         // The units of pixel flux (from header)
353  float   beamSize;             // The calculated beam size in pixels.
354  float   bmajKeyword;          // The FITS header keyword BMAJ.
355  float   bminKeyword;          // The FITS header keyword BMIN.
356  int     blankKeyword;         // The FITS header keyword BLANK.
357  float   bzeroKeyword;         // The FITS header keyword BZERO.
358  float   bscaleKeyword;        // The FITS header keyword BSCALE.
359  double  scale;                // scale param for converting spectral coords
360  double  offset;               // offset param for converting spectral coords
361  double  power;                // power param for converting spectral coords
362};
363
364string makelower( string s );
365
366#endif
Note: See TracBrowser for help on using the repository browser.