source: branches/pixel-map-branch/src/param.hh @ 236

Last change on this file since 236 was 232, checked in by Matthew Whiting, 17 years ago

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

  • Moving the reconstruction filter class Filter into its own header/implementation files filter.{hh,cc}. As a result, the atrous.cc file is removed, but atrous.hh remains with just the function prototypes.
  • Incorporating a Filter object into the Param set, so that the reconstruction routines can see it without the messy "extern" call. The define() function is now called in both the Param() and Param::readParams() functions, and no longer in the main body.
  • Col functions in columns.cc moved into the Column namespace, while the template function printEntry is moved into the columns.hh file -- it would not compile on delphinus with it in the columns.cc, even though all the implementations were present.
  • Improved the introductory section of the Guide, with a bit more detail about each of the execution steps. This way the reader can read this section and have a reasonably good idea about what is happening.
  • Other minor changes to the Guide.
File size: 20.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#include <wcshdr.h>
10#include <Utils/utils.hh>
11#include <ATrous/filter.hh>
12
13class FitsHeader; // foreshadow this so that Param knows it exists
14
15/**
16 * Class to store general parameters.
17 *
18 * This is a general repository for parameters that are used by all
19 * functions. This is how the user interacts with the program, as
20 * parameters are read in from disk files through functions in this
21 * class.
22 */
23
24class Param
25{
26public:
27  Param();
28  virtual ~Param(){if(sizeOffsets>0) delete [] offsets;};
29  Param(const Param& p);
30  Param& operator= (const Param& p);
31  //-----------------
32  // Functions in param.cc
33  //
34  /** Read in parameters from a disk file. */
35  int    readParams(std::string paramfile);
36
37  /** Copy certain necessary FITS header parameters from a FitsHeader object */
38  void   copyHeaderInfo(FitsHeader &head);
39
40  /** Determine filename in which to save the Hanning-smoothed array. */
41  std::string outputSmoothFile();
42
43  /** Determine filename in which to save the reconstructed array. */
44  std::string outputReconFile();
45
46  /** Determine filename in which to save the residual array from the atrous reconstruction. */
47  std::string outputResidFile();
48
49  /** Print the parameter set in a readable fashion. */
50  friend std::ostream& operator<< ( std::ostream& theStream, Param& par);
51  friend class Image;
52  //------------------
53  // Functions in FitsIO/subsection.cc
54  //
55  /** Make sure the subsection string is OK, and read the axis subsections. */
56  int    verifySubsection();
57
58  /** Set the correct offset values for each axis */
59  void   setOffsets(struct wcsprm *wcs);
60  //--------------------
61  // These are inline functions.
62  //
63  /** Is a pixel value a BLANK?
64   *  Tests whether the value passed as the argument is BLANK or not.
65   *   If flagBlankPix is false, return false.
66   *   Otherwise, compare to the relevant FITS keywords, using integer comparison.
67   */
68  bool   isBlank(float &value){
69    return this->flagBlankPix &&
70      (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
71  };
72
73  /** Is a given channel flagged as being in the Milky Way?*/           
74  bool   isInMW(int z){return ( flagMW && (z>=minMW) && (z<=maxMW) );};
75
76  //--------------------
77  // Basic inline accessor functions
78  //
79  std::string getImageFile(){return imageFile;};
80  void   setImageFile(std::string fname){imageFile = fname;};
81  std::string getFullImageFile(){
82    if(flagSubsection) return imageFile+subsection;
83    else return imageFile;
84  };
85  bool   getFlagSubsection(){return flagSubsection;};
86  void   setFlagSubsection(bool flag){flagSubsection=flag;};
87  std::string getSubsection(){return subsection;};
88  void   setSubsection(std::string range){subsection = range;};
89  bool   getFlagReconExists(){return flagReconExists;};
90  void   setFlagReconExists(bool flag){flagReconExists=flag;};
91  std::string getReconFile(){return reconFile;};
92  void   setReconFile(std::string file){reconFile = file;};
93  bool   getFlagSmoothExists(){return flagSmoothExists;};
94  void   setFlagSmoothExists(bool flag){flagSmoothExists=flag;};
95  std::string getSmoothFile(){return smoothFile;};
96  void   setSmoothFile(std::string file){smoothFile = file;};
97  //
98  bool   getFlagLog(){return flagLog;};
99  void   setFlagLog(bool flag){flagLog=flag;};
100  std::string getLogFile(){return logFile;};
101  void   setLogFile(std::string fname){logFile = fname;};
102  std::string getOutFile(){return outFile;};
103  void   setOutFile(std::string fname){outFile = fname;};
104  std::string getSpectraFile(){return spectraFile;};
105  void   setSpectraFile(std::string fname){spectraFile = fname;};
106  bool   getFlagOutputSmooth(){return flagOutputSmooth;};
107  void   setFlagOutputSmooth(bool flag){flagOutputSmooth=flag;};
108  bool   getFlagOutputRecon(){return flagOutputRecon;};
109  void   setFlagOutputRecon(bool flag){flagOutputRecon=flag;};
110  bool   getFlagOutputResid(){return flagOutputResid;};
111  void   setFlagOutputResid(bool flag){flagOutputResid=flag;};
112  bool   getFlagVOT(){return flagVOT;};
113  void   setFlagVOT(bool flag){flagVOT=flag;};
114  std::string getVOTFile(){return votFile;};
115  void   setVOTFile(std::string fname){votFile = fname;};
116  bool   getFlagKarma(){return flagKarma;};
117  void   setFlagKarma(bool flag){flagKarma=flag;};
118  std::string getKarmaFile(){return karmaFile;};
119  void   setKarmaFile(std::string fname){karmaFile = fname;};
120  bool   getFlagMaps(){return flagMaps;};
121  void   setFlagMaps(bool flag){flagMaps=flag;};
122  std::string getDetectionMap(){return detectionMap;};
123  void   setDetectionMap(std::string fname){detectionMap = fname;};
124  std::string getMomentMap(){return momentMap;};
125  void   setMomentMap(std::string fname){momentMap = fname;};
126  bool   getFlagXOutput(){return flagXOutput;};
127  void   setFlagXOutput(bool b){flagXOutput=b;};
128  //
129  bool   getFlagNegative(){return flagNegative;};
130  void   setFlagNegative(bool flag){flagNegative=flag;};
131  bool   getFlagBlankPix(){return flagBlankPix;};
132  void   setFlagBlankPix(bool flag){flagBlankPix=flag;};
133  float  getBlankPixVal(){return blankPixValue;};
134  void   setBlankPixVal(float v){blankPixValue=v;};
135  int    getBlankKeyword(){return blankKeyword;};
136  void   setBlankKeyword(int v){blankKeyword=v;};
137  float  getBscaleKeyword(){return bscaleKeyword;};
138  void   setBscaleKeyword(float v){bscaleKeyword=v;};
139  float  getBzeroKeyword(){return bzeroKeyword;};
140  void   setBzeroKeyword(float v){bzeroKeyword=v;};
141  bool   getFlagUsingBlank(){return flagUsingBlank;};
142  void   setFlagUsingBlank(bool b){flagUsingBlank=b;};
143  bool   getFlagMW(){return flagMW;};
144  bool   setFlagMW(bool flag){flagMW=flag;};
145  int    getMaxMW(){return maxMW;};
146  void   setMaxMW(int m){maxMW=m;};
147  int    getMinMW(){return minMW;};
148  void   setMinMW(int m){minMW=m;};
149  void   setBeamSize(float s){numPixBeam = s;};
150  float  getBeamSize(){return numPixBeam;};
151  bool   getFlagUsingBeam(){return flagUsingBeam;};
152  void   setFlagUsingBeam(bool b){flagUsingBeam=b;};
153  //
154  bool   getFlagCubeTrimmed(){return flagTrimmed;};
155  void   setFlagCubeTrimmed(bool flag){flagTrimmed = flag;};
156  long   getBorderLeft(){return borderLeft;};
157  void   setBorderLeft(long b){borderLeft = b;};
158  long   getBorderRight(){return borderRight;};
159  void   setBorderRight(long b){borderRight = b;};
160  long   getBorderBottom(){return borderBottom;};
161  void   setBorderBottom(long b){borderBottom = b;};
162  long   getBorderTop(){return borderTop;};
163  void   setBorderTop(long b){borderTop = b;};
164  //
165  long   getXOffset(){return xSubOffset;};
166  void   setXOffset(long o){xSubOffset = o;};
167  long   getYOffset(){return ySubOffset;};
168  void   setYOffset(long o){ySubOffset = o;};
169  long   getZOffset(){return zSubOffset;};
170  void   setZOffset(long o){zSubOffset = o;};
171  //
172  int    getMinPix(){return minPix;};
173  void   setMinPix(int m){minPix=m;};
174  //     
175  bool   getFlagGrowth(){return flagGrowth;};
176  void   setFlagGrowth(bool flag){flagGrowth=flag;};
177  float  getGrowthCut(){return growthCut;};
178  void   setGrowthCut(float c){growthCut=c;};
179  //     
180  bool   getFlagFDR(){return flagFDR;};
181  void   setFlagFDR(bool flag){flagFDR=flag;};
182  float  getAlpha(){return alphaFDR;};
183  void   setAlpha(float a){alphaFDR=a;};
184  //
185  bool   getFlagBaseline(){return flagBaseline;};
186  void   setFlagBaseline(bool flag){flagBaseline = flag;};
187  //
188  float  getCut(){return snrCut;};
189  void   setCut(float c){snrCut=c;};
190  float  getThreshold(){return threshold;};
191  void   setThreshold(float f){threshold=f;};
192  bool   getFlagUserThreshold(){return flagUserThreshold;};
193  void   setFlagUserThreshold(bool b){flagUserThreshold=b;};
194  //     
195  bool   getFlagSmooth(){return flagSmooth;};
196  void   setFlagSmooth(bool b){flagSmooth=b;};
197  int    getHanningWidth(){return hanningWidth;};
198  void   setHanningWidth(int f){hanningWidth=f;};
199  //     
200  bool   getFlagATrous(){return flagATrous;};
201  void   setFlagATrous(bool flag){flagATrous=flag;};
202  int    getReconDim(){return reconDim;};
203  void   setReconDim(int i){reconDim=i;};
204  int    getMinScale(){return scaleMin;};
205  void   setMinScale(int s){scaleMin=s;};
206  float  getAtrousCut(){return snrRecon;};
207  void   setAtrousCut(float c){snrRecon=c;};
208  int    getFilterCode(){return filterCode;};
209  void   setFilterCode(int c){filterCode=c;};
210  std::string getFilterName(){return reconFilter.getName();};
211  Filter& filter(){ Filter &rfilter = reconFilter; return rfilter; };
212  //     
213  bool   getFlagAdjacent(){return flagAdjacent;};
214  void   setFlagAdjacent(bool flag){flagAdjacent=flag;};
215  float  getThreshS(){return threshSpatial;};
216  void   setThreshS(float t){threshSpatial=t;};
217  float  getThreshV(){return threshVelocity;};
218  void   setThreshV(float t){threshVelocity=t;};
219  int    getMinChannels(){return minChannels;};
220  void   setMinChannels(int n){minChannels=n;};
221  //
222  std::string getSpectralMethod(){return spectralMethod;};
223  void   setSpectralMethod(std::string s){spectralMethod=s;};
224  std::string getSpectralUnits(){return spectralUnits;};
225  void   setSpectralUnits(std::string s){spectralUnits=s;};
226  bool   drawBorders(){return borders;};
227  void   setDrawBorders(bool f){borders=f;};
228  bool   drawBlankEdge(){return blankEdge;};
229  void   setDrawBlankEdge(bool f){blankEdge=f;};
230
231  /** Are we in verbose mode? */
232  bool   isVerbose(){return verbose;};
233  void   setVerbosity(bool f){verbose=f;};
234 
235private:
236  // Input files
237  std::string imageFile;       ///< The image to be analysed.
238  bool   flagSubsection;  ///< Whether we just want a subsection of the image
239  std::string subsection;      ///< The subsection requested, taking the form [x1:x2,y1:y2,z1:z2]. If you want the full range of one index, use *
240  bool   flagReconExists; ///< The reconstructed array is in a FITS file on disk.
241  std::string reconFile;       ///< The FITS file containing the reconstructed array.
242  bool   flagSmoothExists;///< The Hanning-smoothed array is in a FITS file.
243  std::string smoothFile;      ///< The FITS file containing the smoothed array.
244
245  // Output files
246  bool   flagLog;         ///< Should we do the intermediate logging?
247  std::string logFile;         ///< Where the intermediate logging goes.
248  std::string outFile;         ///< Where the final results get put.
249  std::string spectraFile;     ///< Where the spectra are displayed
250  bool   flagOutputSmooth;///< Should the Hanning-smoothed cube be written?
251  bool   flagOutputRecon; ///< Should the reconstructed cube be written?
252  bool   flagOutputResid; ///< Should the reconstructed cube be written?
253  bool   flagVOT;         ///< Should we save results in VOTable format?
254  std::string votFile;         ///< Where the VOTable goes.
255  bool   flagKarma;       ///< Should we save results in Karma annotation format?
256  std::string karmaFile;       ///< Where the Karma annotation file goes.
257  bool   flagMaps;        ///< Should we produce detection and moment maps in postscript form?
258  std::string detectionMap;    ///< The name of the detection map (ps file).
259  std::string momentMap;       ///< The name of the 0th moment map (ps file).
260  bool   flagXOutput;     ///< Should there be an xwindows output of the detection map?
261
262  // Cube related parameters
263  bool   flagNegative;    ///< Are we going to search for negative features?
264  bool   flagBlankPix;    ///< A flag that indicates whether there are pixels defined as BLANK and whether we need to remove & ignore them in processing.
265  float  blankPixValue;   ///< Pixel value that is considered BLANK.
266  int    blankKeyword;    ///< The FITS header keyword BLANK.
267  float  bscaleKeyword;   ///< The FITS header keyword BSCALE.
268  float  bzeroKeyword;    ///< The FITS header keyword BZERO.
269  bool   flagUsingBlank;  ///< If true, we are using the blankPixValue keyword,
270                          ///< otherwise we use the value in the FITS header.
271  bool   flagMW;          ///< A flag that indicates whether to ignore the Milky Way channels.
272  int    maxMW;           ///< Last  Galactic velocity plane for HIPASS cubes
273  int    minMW;           ///< First Galactic velocity plane for HIPASS cubes
274  float  numPixBeam;      ///< Size (area) of the beam in pixels.
275  bool   flagUsingBeam;   ///< If true, we are using the numPixBeam parameter,
276                          ///< otherwise we use the value in the FITS header.
277  // Trim-related
278  bool   flagTrimmed;     ///< Has the cube been trimmed of excess BLANKs around the edge?
279  long   borderLeft;      ///< The number of BLANK pixels trimmed from the left of the cube;
280  long   borderRight;     ///< The number trimmed from the Right of the cube;
281  long   borderBottom;    ///< The number trimmed from the Bottom of the cube;
282  long   borderTop;       ///< The number trimmed from the Top of the cube;
283  // Subsection offsets
284  long  *offsets;         ///< The array of offsets for each FITS axis.
285  long   sizeOffsets;     ///< The size of the offsets array.
286  long   xSubOffset;      ///< The offset in the x-direction from the subsection
287  long   ySubOffset;      ///< The offset in the y-direction from the subsection
288  long   zSubOffset;      ///< The offset in the z-direction from the subsection
289  // Baseline related
290  bool   flagBaseline;    ///< Whether to do baseline subtraction before reconstruction and/or searching.
291  // Detection-related
292  int    minPix;          ///< Minimum number of pixels for a detected object to be counted
293  // Object growth
294  bool   flagGrowth;      ///< Are we growing objects once they are found?
295  float  growthCut;       ///< The SNR that we are growing objects down to.
296  // FDR analysis
297  bool   flagFDR;         ///< Should the FDR method be used?
298  float  alphaFDR;        ///< Alpha value for FDR detection algorithm
299  // Basic detection
300  float  snrCut;          ///< How many sigma above mean is a detection when sigma-clipping
301  float  threshold;       ///< What the threshold is (when sigma-clipping).
302  bool   flagUserThreshold;///< Whether the user has defined a threshold of their own.
303  // Smoothing of the cube
304  bool   flagSmooth;      ///< Should the cube be smoothed before searching?
305  int    hanningWidth;    ///< Width for hanning smoothing.
306  // A trous reconstruction parameters
307  bool   flagATrous;      ///< Are we using the a trous reconstruction?
308  int    reconDim;        ///< How many dimensions to use for the reconstruction?
309  int    scaleMin;        ///< Min scale used in a trous reconstruction
310  float  snrRecon;        ///< SNR cutoff used in a trous reconstruction (only wavelet coefficients that survive this threshold are kept)
311  Filter reconFilter;     ///< The filter used for reconstructions.
312  int    filterCode;      ///< The code number for the filter to be used (saves having to parse names)
313  std::string filterName;      ///< The code number converted into a name, for outputting purposes.
314
315  // Volume-merging parameters
316  bool   flagAdjacent;    ///< Whether to use the adjacent criterion for judging if objects are to be merged.
317  float  threshSpatial;   ///< Maximum spatial separation between objects
318  float  threshVelocity;  ///< Maximum channels separation between objects
319  int    minChannels;     ///< Minimum no. of channels to make an object
320  // Input-Output related
321  std::string spectralMethod;  ///< A string indicating choice of spectral plotting method: choices are "peak" (default) or "sum"
322  std::string spectralUnits;   ///< A string indicating what units the spectral axis should be quoted in.
323  bool   borders;         ///< Whether to draw a border around the individual pixels of a detection in the spectral display
324  bool   blankEdge;       ///< Whether to draw a border around the BLANK pixel region in the moment maps and cutout images
325  bool   verbose;         ///< Whether to use maximum verbosity -- use progress indicators in the reconstruction & merging steps.
326
327};
328
329//===========================================================================
330
331/**
332 *  Class to store FITS header information.
333 *
334 *   Stores information from a FITS header, including WCS information
335 *    in the form of a wcsprm struct, as well as various keywords.
336 */
337class FitsHeader
338{
339
340public:
341  FitsHeader();
342  virtual ~FitsHeader(){wcsvfree(&nwcs,&wcs);};
343  FitsHeader(const FitsHeader& h);
344  FitsHeader& operator= (const FitsHeader& h);
345
346  //--------------------
347  // Functions in param.cc
348  //
349  /** Assign correct WCS parameters.  */
350  void    setWCS(struct wcsprm *w);
351
352  /** Return the WCS parameters in a WCSLIB wcsprm struct. */
353  struct wcsprm *getWCS();
354
355  // front ends to WCS functions
356  /** Convert pixel coords to world coords for a single point. */
357  int     wcsToPix(const double *world, double *pix);
358
359  /** Convert pixel coords to world coords for many points. */
360  int     wcsToPix(const double *world, double *pix, const int npts);
361
362  /** Convert world coords to pixel coords for a single point. */
363  int     pixToWCS(const double *pix, double *world);
364
365  /** Convert world coords to pixel coords for many points. */
366  int     pixToWCS(const double *pix, double *world, const int npts);
367
368  /** Convert a (x,y,z) position to a velocity. */
369  double  pixToVel(double &x, double &y, double &z);
370
371  /** Convert a set of  (x,y,z) positions to a set of velocities. */
372  double *pixToVel(double &x, double &y, double *zarray, int size);
373
374  /** Convert a spectral coordinate to a velocity coordinate.*/
375  double  specToVel(const double &z);
376
377  /** Convert a velocity coordinate to a spectral coordinate.*/
378  double  velToSpec(const float &vel);
379
380  /** Get an IAU-style name for an equatorial or galactic coordinates. */
381  std::string  getIAUName(double ra, double dec);
382
383  /** Correct the units for the spectral axis */
384  void    fixUnits(Param &par);
385 
386  //--------------------
387  // Functions in FitsIO/headerIO.cc
388  //
389  /** Read all header info. */
390  int     readHeaderInfo(std::string fname, Param &par);
391
392  /** Read BUNIT keyword */
393  int     readBUNIT(std::string fname);
394
395  /** Read BLANK & related keywords */
396  int     readBLANKinfo(std::string fname, Param &par);
397
398  /** Read beam-related keywords */
399  int     readBeamInfo(std::string fname, Param &par);
400 
401  //--------------------
402  // Function in FitsIO/wcsIO.cc
403  //
404  /** Read the WCS information from a file. */
405  int     defineWCS(std::string fname, Param &par);
406
407  //--------------------
408  // Basic inline accessor functions
409  //
410  bool    isWCS(){return wcsIsGood;};
411  int     getNWCS(){return nwcs;};
412  void    setNWCS(int i){nwcs=i;};
413  std::string  getSpectralUnits(){return spectralUnits;};
414  void    setSpectralUnits(std::string s){spectralUnits=s;};
415  std::string  getSpectralDescription(){return spectralDescription;};
416  void    setSpectralDescription(std::string s){spectralDescription=s;};
417  std::string  getFluxUnits(){return fluxUnits;};
418  void    setFluxUnits(std::string s){fluxUnits=s;};
419  std::string  getIntFluxUnits(){return intFluxUnits;};
420  void    setIntFluxUnits(std::string s){intFluxUnits=s;};
421  float   getBeamSize(){return beamSize;};
422  void    setBeamSize(float f){beamSize=f;};
423  float   getBmajKeyword(){return bmajKeyword;};
424  void    setBmajKeyword(float f){bmajKeyword=f;};
425  float   getBminKeyword(){return bminKeyword;};
426  void    setBminKeyword(float f){bminKeyword=f;};
427  int     getBlankKeyword(){return blankKeyword;};
428  void    setBlankKeyword(int f){blankKeyword=f;};
429  float   getBzeroKeyword(){return bzeroKeyword;};
430  void    setBzeroKeyword(float f){bzeroKeyword=f;};
431  float   getBscaleKeyword(){return bscaleKeyword;};
432  void    setBscaleKeyword(float f){bscaleKeyword=f;};
433  float   getAvPixScale(){
434    return sqrt( fabs ( (wcs->pc[0]*wcs->cdelt[0])*
435                        (wcs->pc[wcs->naxis+1]*wcs->cdelt[1])));
436  };
437
438
439private:
440  struct wcsprm *wcs;           ///< The WCS parameters for the cube in a struct from the wcslib library.
441  int     nwcs;                 ///< The number of WCS parameters
442  bool    wcsIsGood;            ///< A flag indicating whether there is a valid WCS present.
443  std::string  spectralUnits;        ///< The units of the spectral dimension
444  std::string  spectralDescription;  ///< The description of the spectral dimension (Frequency, Velocity, ...)
445  std::string  fluxUnits;            ///< The units of pixel flux (from header)
446  std::string  intFluxUnits;         ///< The units of pixel flux (from header)
447  float   beamSize;             ///< The calculated beam size in pixels.
448  float   bmajKeyword;          ///< The FITS header keyword BMAJ.
449  float   bminKeyword;          ///< The FITS header keyword BMIN.
450  int     blankKeyword;         ///< The FITS header keyword BLANK.
451  float   bzeroKeyword;         ///< The FITS header keyword BZERO.
452  float   bscaleKeyword;        ///< The FITS header keyword BSCALE.
453  double  scale;                ///< scale param for converting spectral coords
454  double  offset;               ///< offset param for converting spectral coords
455  double  power;                ///< power param for converting spectral coords
456};
457
458std::string makelower( std::string s );
459
460#endif
Note: See TracBrowser for help on using the repository browser.