source: tags/release-1.1.5/src/param.hh @ 1441

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

Adding an annotationType parameter to be able to switch between different karma styles.

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