source: tags/release-1.1.1/src/param.hh @ 1213

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

Mostly changes to fix some memory allocation/deallocation issues raised by valgrind. Minor changes to the Guide.

File size: 18.9 KB
Line 
1// -----------------------------------------------------------------------
2// param.hh: Definition of the parameter set.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#ifndef PARAM_H
29#define PARAM_H
30
31#include <iostream>
32#include <string>
33#include <vector>
34#include <math.h>
35#include <wcs.h>
36#include <wcshdr.h>
37#include <Utils/Section.hh>
38#include <ATrous/filter.hh>
39
40class FitsHeader; // foreshadow this so that Param knows it exists
41
42/**
43 * Class to store general parameters.
44 *
45 * This is a general repository for parameters that are used by all
46 * functions. This is how the user interacts with the program, as
47 * parameters are read in from disk files through functions in this
48 * class.
49 */
50
51class Param
52{
53public:
54  /** Default constructor. */
55  Param();
56
57  /** Copy constructor for Param. */
58  Param(const Param& p);
59
60  /** Assignment operator for Param.*/
61  Param& operator= (const Param& p);
62
63  /** Destructor function.  */
64  virtual ~Param();
65
66  /** Define the default values of each parameter.*/
67  void  defaultValues();
68
69  //-----------------
70  // Functions in param.cc
71  //
72  /** Parse the command line parameters correctly. */
73  int    getopts(int argc, char ** argv);
74
75  /** Read in parameters from a disk file. */
76  int    readParams(std::string paramfile);
77
78  /** Copy certain necessary FITS header parameters from a FitsHeader
79      object */
80  void   copyHeaderInfo(FitsHeader &head);
81
82  /** Determine filename in which to save the smoothed array. */
83  std::string outputSmoothFile();
84
85  /** Determine filename in which to save the reconstructed array. */
86  std::string outputReconFile();
87
88  /** Determine filename in which to save the residual array from the
89      atrous reconstruction. */
90  std::string outputResidFile();
91
92  /** Print the parameter set in a readable fashion. */
93  friend std::ostream& operator<< ( std::ostream& theStream, Param& par);
94  friend class Image;
95
96  //------------------
97  // Functions in FitsIO/subsection.cc
98  //
99  /** Make sure the subsection strings are OK. */
100  int    verifySubsection();
101
102  /** Set the correct offset values for each axis */
103  void   setOffsets(struct wcsprm *wcs);
104
105  /** Set the correct offset values for each axis */
106  void   setOffsets(struct wcsprm &wcs);
107
108  //------------------
109  // These are in param.cc
110  /** Is a pixel value a BLANK? */
111  bool   isBlank(float &value);
112
113  /** Is a given channel flagged as being in the Milky Way?*/           
114  bool   isInMW(int z);
115
116  /** Is a given pixel position OK for use with stats calculations? */
117  bool   isStatOK(int x, int y, int z);
118
119  /** Make a mask array -- an array saying whether each pixel is BLANK
120      or not*/
121  bool  *makeBlankMask(float *array, int size);
122
123
124  //--------------------
125  // Basic inline accessor functions
126  //
127  std::string getImageFile(){return imageFile;};
128  void   setImageFile(std::string fname){imageFile = fname;};
129  std::string getFullImageFile(){
130    if(flagSubsection) return imageFile+pixelSec.getSection();
131    else return imageFile;
132  };
133  bool   getFlagSubsection(){return flagSubsection;};
134  void   setFlagSubsection(bool flag){flagSubsection=flag;};
135  std::string getSubsection(){return pixelSec.getSection();};
136  void   setSubsection(std::string range){pixelSec.setSection(range);};
137  bool   getFlagReconExists(){return flagReconExists;};
138  void   setFlagReconExists(bool flag){flagReconExists=flag;};
139  std::string getReconFile(){return reconFile;};
140  void   setReconFile(std::string file){reconFile = file;};
141  bool   getFlagSmoothExists(){return flagSmoothExists;};
142  void   setFlagSmoothExists(bool flag){flagSmoothExists=flag;};
143  std::string getSmoothFile(){return smoothFile;};
144  void   setSmoothFile(std::string file){smoothFile = file;};
145  //
146  bool   getFlagLog(){return flagLog;};
147  void   setFlagLog(bool flag){flagLog=flag;};
148  std::string getLogFile(){return logFile;};
149  void   setLogFile(std::string fname){logFile = fname;};
150  std::string getOutFile(){return outFile;};
151  void   setOutFile(std::string fname){outFile = fname;};
152  std::string getSpectraFile(){return spectraFile;};
153  void   setSpectraFile(std::string fname){spectraFile = fname;};
154  bool   getFlagOutputSmooth(){return flagOutputSmooth;};
155  void   setFlagOutputSmooth(bool flag){flagOutputSmooth=flag;};
156  bool   getFlagOutputRecon(){return flagOutputRecon;};
157  void   setFlagOutputRecon(bool flag){flagOutputRecon=flag;};
158  bool   getFlagOutputResid(){return flagOutputResid;};
159  void   setFlagOutputResid(bool flag){flagOutputResid=flag;};
160  bool   getFlagVOT(){return flagVOT;};
161  void   setFlagVOT(bool flag){flagVOT=flag;};
162  std::string getVOTFile(){return votFile;};
163  void   setVOTFile(std::string fname){votFile = fname;};
164  bool   getFlagKarma(){return flagKarma;};
165  void   setFlagKarma(bool flag){flagKarma=flag;};
166  std::string getKarmaFile(){return karmaFile;};
167  void   setKarmaFile(std::string fname){karmaFile = fname;};
168  bool   getFlagMaps(){return flagMaps;};
169  void   setFlagMaps(bool flag){flagMaps=flag;};
170  std::string getDetectionMap(){return detectionMap;};
171  void   setDetectionMap(std::string fname){detectionMap = fname;};
172  std::string getMomentMap(){return momentMap;};
173  void   setMomentMap(std::string fname){momentMap = fname;};
174  bool   getFlagXOutput(){return flagXOutput;};
175  void   setFlagXOutput(bool b){flagXOutput=b;};
176  //
177  bool   getFlagNegative(){return flagNegative;};
178  void   setFlagNegative(bool flag){flagNegative=flag;};
179  bool   getFlagBlankPix(){return flagBlankPix;};
180  void   setFlagBlankPix(bool flag){flagBlankPix=flag;};
181  float  getBlankPixVal(){return blankPixValue;};
182  void   setBlankPixVal(float v){blankPixValue=v;};
183  int    getBlankKeyword(){return blankKeyword;};
184  void   setBlankKeyword(int v){blankKeyword=v;};
185  float  getBscaleKeyword(){return bscaleKeyword;};
186  void   setBscaleKeyword(float v){bscaleKeyword=v;};
187  float  getBzeroKeyword(){return bzeroKeyword;};
188  void   setBzeroKeyword(float v){bzeroKeyword=v;};
189  bool   getFlagMW(){return flagMW;};
190  void   setFlagMW(bool flag){flagMW=flag;};
191  int    getMaxMW(){return maxMW;};
192  void   setMaxMW(int m){maxMW=m;};
193  int    getMinMW(){return minMW;};
194  void   setMinMW(int m){minMW=m;};
195  void   setBeamSize(float s){numPixBeam = s;};
196  float  getBeamSize(){return numPixBeam;};
197  bool   getFlagUsingBeam(){return flagUsingBeam;};
198  void   setFlagUsingBeam(bool b){flagUsingBeam=b;};
199  //
200  bool   getFlagTrim(){return flagTrim;};
201  void   setFlagTrim(bool b){flagTrim=b;};
202  bool   getFlagCubeTrimmed(){return hasBeenTrimmed;};
203  void   setFlagCubeTrimmed(bool flag){hasBeenTrimmed = flag;};
204  long   getBorderLeft(){return borderLeft;};
205  void   setBorderLeft(long b){borderLeft = b;};
206  long   getBorderRight(){return borderRight;};
207  void   setBorderRight(long b){borderRight = b;};
208  long   getBorderBottom(){return borderBottom;};
209  void   setBorderBottom(long b){borderBottom = b;};
210  long   getBorderTop(){return borderTop;};
211  void   setBorderTop(long b){borderTop = b;};
212  //
213  long   getXOffset(){return xSubOffset;};
214  void   setXOffset(long o){xSubOffset = o;};
215  long   getYOffset(){return ySubOffset;};
216  void   setYOffset(long o){ySubOffset = o;};
217  long   getZOffset(){return zSubOffset;};
218  void   setZOffset(long o){zSubOffset = o;};
219  //
220  int    getMinPix(){return minPix;};
221  void   setMinPix(int m){minPix=m;};
222  //     
223  bool   getFlagGrowth(){return flagGrowth;};
224  void   setFlagGrowth(bool flag){flagGrowth=flag;};
225  float  getGrowthCut(){return growthCut;};
226  void   setGrowthCut(float c){growthCut=c;};
227  //     
228  bool   getFlagFDR(){return flagFDR;};
229  void   setFlagFDR(bool flag){flagFDR=flag;};
230  float  getAlpha(){return alphaFDR;};
231  void   setAlpha(float a){alphaFDR=a;};
232  //
233  bool   getFlagBaseline(){return flagBaseline;};
234  void   setFlagBaseline(bool flag){flagBaseline = flag;};
235  //
236  bool   getFlagStatSec(){return flagStatSec;};
237  void   setFlagStatSec(bool flag){flagStatSec=flag;};
238  std::string getStatSec(){return statSec.getSection();};
239  void   setStatSec(std::string range){statSec.setSection(range);};
240  float  getCut(){return snrCut;};
241  void   setCut(float c){snrCut=c;};
242  float  getThreshold(){return threshold;};
243  void   setThreshold(float f){threshold=f;};
244  bool   getFlagUserThreshold(){return flagUserThreshold;};
245  void   setFlagUserThreshold(bool b){flagUserThreshold=b;};
246  //     
247  bool   getFlagSmooth(){return flagSmooth;};
248  void   setFlagSmooth(bool b){flagSmooth=b;};
249  std::string getSmoothType(){return smoothType;};
250  void   setSmoothType(std::string s){smoothType=s;};
251  int    getHanningWidth(){return hanningWidth;};
252  void   setHanningWidth(int f){hanningWidth=f;};
253  void   setKernMaj(float f){kernMaj=f;};
254  float  getKernMaj(){return kernMaj;};
255  void   setKernMin(float f){kernMin=f;};
256  float  getKernMin(){return kernMin;};
257  void   setKernPA(float f){kernPA=f;};
258  float  getKernPA(){return kernPA;};
259  //     
260  bool   getFlagATrous(){return flagATrous;};
261  void   setFlagATrous(bool flag){flagATrous=flag;};
262  int    getReconDim(){return reconDim;};
263  void   setReconDim(int i){reconDim=i;};
264  int    getMinScale(){return scaleMin;};
265  void   setMinScale(int s){scaleMin=s;};
266  float  getAtrousCut(){return snrRecon;};
267  void   setAtrousCut(float c){snrRecon=c;};
268  int    getFilterCode(){return filterCode;};
269  void   setFilterCode(int c){filterCode=c;};
270  std::string getFilterName(){return reconFilter.getName();};
271  Filter& filter(){ Filter &rfilter = reconFilter; return rfilter; };
272  //     
273  bool   getFlagAdjacent(){return flagAdjacent;};
274  void   setFlagAdjacent(bool flag){flagAdjacent=flag;};
275  float  getThreshS(){return threshSpatial;};
276  void   setThreshS(float t){threshSpatial=t;};
277  float  getThreshV(){return threshVelocity;};
278  void   setThreshV(float t){threshVelocity=t;};
279  int    getMinChannels(){return minChannels;};
280  void   setMinChannels(int n){minChannels=n;};
281  //
282  std::string getSpectralMethod(){return spectralMethod;};
283  void   setSpectralMethod(std::string s){spectralMethod=s;};
284  std::string getSpectralUnits(){return spectralUnits;};
285  void   setSpectralUnits(std::string s){spectralUnits=s;};
286  std::string getPixelCentre(){return pixelCentre;};
287  void   setPixelCentre(std::string s){pixelCentre=s;};
288  bool   drawBorders(){return borders;};
289  void   setDrawBorders(bool f){borders=f;};
290  bool   drawBlankEdge(){return blankEdge;};
291  void   setDrawBlankEdge(bool f){blankEdge=f;};
292
293  /** Are we in verbose mode? */
294  bool   isVerbose(){return verbose;};
295  void   setVerbosity(bool f){verbose=f;};
296 
297private:
298  // Input files
299  std::string imageFile;  ///< The image to be analysed.
300  bool   flagSubsection;  ///< Whether we just want a subsection of
301                          ///   the image
302  Section pixelSec;       ///< The Section object storing the pixel
303                          ///   subsection information.
304  bool   flagReconExists; ///< The reconstructed array is in a FITS
305                          ///   file on disk.
306  std::string reconFile;  ///< The FITS file containing the
307                          ///   reconstructed array.
308  bool   flagSmoothExists;///< The smoothed array is in a FITS file.
309  std::string smoothFile; ///< The FITS file containing the smoothed
310                          ///   array.
311
312  // Output files
313  bool   flagLog;         ///< Should we do the intermediate logging?
314  std::string logFile;    ///< Where the intermediate logging goes.
315  std::string outFile;    ///< Where the final results get put.
316  std::string spectraFile;///< Where the spectra are displayed
317  bool   flagOutputSmooth;///< Should the smoothed cube be written?
318  bool   flagOutputRecon; ///< Should the reconstructed cube be
319                          ///   written?
320  bool   flagOutputResid; ///< Should the reconstructed cube be
321                          ///   written?
322  bool   flagVOT;         ///< Should we save results in VOTable
323                          ///   format?
324  std::string votFile;    ///< Where the VOTable goes.
325  bool   flagKarma;       ///< Should we save results in Karma
326                          ///   annotation format?
327  std::string karmaFile;  ///< Where the Karma annotation file goes.
328  bool   flagMaps;        ///< Should we produce detection and moment
329                          ///   maps in postscript form?
330  std::string detectionMap;///< The name of the detection map
331                           ///   (postscript file).
332  std::string momentMap;  ///< The name of the 0th moment map (ps file).
333  bool   flagXOutput;     ///< Should there be an xwindows output of
334                          ///   the detection map?
335
336  // Cube related parameters
337  bool   flagNegative;    ///< Are we going to search for negative
338                          ///   features?
339  bool   flagBlankPix;    ///< A flag that indicates whether there are
340                          ///   pixels defined as BLANK and whether we
341                          ///   need to remove & ignore them in
342                          ///   processing.
343  float  blankPixValue;   ///< Pixel value that is considered BLANK.
344  int    blankKeyword;    ///< The FITS header keyword BLANK.
345  float  bscaleKeyword;   ///< The FITS header keyword BSCALE.
346  float  bzeroKeyword;    ///< The FITS header keyword BZERO.
347  //Milky-Way parameters
348  bool   flagMW;          ///< A flag that indicates whether to ignore
349                          ///   the Milky Way channels.
350  int    maxMW;           ///< Last  Milky Way channel
351  int    minMW;           ///< First Milky Way channel
352  // Trim-related
353  bool   flagTrim;        ///< Does the user want the cube trimmed?
354  bool   hasBeenTrimmed;  ///< Has the cube been trimmed of excess
355                          ///   BLANKs around the edge?
356  long   borderLeft;      ///< The number of BLANK pixels trimmed from
357                          ///   the left of the cube;
358  long   borderRight;     ///< The number trimmed from the Right of
359                          ///   the cube;
360  long   borderBottom;    ///< The number trimmed from the Bottom of
361                          ///   the cube;
362  long   borderTop;       ///< The number trimmed from the Top of the
363                          ///   cube;
364  // Subsection offsets
365  long  *offsets;         ///< The array of offsets for each FITS axis.
366  long   sizeOffsets;     ///< The size of the offsets array.
367  long   xSubOffset;      ///< The subsection's x-axis offset
368  long   ySubOffset;      ///< The subsection's y-axis offset
369  long   zSubOffset;      ///< The subsection's z-axis offset
370  // Baseline related
371  bool   flagBaseline;    ///< Whether to do baseline subtraction
372                          ///   before reconstruction and/or searching.
373  // Detection-related
374  int    minPix;          ///< Minimum number of pixels for a detected
375                          ///   object to be counted
376  float  numPixBeam;      ///< Size (area) of the beam in pixels.
377  bool   flagUsingBeam;   ///< If true, we are using the numPixBeam
378                          ///   parameter, otherwise we use the value
379                          ///   in the FITS header.
380  // Object growth
381  bool   flagGrowth;      ///< Are we growing objects once they are
382                          ///   found?
383  float  growthCut;       ///< The SNR that we are growing objects
384                          ///   down to.
385  // FDR analysis
386  bool   flagFDR;         ///< Should the FDR method be used?
387  float  alphaFDR;        ///< Alpha value for FDR detection algorithm
388  // Basic detection
389  bool   flagStatSec;     ///< Whether we just want to use a
390                          ///   subsection of the image to calculate
391                          ///   the statistics.
392  Section statSec;       ///< The Section object storing the statistics
393                          ///   subsection information.
394  float  snrCut;          ///< How many sigma above mean is a
395                          ///   detection when sigma-clipping
396  float  threshold;       ///< What the threshold is (when
397                          ///   sigma-clipping).
398  bool   flagUserThreshold;///< Whether the user has defined a
399                           ///   threshold of their own.
400  // Smoothing of the cube
401  bool   flagSmooth;      ///< Should the cube be smoothed before
402                          ///   searching?
403  std::string smoothType; ///< The type of smoothing to be done.
404  int    hanningWidth;    ///< Width for hanning smoothing.
405  float  kernMaj;         ///< Semi-Major axis of gaussian smoothing kernel
406  float  kernMin;         ///< Semi-Minor axis of gaussian smoothing kernel
407  float  kernPA;          ///< Position angle of gaussian smoothing
408                          ///   kernel, in degrees east of north
409                          ///   (i.e. anticlockwise).
410  // A trous reconstruction parameters
411  bool   flagATrous;      ///< Are we using the a trous reconstruction?
412  int    reconDim;        ///< How many dimensions to use for the
413                          ///   reconstruction?
414  int    scaleMin;        ///< Min scale used in a trous reconstruction
415  float  snrRecon;        ///< SNR cutoff used in a trous
416                          ///   reconstruction (only wavelet coefficients
417                          ///   that survive this threshold are kept)
418  Filter reconFilter;     ///< The filter used for reconstructions.
419  int    filterCode;      ///< The code number for the filter to be
420                          ///   used (saves having to parse names)
421  std::string filterName; ///< The code number converted into a name,
422                          ///   for outputting purposes.
423
424  // Volume-merging parameters
425  bool   flagAdjacent;    ///< Whether to use the adjacent criterion
426                          ///   for judging if objects are to be merged.
427  float  threshSpatial;   ///< Maximum spatial separation between
428                          ///   objects
429  float  threshVelocity;  ///< Maximum channels separation between
430                          ///   objects
431  int    minChannels;     ///< Minimum no. of channels to make an object
432  // Input-Output related
433  std::string spectralMethod; ///< A string indicating choice of
434                              ///   spectral plotting method: choices are
435                              ///   "peak" (default) or "sum"
436  std::string spectralUnits;   ///< A string indicating what units the
437                               ///   spectral axis should be quoted in.
438  std::string pixelCentre;///< A string indicating which type of
439                          ///   centre to give the results in: "average",
440                          ///   "centroid", or "peak"(flux).
441  bool   borders;         ///< Whether to draw a border around the
442                          ///   individual pixels of a detection in the
443                          ///   spectral display
444  bool   blankEdge;       ///< Whether to draw a border around the
445                          ///   BLANK pixel region in the moment maps and
446                          ///   cutout images
447  bool   verbose;         ///< Whether to use maximum verbosity -- use
448                          ///   progress indicators in the reconstruction
449                          ///   & merging steps.
450
451};
452
453//===========================================================================
454
455
456std::string makelower( std::string s );
457
458#endif
Note: See TracBrowser for help on using the repository browser.