source: trunk/src/param.hh @ 503

Last change on this file since 503 was 503, checked in by MatthewWhiting, 16 years ago

Fixing a couple of bugs in the Param copying function, and making the parameter checking routines in the readParams function a separate function checkPars().

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