source: trunk/src/param.hh @ 521

Last change on this file since 521 was 521, checked in by MatthewWhiting, 15 years ago

Changes for ticket #48, allowing the MASK image to record the object ID of detected pixels. Involves a new parameter flagMaskWithObjectNum.

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