source: tags/release-1.0.7/src/param.hh @ 1441

Last change on this file since 1441 was 208, checked in by Matthew Whiting, 18 years ago
  • Enabled saving and reading in of a smoothed array, in manner directly analogous to that for the recon array.
    • New file : src/Cubes/readSmooth.cc
    • The other new functions go in existing files eg. saveImage.cc
    • Renamed some functions (like writeHeader...) to be more obvious what they do.
    • The reading in is taken care of by new function Cube::readSavedArrays() -- handles both smoothed and recon'd arrays.
    • Associated parameters in Param class
    • Clarified names of FITS header strings in duchamp.hh.
  • Updated the documentation to describe the ability to smooth a cube.
  • Added description of feedback mechanisms in the Install appendix.
  • Also, Hanning class improved to guard against memory leaks.


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