source: trunk/src/param.hh @ 363

Last change on this file since 363 was 363, checked in by MatthewWhiting, 17 years ago

Added parameters to write the header information that is presently in the results file to another file.

File size: 19.5 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  bool   getFlagSeparateHeader(){return flagSeparateHeader;};
153  void   setFlagSeparateHeader(bool b){flagSeparateHeader=b;};
154  std::string getHeaderFile(){return headerFile;};
155  void   setHeaderFile(std::string s){headerFile=s;};
156  std::string getSpectraFile(){return spectraFile;};
157  void   setSpectraFile(std::string fname){spectraFile = fname;};
158  bool   getFlagOutputSmooth(){return flagOutputSmooth;};
159  void   setFlagOutputSmooth(bool flag){flagOutputSmooth=flag;};
160  bool   getFlagOutputRecon(){return flagOutputRecon;};
161  void   setFlagOutputRecon(bool flag){flagOutputRecon=flag;};
162  bool   getFlagOutputResid(){return flagOutputResid;};
163  void   setFlagOutputResid(bool flag){flagOutputResid=flag;};
164  bool   getFlagVOT(){return flagVOT;};
165  void   setFlagVOT(bool flag){flagVOT=flag;};
166  std::string getVOTFile(){return votFile;};
167  void   setVOTFile(std::string fname){votFile = fname;};
168  bool   getFlagKarma(){return flagKarma;};
169  void   setFlagKarma(bool flag){flagKarma=flag;};
170  std::string getKarmaFile(){return karmaFile;};
171  void   setKarmaFile(std::string fname){karmaFile = fname;};
172  bool   getFlagMaps(){return flagMaps;};
173  void   setFlagMaps(bool flag){flagMaps=flag;};
174  std::string getDetectionMap(){return detectionMap;};
175  void   setDetectionMap(std::string fname){detectionMap = fname;};
176  std::string getMomentMap(){return momentMap;};
177  void   setMomentMap(std::string fname){momentMap = fname;};
178  bool   getFlagXOutput(){return flagXOutput;};
179  void   setFlagXOutput(bool b){flagXOutput=b;};
180  //
181  bool   getFlagNegative(){return flagNegative;};
182  void   setFlagNegative(bool flag){flagNegative=flag;};
183  bool   getFlagBlankPix(){return flagBlankPix;};
184  void   setFlagBlankPix(bool flag){flagBlankPix=flag;};
185  float  getBlankPixVal(){return blankPixValue;};
186  void   setBlankPixVal(float v){blankPixValue=v;};
187  int    getBlankKeyword(){return blankKeyword;};
188  void   setBlankKeyword(int v){blankKeyword=v;};
189  float  getBscaleKeyword(){return bscaleKeyword;};
190  void   setBscaleKeyword(float v){bscaleKeyword=v;};
191  float  getBzeroKeyword(){return bzeroKeyword;};
192  void   setBzeroKeyword(float v){bzeroKeyword=v;};
193  bool   getFlagMW(){return flagMW;};
194  void   setFlagMW(bool flag){flagMW=flag;};
195  int    getMaxMW(){return maxMW;};
196  void   setMaxMW(int m){maxMW=m;};
197  int    getMinMW(){return minMW;};
198  void   setMinMW(int m){minMW=m;};
199  void   setBeamSize(float s){numPixBeam = s;};
200  float  getBeamSize(){return numPixBeam;};
201  bool   getFlagUsingBeam(){return flagUsingBeam;};
202  void   setFlagUsingBeam(bool b){flagUsingBeam=b;};
203  //
204  bool   getFlagTrim(){return flagTrim;};
205  void   setFlagTrim(bool b){flagTrim=b;};
206  bool   getFlagCubeTrimmed(){return hasBeenTrimmed;};
207  void   setFlagCubeTrimmed(bool flag){hasBeenTrimmed = flag;};
208  long   getBorderLeft(){return borderLeft;};
209  void   setBorderLeft(long b){borderLeft = b;};
210  long   getBorderRight(){return borderRight;};
211  void   setBorderRight(long b){borderRight = b;};
212  long   getBorderBottom(){return borderBottom;};
213  void   setBorderBottom(long b){borderBottom = b;};
214  long   getBorderTop(){return borderTop;};
215  void   setBorderTop(long b){borderTop = b;};
216  //
217  long   getXOffset(){return xSubOffset;};
218  void   setXOffset(long o){xSubOffset = o;};
219  long   getYOffset(){return ySubOffset;};
220  void   setYOffset(long o){ySubOffset = o;};
221  long   getZOffset(){return zSubOffset;};
222  void   setZOffset(long o){zSubOffset = o;};
223  //
224  int    getMinPix(){return minPix;};
225  void   setMinPix(int m){minPix=m;};
226  //     
227  bool   getFlagGrowth(){return flagGrowth;};
228  void   setFlagGrowth(bool flag){flagGrowth=flag;};
229  float  getGrowthCut(){return growthCut;};
230  void   setGrowthCut(float c){growthCut=c;};
231  //     
232  bool   getFlagFDR(){return flagFDR;};
233  void   setFlagFDR(bool flag){flagFDR=flag;};
234  float  getAlpha(){return alphaFDR;};
235  void   setAlpha(float a){alphaFDR=a;};
236  //
237  bool   getFlagBaseline(){return flagBaseline;};
238  void   setFlagBaseline(bool flag){flagBaseline = flag;};
239  //
240  bool   getFlagStatSec(){return flagStatSec;};
241  void   setFlagStatSec(bool flag){flagStatSec=flag;};
242  std::string getStatSec(){return statSec.getSection();};
243  void   setStatSec(std::string range){statSec.setSection(range);};
244  float  getCut(){return snrCut;};
245  void   setCut(float c){snrCut=c;};
246  float  getThreshold(){return threshold;};
247  void   setThreshold(float f){threshold=f;};
248  bool   getFlagUserThreshold(){return flagUserThreshold;};
249  void   setFlagUserThreshold(bool b){flagUserThreshold=b;};
250  //     
251  bool   getFlagSmooth(){return flagSmooth;};
252  void   setFlagSmooth(bool b){flagSmooth=b;};
253  std::string getSmoothType(){return smoothType;};
254  void   setSmoothType(std::string s){smoothType=s;};
255  int    getHanningWidth(){return hanningWidth;};
256  void   setHanningWidth(int f){hanningWidth=f;};
257  void   setKernMaj(float f){kernMaj=f;};
258  float  getKernMaj(){return kernMaj;};
259  void   setKernMin(float f){kernMin=f;};
260  float  getKernMin(){return kernMin;};
261  void   setKernPA(float f){kernPA=f;};
262  float  getKernPA(){return kernPA;};
263  //     
264  bool   getFlagATrous(){return flagATrous;};
265  void   setFlagATrous(bool flag){flagATrous=flag;};
266  int    getReconDim(){return reconDim;};
267  void   setReconDim(int i){reconDim=i;};
268  int    getMinScale(){return scaleMin;};
269  void   setMinScale(int s){scaleMin=s;};
270  int    getMaxScale(){return scaleMax;};
271  void   setMaxScale(int s){scaleMax=s;};
272  float  getAtrousCut(){return snrRecon;};
273  void   setAtrousCut(float c){snrRecon=c;};
274  int    getFilterCode(){return filterCode;};
275  void   setFilterCode(int c){filterCode=c;};
276  std::string getFilterName(){return reconFilter.getName();};
277  Filter& filter(){ Filter &rfilter = reconFilter; return rfilter; };
278  //     
279  bool   getFlagAdjacent(){return flagAdjacent;};
280  void   setFlagAdjacent(bool flag){flagAdjacent=flag;};
281  float  getThreshS(){return threshSpatial;};
282  void   setThreshS(float t){threshSpatial=t;};
283  float  getThreshV(){return threshVelocity;};
284  void   setThreshV(float t){threshVelocity=t;};
285  int    getMinChannels(){return minChannels;};
286  void   setMinChannels(int n){minChannels=n;};
287  //
288  std::string getSpectralMethod(){return spectralMethod;};
289  void   setSpectralMethod(std::string s){spectralMethod=s;};
290  std::string getSpectralUnits(){return spectralUnits;};
291  void   setSpectralUnits(std::string s){spectralUnits=s;};
292  std::string getPixelCentre(){return pixelCentre;};
293  void   setPixelCentre(std::string s){pixelCentre=s;};
294  bool   drawBorders(){return borders;};
295  void   setDrawBorders(bool f){borders=f;};
296  bool   drawBlankEdge(){return blankEdge;};
297  void   setDrawBlankEdge(bool f){blankEdge=f;};
298
299  /** Are we in verbose mode? */
300  bool   isVerbose(){return verbose;};
301  void   setVerbosity(bool f){verbose=f;};
302 
303private:
304  // Input files
305  std::string imageFile;  ///< The image to be analysed.
306  bool   flagSubsection;  ///< Whether we just want a subsection of
307                          ///   the image
308  Section pixelSec;       ///< The Section object storing the pixel
309                          ///   subsection information.
310  bool   flagReconExists; ///< The reconstructed array is in a FITS
311                          ///   file on disk.
312  std::string reconFile;  ///< The FITS file containing the
313                          ///   reconstructed array.
314  bool   flagSmoothExists;///< The smoothed array is in a FITS file.
315  std::string smoothFile; ///< The FITS file containing the smoothed
316                          ///   array.
317
318  // Output files
319  bool   flagLog;         ///< Should we do the intermediate logging?
320  std::string logFile;    ///< Where the intermediate logging goes.
321  std::string outFile;    ///< Where the final results get put.
322  bool   flagSeparateHeader;///< Should the header information
323                            ///   (parameters & statistics) be written
324                            ///   to a separate file to the table of
325                            ///   results?
326  std::string headerFile; ///< Where the header information to go with
327                          ///   the results table should be written.
328  std::string spectraFile;///< Where the spectra are displayed
329  bool   flagOutputSmooth;///< Should the smoothed cube be written?
330  bool   flagOutputRecon; ///< Should the reconstructed cube be
331                          ///   written?
332  bool   flagOutputResid; ///< Should the reconstructed cube be
333                          ///   written?
334  bool   flagVOT;         ///< Should we save results in VOTable
335                          ///   format?
336  std::string votFile;    ///< Where the VOTable goes.
337  bool   flagKarma;       ///< Should we save results in Karma
338                          ///   annotation format?
339  std::string karmaFile;  ///< Where the Karma annotation file goes.
340  bool   flagMaps;        ///< Should we produce detection and moment
341                          ///   maps in postscript form?
342  std::string detectionMap;///< The name of the detection map
343                           ///   (postscript file).
344  std::string momentMap;  ///< The name of the 0th moment map (ps file).
345  bool   flagXOutput;     ///< Should there be an xwindows output of
346                          ///   the detection map?
347
348  // Cube related parameters
349  bool   flagNegative;    ///< Are we going to search for negative
350                          ///   features?
351  bool   flagBlankPix;    ///< A flag that indicates whether there are
352                          ///   pixels defined as BLANK and whether we
353                          ///   need to remove & ignore them in
354                          ///   processing.
355  float  blankPixValue;   ///< Pixel value that is considered BLANK.
356  int    blankKeyword;    ///< The FITS header keyword BLANK.
357  float  bscaleKeyword;   ///< The FITS header keyword BSCALE.
358  float  bzeroKeyword;    ///< The FITS header keyword BZERO.
359  //Milky-Way parameters
360  bool   flagMW;          ///< A flag that indicates whether to ignore
361                          ///   the Milky Way channels.
362  int    maxMW;           ///< Last  Milky Way channel
363  int    minMW;           ///< First Milky Way channel
364  // Trim-related
365  bool   flagTrim;        ///< Does the user want the cube trimmed?
366  bool   hasBeenTrimmed;  ///< Has the cube been trimmed of excess
367                          ///   BLANKs around the edge?
368  long   borderLeft;      ///< The number of BLANK pixels trimmed from
369                          ///   the left of the cube;
370  long   borderRight;     ///< The number trimmed from the Right of
371                          ///   the cube;
372  long   borderBottom;    ///< The number trimmed from the Bottom of
373                          ///   the cube;
374  long   borderTop;       ///< The number trimmed from the Top of the
375                          ///   cube;
376  // Subsection offsets
377  long  *offsets;         ///< The array of offsets for each FITS axis.
378  long   sizeOffsets;     ///< The size of the offsets array.
379  long   xSubOffset;      ///< The subsection's x-axis offset
380  long   ySubOffset;      ///< The subsection's y-axis offset
381  long   zSubOffset;      ///< The subsection's z-axis offset
382  // Baseline related
383  bool   flagBaseline;    ///< Whether to do baseline subtraction
384                          ///   before reconstruction and/or searching.
385  // Detection-related
386  int    minPix;          ///< Minimum number of pixels for a detected
387                          ///   object to be counted
388  float  numPixBeam;      ///< Size (area) of the beam in pixels.
389  bool   flagUsingBeam;   ///< If true, we are using the numPixBeam
390                          ///   parameter, otherwise we use the value
391                          ///   in the FITS header.
392  // Object growth
393  bool   flagGrowth;      ///< Are we growing objects once they are
394                          ///   found?
395  float  growthCut;       ///< The SNR that we are growing objects
396                          ///   down to.
397  // FDR analysis
398  bool   flagFDR;         ///< Should the FDR method be used?
399  float  alphaFDR;        ///< Alpha value for FDR detection algorithm
400  // Basic detection
401  bool   flagStatSec;     ///< Whether we just want to use a
402                          ///   subsection of the image to calculate
403                          ///   the statistics.
404  Section statSec;       ///< The Section object storing the statistics
405                          ///   subsection information.
406  float  snrCut;          ///< How many sigma above mean is a
407                          ///   detection when sigma-clipping
408  float  threshold;       ///< What the threshold is (when
409                          ///   sigma-clipping).
410  bool   flagUserThreshold;///< Whether the user has defined a
411                           ///   threshold of their own.
412  // Smoothing of the cube
413  bool   flagSmooth;      ///< Should the cube be smoothed before
414                          ///   searching?
415  std::string smoothType; ///< The type of smoothing to be done.
416  int    hanningWidth;    ///< Width for hanning smoothing.
417  float  kernMaj;         ///< Semi-Major axis of gaussian smoothing kernel
418  float  kernMin;         ///< Semi-Minor axis of gaussian smoothing kernel
419  float  kernPA;          ///< Position angle of gaussian smoothing
420                          ///   kernel, in degrees east of north
421                          ///   (i.e. anticlockwise).
422  // A trous reconstruction parameters
423  bool   flagATrous;      ///< Are we using the a trous reconstruction?
424  int    reconDim;        ///< How many dimensions to use for the
425                          ///   reconstruction?
426  int    scaleMin;        ///< Min scale used in a trous reconstruction
427  int    scaleMax;        ///< Max scale used in a trous reconstruction
428  float  snrRecon;        ///< SNR cutoff used in a trous
429                          ///   reconstruction (only wavelet coefficients
430                          ///   that survive this threshold are kept)
431  Filter reconFilter;     ///< The filter used for reconstructions.
432  int    filterCode;      ///< The code number for the filter to be
433                          ///   used (saves having to parse names)
434  std::string filterName; ///< The code number converted into a name,
435                          ///   for outputting purposes.
436
437  // Volume-merging parameters
438  bool   flagAdjacent;    ///< Whether to use the adjacent criterion
439                          ///   for judging if objects are to be merged.
440  float  threshSpatial;   ///< Maximum spatial separation between
441                          ///   objects
442  float  threshVelocity;  ///< Maximum channels separation between
443                          ///   objects
444  int    minChannels;     ///< Minimum no. of channels to make an object
445  // Input-Output related
446  std::string spectralMethod; ///< A string indicating choice of
447                              ///   spectral plotting method: choices are
448                              ///   "peak" (default) or "sum"
449  std::string spectralUnits;   ///< A string indicating what units the
450                               ///   spectral axis should be quoted in.
451  std::string pixelCentre;///< A string indicating which type of
452                          ///   centre to give the results in: "average",
453                          ///   "centroid", or "peak"(flux).
454  bool   borders;         ///< Whether to draw a border around the
455                          ///   individual pixels of a detection in the
456                          ///   spectral display
457  bool   blankEdge;       ///< Whether to draw a border around the
458                          ///   BLANK pixel region in the moment maps and
459                          ///   cutout images
460  bool   verbose;         ///< Whether to use maximum verbosity -- use
461                          ///   progress indicators in the reconstruction
462                          ///   & merging steps.
463
464};
465
466//===========================================================================
467
468
469std::string makelower( std::string s );
470
471#endif
Note: See TracBrowser for help on using the repository browser.