source: tags/release-1.1.6/src/param.hh

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

Implemented changes to Duchamp to allow the re-plotting of object spectra. This incorporates the functionality of Selavy into Duchamp, so that you only need a single executable.

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