source: trunk/src/param.hh @ 513

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

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