source: trunk/src/param.hh @ 164

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

A series of changes, prompted by the need to update the subsections parsing
to make it compliant with the new multi-dimensional FITS formalism.
Specifically:

  • FitsIO/subsection.cc
    • New file. Main task the Param::verifySubsection() function. Makes sure the subsection has correct format and number of axes.

Also removes any steps in the subsection string.

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