source: trunk/src/param.hh @ 204

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

A large commit, based on improving memory usage, allocation, etc:

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