source: trunk/src/param.hh @ 349

Last change on this file since 349 was 348, checked in by MatthewWhiting, 17 years ago
  • Added a "scaleMax" parameter, so we can specify a range of scales to be used in the reconstruction. Changed the 1D reconstruction code as well.
  • Minor fixes to the merger code so 2D data doesn't do unnecessary checking.
  • Other minor fixes to work around bugs in outputs.
File size: 19.0 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  int    getMaxScale(){return scaleMax;};
267  void   setMaxScale(int s){scaleMax=s;};
268  float  getAtrousCut(){return snrRecon;};
269  void   setAtrousCut(float c){snrRecon=c;};
270  int    getFilterCode(){return filterCode;};
271  void   setFilterCode(int c){filterCode=c;};
272  std::string getFilterName(){return reconFilter.getName();};
273  Filter& filter(){ Filter &rfilter = reconFilter; return rfilter; };
274  //     
275  bool   getFlagAdjacent(){return flagAdjacent;};
276  void   setFlagAdjacent(bool flag){flagAdjacent=flag;};
277  float  getThreshS(){return threshSpatial;};
278  void   setThreshS(float t){threshSpatial=t;};
279  float  getThreshV(){return threshVelocity;};
280  void   setThreshV(float t){threshVelocity=t;};
281  int    getMinChannels(){return minChannels;};
282  void   setMinChannels(int n){minChannels=n;};
283  //
284  std::string getSpectralMethod(){return spectralMethod;};
285  void   setSpectralMethod(std::string s){spectralMethod=s;};
286  std::string getSpectralUnits(){return spectralUnits;};
287  void   setSpectralUnits(std::string s){spectralUnits=s;};
288  std::string getPixelCentre(){return pixelCentre;};
289  void   setPixelCentre(std::string s){pixelCentre=s;};
290  bool   drawBorders(){return borders;};
291  void   setDrawBorders(bool f){borders=f;};
292  bool   drawBlankEdge(){return blankEdge;};
293  void   setDrawBlankEdge(bool f){blankEdge=f;};
294
295  /** Are we in verbose mode? */
296  bool   isVerbose(){return verbose;};
297  void   setVerbosity(bool f){verbose=f;};
298 
299private:
300  // Input files
301  std::string imageFile;  ///< The image to be analysed.
302  bool   flagSubsection;  ///< Whether we just want a subsection of
303                          ///   the image
304  Section pixelSec;       ///< The Section object storing the pixel
305                          ///   subsection information.
306  bool   flagReconExists; ///< The reconstructed array is in a FITS
307                          ///   file on disk.
308  std::string reconFile;  ///< The FITS file containing the
309                          ///   reconstructed array.
310  bool   flagSmoothExists;///< The smoothed array is in a FITS file.
311  std::string smoothFile; ///< The FITS file containing the smoothed
312                          ///   array.
313
314  // Output files
315  bool   flagLog;         ///< Should we do the intermediate logging?
316  std::string logFile;    ///< Where the intermediate logging goes.
317  std::string outFile;    ///< Where the final results get put.
318  std::string spectraFile;///< Where the spectra are displayed
319  bool   flagOutputSmooth;///< Should the smoothed cube be written?
320  bool   flagOutputRecon; ///< Should the reconstructed cube be
321                          ///   written?
322  bool   flagOutputResid; ///< Should the reconstructed cube be
323                          ///   written?
324  bool   flagVOT;         ///< Should we save results in VOTable
325                          ///   format?
326  std::string votFile;    ///< Where the VOTable goes.
327  bool   flagKarma;       ///< Should we save results in Karma
328                          ///   annotation format?
329  std::string karmaFile;  ///< Where the Karma annotation file goes.
330  bool   flagMaps;        ///< Should we produce detection and moment
331                          ///   maps in postscript form?
332  std::string detectionMap;///< The name of the detection map
333                           ///   (postscript file).
334  std::string momentMap;  ///< The name of the 0th moment map (ps file).
335  bool   flagXOutput;     ///< Should there be an xwindows output of
336                          ///   the detection map?
337
338  // Cube related parameters
339  bool   flagNegative;    ///< Are we going to search for negative
340                          ///   features?
341  bool   flagBlankPix;    ///< A flag that indicates whether there are
342                          ///   pixels defined as BLANK and whether we
343                          ///   need to remove & ignore them in
344                          ///   processing.
345  float  blankPixValue;   ///< Pixel value that is considered BLANK.
346  int    blankKeyword;    ///< The FITS header keyword BLANK.
347  float  bscaleKeyword;   ///< The FITS header keyword BSCALE.
348  float  bzeroKeyword;    ///< The FITS header keyword BZERO.
349  //Milky-Way parameters
350  bool   flagMW;          ///< A flag that indicates whether to ignore
351                          ///   the Milky Way channels.
352  int    maxMW;           ///< Last  Milky Way channel
353  int    minMW;           ///< First Milky Way channel
354  // Trim-related
355  bool   flagTrim;        ///< Does the user want the cube trimmed?
356  bool   hasBeenTrimmed;  ///< Has the cube been trimmed of excess
357                          ///   BLANKs around the edge?
358  long   borderLeft;      ///< The number of BLANK pixels trimmed from
359                          ///   the left of the cube;
360  long   borderRight;     ///< The number trimmed from the Right of
361                          ///   the cube;
362  long   borderBottom;    ///< The number trimmed from the Bottom of
363                          ///   the cube;
364  long   borderTop;       ///< The number trimmed from the Top of the
365                          ///   cube;
366  // Subsection offsets
367  long  *offsets;         ///< The array of offsets for each FITS axis.
368  long   sizeOffsets;     ///< The size of the offsets array.
369  long   xSubOffset;      ///< The subsection's x-axis offset
370  long   ySubOffset;      ///< The subsection's y-axis offset
371  long   zSubOffset;      ///< The subsection's z-axis offset
372  // Baseline related
373  bool   flagBaseline;    ///< Whether to do baseline subtraction
374                          ///   before reconstruction and/or searching.
375  // Detection-related
376  int    minPix;          ///< Minimum number of pixels for a detected
377                          ///   object to be counted
378  float  numPixBeam;      ///< Size (area) of the beam in pixels.
379  bool   flagUsingBeam;   ///< If true, we are using the numPixBeam
380                          ///   parameter, otherwise we use the value
381                          ///   in the FITS header.
382  // Object growth
383  bool   flagGrowth;      ///< Are we growing objects once they are
384                          ///   found?
385  float  growthCut;       ///< The SNR that we are growing objects
386                          ///   down to.
387  // FDR analysis
388  bool   flagFDR;         ///< Should the FDR method be used?
389  float  alphaFDR;        ///< Alpha value for FDR detection algorithm
390  // Basic detection
391  bool   flagStatSec;     ///< Whether we just want to use a
392                          ///   subsection of the image to calculate
393                          ///   the statistics.
394  Section statSec;       ///< The Section object storing the statistics
395                          ///   subsection information.
396  float  snrCut;          ///< How many sigma above mean is a
397                          ///   detection when sigma-clipping
398  float  threshold;       ///< What the threshold is (when
399                          ///   sigma-clipping).
400  bool   flagUserThreshold;///< Whether the user has defined a
401                           ///   threshold of their own.
402  // Smoothing of the cube
403  bool   flagSmooth;      ///< Should the cube be smoothed before
404                          ///   searching?
405  std::string smoothType; ///< The type of smoothing to be done.
406  int    hanningWidth;    ///< Width for hanning smoothing.
407  float  kernMaj;         ///< Semi-Major axis of gaussian smoothing kernel
408  float  kernMin;         ///< Semi-Minor axis of gaussian smoothing kernel
409  float  kernPA;          ///< Position angle of gaussian smoothing
410                          ///   kernel, in degrees east of north
411                          ///   (i.e. anticlockwise).
412  // A trous reconstruction parameters
413  bool   flagATrous;      ///< Are we using the a trous reconstruction?
414  int    reconDim;        ///< How many dimensions to use for the
415                          ///   reconstruction?
416  int    scaleMin;        ///< Min scale used in a trous reconstruction
417  int    scaleMax;        ///< Max scale used in a trous reconstruction
418  float  snrRecon;        ///< SNR cutoff used in a trous
419                          ///   reconstruction (only wavelet coefficients
420                          ///   that survive this threshold are kept)
421  Filter reconFilter;     ///< The filter used for reconstructions.
422  int    filterCode;      ///< The code number for the filter to be
423                          ///   used (saves having to parse names)
424  std::string filterName; ///< The code number converted into a name,
425                          ///   for outputting purposes.
426
427  // Volume-merging parameters
428  bool   flagAdjacent;    ///< Whether to use the adjacent criterion
429                          ///   for judging if objects are to be merged.
430  float  threshSpatial;   ///< Maximum spatial separation between
431                          ///   objects
432  float  threshVelocity;  ///< Maximum channels separation between
433                          ///   objects
434  int    minChannels;     ///< Minimum no. of channels to make an object
435  // Input-Output related
436  std::string spectralMethod; ///< A string indicating choice of
437                              ///   spectral plotting method: choices are
438                              ///   "peak" (default) or "sum"
439  std::string spectralUnits;   ///< A string indicating what units the
440                               ///   spectral axis should be quoted in.
441  std::string pixelCentre;///< A string indicating which type of
442                          ///   centre to give the results in: "average",
443                          ///   "centroid", or "peak"(flux).
444  bool   borders;         ///< Whether to draw a border around the
445                          ///   individual pixels of a detection in the
446                          ///   spectral display
447  bool   blankEdge;       ///< Whether to draw a border around the
448                          ///   BLANK pixel region in the moment maps and
449                          ///   cutout images
450  bool   verbose;         ///< Whether to use maximum verbosity -- use
451                          ///   progress indicators in the reconstruction
452                          ///   & merging steps.
453
454};
455
456//===========================================================================
457
458
459std::string makelower( std::string s );
460
461#endif
Note: See TracBrowser for help on using the repository browser.