source: trunk/src/param.hh @ 201

Last change on this file since 201 was 201, checked in by Matthew Whiting, 18 years ago
  • New functionality added: ability to smooth a cube (in each individual spectrum) using a hanning filter before searching.
  • This comes with associated input parameters: flagSmooth and hanningWidth.
  • Hanning smoothing implemented via a new class that does the smoothing
  • Other minor changes:
    • changed the way getIAUName is called.
    • new colour names in mycpgplot
    • a << operator for the StatsContainer? class
    • more robust ProgressBar? functions
    • updated the Makefile.in
File size: 17.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  bool   getFlagXOutput(){return flagXOutput;};
80  void   setFlagXOutput(bool b){flagXOutput=b;};
81  //
82  bool   getFlagNegative(){return flagNegative;};
83  void   setFlagNegative(bool flag){flagNegative=flag;};
84  bool   getFlagBlankPix(){return flagBlankPix;};
85  void   setFlagBlankPix(bool flag){flagBlankPix=flag;};
86  float  getBlankPixVal(){return blankPixValue;};
87  void   setBlankPixVal(float v){blankPixValue=v;};
88  int    getBlankKeyword(){return blankKeyword;};
89  void   setBlankKeyword(int v){blankKeyword=v;};
90  float  getBscaleKeyword(){return bscaleKeyword;};
91  void   setBscaleKeyword(float v){bscaleKeyword=v;};
92  float  getBzeroKeyword(){return bzeroKeyword;};
93  void   setBzeroKeyword(float v){bzeroKeyword=v;};
94  bool   getFlagUsingBlank(){return flagUsingBlank;};
95  void   setFlagUsingBlank(bool b){flagUsingBlank=b;};
96  bool   getFlagMW(){return flagMW;};
97  bool   setFlagMW(bool flag){flagMW=flag;};
98  int    getMaxMW(){return maxMW;};
99  void   setMaxMW(int m){maxMW=m;};
100  int    getMinMW(){return minMW;};
101  void   setMinMW(int m){minMW=m;};
102  void   setBeamSize(float s){numPixBeam = s;};
103  float  getBeamSize(){return numPixBeam;};
104  bool   getFlagUsingBeam(){return flagUsingBeam;};
105  void   setFlagUsingBeam(bool b){flagUsingBeam=b;};
106  //
107  bool   getFlagCubeTrimmed(){return flagTrimmed;};
108  void   setFlagCubeTrimmed(bool flag){flagTrimmed = flag;};
109  long   getBorderLeft(){return borderLeft;};
110  void   setBorderLeft(long b){borderLeft = b;};
111  long   getBorderRight(){return borderRight;};
112  void   setBorderRight(long b){borderRight = b;};
113  long   getBorderBottom(){return borderBottom;};
114  void   setBorderBottom(long b){borderBottom = b;};
115  long   getBorderTop(){return borderTop;};
116  void   setBorderTop(long b){borderTop = b;};
117  //
118  long   getXOffset(){return xSubOffset;};
119  void   setXOffset(long o){xSubOffset = o;};
120  long   getYOffset(){return ySubOffset;};
121  void   setYOffset(long o){ySubOffset = o;};
122  long   getZOffset(){return zSubOffset;};
123  void   setZOffset(long o){zSubOffset = o;};
124  //
125  int    getMinPix(){return minPix;};
126  void   setMinPix(int m){minPix=m;};
127  //     
128  bool   getFlagGrowth(){return flagGrowth;};
129  void   setFlagGrowth(bool flag){flagGrowth=flag;};
130  float  getGrowthCut(){return growthCut;};
131  void   setGrowthCut(float c){growthCut=c;};
132  //     
133  bool   getFlagFDR(){return flagFDR;};
134  void   setFlagFDR(bool flag){flagFDR=flag;};
135  float  getAlpha(){return alphaFDR;};
136  void   setAlpha(float a){alphaFDR=a;};
137  //
138  bool   getFlagBaseline(){return flagBaseline;};
139  void   setFlagBaseline(bool flag){flagBaseline = flag;};
140  //
141  float  getCut(){return snrCut;};
142  void   setCut(float c){snrCut=c;};
143  float  getThreshold(){return threshold;};
144  void   setThreshold(float f){threshold=f;};
145  bool   getFlagUserThreshold(){return flagUserThreshold;};
146  void   setFlagUserThreshold(bool b){flagUserThreshold=b;};
147  //     
148  bool   getFlagSmooth(){return flagSmooth;};
149  void   setFlagSmooth(bool b){flagSmooth=b;};
150  int    getHanningWidth(){return hanningWidth;};
151  void   setHanningWidth(int f){hanningWidth=f;};
152  //     
153  bool   getFlagATrous(){return flagATrous;};
154  void   setFlagATrous(bool flag){flagATrous=flag;};
155  int    getReconDim(){return reconDim;};
156  void   setReconDim(int i){reconDim=i;};
157  int    getMinScale(){return scaleMin;};
158  void   setMinScale(int s){scaleMin=s;};
159  float  getAtrousCut(){return snrRecon;};
160  void   setAtrousCut(float c){snrRecon=c;};
161  int    getFilterCode(){return filterCode;};
162  void   setFilterCode(int c){filterCode=c;};
163  string getFilterName(){return filterName;};
164  void   setFilterName(string s){filterName=s;};
165  //     
166  bool   getFlagAdjacent(){return flagAdjacent;};
167  void   setFlagAdjacent(bool flag){flagAdjacent=flag;};
168  float  getThreshS(){return threshSpatial;};
169  void   setThreshS(float t){threshSpatial=t;};
170  float  getThreshV(){return threshVelocity;};
171  void   setThreshV(float t){threshVelocity=t;};
172  int    getMinChannels(){return minChannels;};
173  void   setMinChannels(int n){minChannels=n;};
174  //
175  string getSpectralMethod(){return spectralMethod;};
176  void   setSpectralMethod(string s){spectralMethod=s;};
177  string getSpectralUnits(){return spectralUnits;};
178  void   setSpectralUnits(string s){spectralUnits=s;};
179  bool   drawBorders(){return borders;};
180  void   setDrawBorders(bool f){borders=f;};
181  bool   drawBlankEdge(){return blankEdge;};
182  void   setDrawBlankEdge(bool f){blankEdge=f;};
183  bool   isVerbose(){return verbose;};
184  void   setVerbosity(bool f){verbose=f;};
185 
186private:
187  // Input files
188  string imageFile;       // The image to be analysed.
189  bool   flagSubsection;  // Whether we just want a subsection of the image
190  string subsection;      // The subsection requested, taking the form
191                          //  [x1:x2,y1:y2,z1:z2]
192                          //  If you want the full range of one index, use *
193  bool   flagReconExists; // The reconstructed array is in a FITS file on disk.
194  string reconFile;       // The FITS file containing the reconstructed array.
195
196  // Output files
197  bool   flagLog;         // Should we do the intermediate logging?
198  string logFile;         // Where the intermediate logging goes.
199  string outFile;         // Where the final results get put.
200  string spectraFile;     // Where the spectra are displayed
201  bool   flagOutputRecon; // Should the reconstructed cube be written?
202  bool   flagOutputResid; // Should the reconstructed cube be written?
203  bool   flagVOT;         // Should we save results in VOTable format?
204  string votFile;         // Where the VOTable goes.
205  bool   flagKarma;       // Should we save results in Karma annotation format?
206  string karmaFile;       // Where the Karma annotation file goes.
207  bool   flagMaps;        // Should we produce detection and moment maps
208                          //  in postscript form?
209  string detectionMap;    // The name of the detection map (ps file).
210  string momentMap;       // The name of the 0th moment map (ps file).
211  bool   flagXOutput;     // Should there be an xwindows output of the
212                          //  detection map?
213
214  // Cube related parameters
215  bool   flagNegative;    // Are we going to search for negative features?
216  bool   flagBlankPix;    // A flag that indicates whether there are pixels
217                          //   defined as BLANK and whether we need to remove
218                          //   & ignore them in processing.
219  float  blankPixValue;   // Pixel value that is considered BLANK.
220  int    blankKeyword;    // The FITS header keyword BLANK.
221  float  bscaleKeyword;   // The FITS header keyword BSCALE.
222  float  bzeroKeyword;    // The FITS header keyword BZERO.
223  bool   flagUsingBlank;  // If true, we are using the blankPixValue keyword,
224                          // otherwise we use the value in the FITS header.
225  bool   flagMW;          // A flag that indicates whether to ignore the
226                          //  Milky Way channels.
227  int    maxMW;           // Last  Galactic velocity plane for HIPASS cubes
228  int    minMW;           // First Galactic velocity plane for HIPASS cubes
229  float  numPixBeam;      // Size (area) of the beam in pixels.
230  bool   flagUsingBeam;   // If true, we are using the numPixBeam parameter,
231                          // otherwise we use the value in the FITS header.
232  // Trim-related         
233  bool   flagTrimmed;     // Has the cube been trimmed of excess BLANKs
234                          //  around the edge?
235  long   borderLeft;      // The number of BLANK pixels trimmed from the
236                          //   Left of the cube;
237  long   borderRight;     // The number trimmed from the Right of the cube;
238  long   borderBottom;    // The number trimmed from the Bottom of the cube;
239  long   borderTop;       // The number trimmed from the Top of the cube;
240  // Subsection offsets
241  long  *offsets;         // The array of offsets for each FITS axis.
242  long   xSubOffset;      // The offset in the x-direction from the subsection
243  long   ySubOffset;      // The offset in the y-direction from the subsection
244  long   zSubOffset;      // The offset in the z-direction from the subsection
245  // Baseline related;
246  bool   flagBaseline;    // Whether to do baseline subtraction before
247                          //  reconstruction and/or searching.
248  // Detection-related   
249  int    minPix;          // Minimum number of pixels for a detected object
250                          //   to be counted
251  // Object growth       
252  bool   flagGrowth;      // Are we growing objects once they are found?
253  float  growthCut;       // The SNR that we are growing objects down to.
254  // FDR analysis         
255  bool   flagFDR;         // Should the FDR method be used?
256  float  alphaFDR;        // Alpha value for FDR detection algorithm
257  // Basic detection     
258  float  snrCut;          // How many sigma above mean is a detection
259                          //   when sigma-clipping
260  float  threshold;       // What the threshold is (when sigma-clipping).
261  bool   flagUserThreshold;// Whether the user has defined a threshold of
262                           //  their own.
263  // Smoothing of the cube
264  bool   flagSmooth;      // Should the cube be smoothed before searching?
265  int    hanningWidth;    // Width for hanning smoothing.
266  // A trous reconstruction parameters
267  bool   flagATrous;      // Are we using the a trous reconstruction?
268  int    reconDim;        // How many dimensions to use for the reconstruction?
269  int    scaleMin;        // Min scale used in a trous reconstruction
270  float  snrRecon;        // SNR cutoff used in a trous reconstruction
271                          //   (only wavelet coefficients that survive this
272                          //    threshold are kept)
273  int    filterCode;      // The code number for the filter to be used
274                          //  (saves having to parse names)
275  string filterName;      // The code number converted into a name,
276                          //  for outputting purposes.
277
278  // Volume-merging parameters
279  bool   flagAdjacent;    // Whether to use the adjacent criterion for
280                          //    judging if objects are to be merged.
281  float  threshSpatial;   // Maximum spatial separation between objects
282  float  threshVelocity;  // Maximum channels separation between objects
283  int    minChannels;     // Minimum no. of channels to make an object
284  // Input-Output related
285  string spectralMethod;  // A string indicating choice of spectral plotting
286                          //  method: choices are "peak" (default) or "sum"
287  string spectralUnits;   // A string indicating what units the spectral
288                          //  axis should be quoted in.
289  bool   borders;         // Whether to draw a border around the individual
290                          //  pixels of a detection in the spectral display
291  bool   blankEdge;       // Whether to draw a border around the BLANK pixel
292                          //  region in the moment maps and cutout images
293  bool   verbose;         // Whether to use maximum verbosity -- use progress
294                          //  indicators in the reconstruction & merging steps.
295
296};
297
298class FitsHeader
299{
300  /**
301   *  FitsHeader Class
302   *
303   *   Stores information from a FITS header, including WCS information
304   *    in the form of a wcsprm struct, as well as various keywords.
305   */
306
307public:
308  FitsHeader();
309  virtual ~FitsHeader(){};
310  FitsHeader(const FitsHeader& h);
311  FitsHeader& operator= (const FitsHeader& h);
312
313  wcsprm *getWCS();             // in param.cc
314  void    setWCS(wcsprm *w);    // in param.cc
315  bool    isWCS(){return wcsIsGood;};
316  int     getNWCS(){return nwcs;};
317  void    setNWCS(int i){nwcs=i;};
318  int     readHeaderInfo(string fname, Param &par);
319  int     defineWCS(string fname, Param &par);
320  int     readBUNIT(string fname);
321  int     readBLANKinfo(string fname, Param &par);
322  int     readBeamInfo(string fname, Param &par);
323  string  getSpectralUnits(){return spectralUnits;};
324  void    setSpectralUnits(string s){spectralUnits=s;};
325  string  getSpectralDescription(){return spectralDescription;};
326  void    setSpectralDescription(string s){spectralDescription=s;};
327  string  getFluxUnits(){return fluxUnits;};
328  void    setFluxUnits(string s){fluxUnits=s;};
329  string  getIntFluxUnits(){return intFluxUnits;};
330  void    setIntFluxUnits(string s){intFluxUnits=s;};
331  float   getBeamSize(){return beamSize;};
332  void    setBeamSize(float f){beamSize=f;};
333  float   getBmajKeyword(){return bmajKeyword;};
334  void    setBmajKeyword(float f){bmajKeyword=f;};
335  float   getBminKeyword(){return bminKeyword;};
336  void    setBminKeyword(float f){bminKeyword=f;};
337  int     getBlankKeyword(){return blankKeyword;};
338  void    setBlankKeyword(int f){blankKeyword=f;};
339  float   getBzeroKeyword(){return bzeroKeyword;};
340  void    setBzeroKeyword(float f){bzeroKeyword=f;};
341  float   getBscaleKeyword(){return bscaleKeyword;};
342  void    setBscaleKeyword(float f){bscaleKeyword=f;};
343  float   getAvPixScale(){
344    return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])*
345                        (wcs->pc[wcs->naxis+1]*wcs->cdelt[1])));
346  };
347
348  // front ends to WCS functions
349  int     wcsToPix(const double *world, double *pix);
350  int     pixToWCS(const double *pix, double *world);
351  int     wcsToPix(const double *world, double *pix, const int npts);
352  int     pixToWCS(const double *pix, double *world, const int npts);
353  double  pixToVel(double &x, double &y, double &z);
354  double *pixToVel(double &x, double &y, double *zarray, int size);
355  double  specToVel(const double &z);
356  double  velToSpec(const float &vel);
357  string  getIAUName(double ra, double dec);
358
359  void    fixUnits(Param &par);
360 
361private:
362  wcsprm *wcs;                  // The WCS parameters for the cube in a
363                                //  struct from the wcslib library.
364  int     nwcs;                 // The number of WCS parameters
365  bool    wcsIsGood;            // A flag indicating whether there is a
366                                //  valid WCS present.
367  string  spectralUnits;        // The units of the spectral dimension
368  string  spectralDescription;  // The description of the spectral dimension
369                                //   (Frequency, Velocity, ...)
370  string  fluxUnits;            // The units of pixel flux (from header)
371  string  intFluxUnits;         // The units of pixel flux (from header)
372  float   beamSize;             // The calculated beam size in pixels.
373  float   bmajKeyword;          // The FITS header keyword BMAJ.
374  float   bminKeyword;          // The FITS header keyword BMIN.
375  int     blankKeyword;         // The FITS header keyword BLANK.
376  float   bzeroKeyword;         // The FITS header keyword BZERO.
377  float   bscaleKeyword;        // The FITS header keyword BSCALE.
378  double  scale;                // scale param for converting spectral coords
379  double  offset;               // offset param for converting spectral coords
380  double  power;                // power param for converting spectral coords
381};
382
383string makelower( string s );
384
385#endif
Note: See TracBrowser for help on using the repository browser.