source: trunk/src/param.cc @ 642

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

Changing references of unsigned ints to size_t, or to use of iterators. Also fixing one bug in Object2D::getNumDistinctX, where we weren't looking at all scans. This
should fix ticket #63.

File size: 51.1 KB
Line 
1// -----------------------------------------------------------------------
2// param.cc: Dealing with the set of parameters for Duchamp.
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#include <iostream>
29#include <iomanip>
30#include <fstream>
31#include <sstream>
32#include <string>
33#include <algorithm>
34#include <stdlib.h>
35#include <ctype.h>
36#include <math.h>
37#include <unistd.h>
38#include <duchamp/param.hh>
39#include <duchamp/fitsHeader.hh>
40#include <duchamp/duchamp.hh>
41#include <duchamp/pgheader.hh>
42#include <duchamp/ATrous/filter.hh>
43#include <duchamp/Utils/utils.hh>
44#include <duchamp/Utils/Section.hh>
45#include <duchamp/Detection/columns.hh>
46
47namespace duchamp
48{
49
50  /****************************************************************/
51  ///////////////////////////////////////////////////
52  //// Accessor Functions for Parameter class:
53  ///////////////////////////////////////////////////
54  Param::~Param()
55  {
56    /// Deletes the offsets array if the sizeOffsets parameter is
57    /// positive.
58    if(this->sizeOffsets>0) delete [] this->offsets;
59  }
60
61  Param::Param()
62  {
63    this->defaultValues();
64  }
65
66  void Param::defaultValues()
67  {
68    /// Provides default intial values for the parameters. Note that
69    /// imageFile has no default value!
70
71    std::string baseSection = "[*,*,*]";
72    // Input files
73    this->imageFile         = "";
74    this->flagSubsection    = false;
75    this->pixelSec.setSection(baseSection);
76    this->flagReconExists   = false;
77    this->reconFile         = "";
78    this->flagSmoothExists  = false;
79    this->smoothFile        = "";
80    this->usePrevious       = false;
81    this->objectList        = "";
82    // Output files
83    this->flagLog           = false;
84    this->logFile           = "duchamp-Logfile.txt";
85    this->outFile           = "duchamp-Results.txt";
86    this->flagSeparateHeader= false;
87    this->headerFile        = "duchamp-Results.hdr";
88    this->spectraFile       = "duchamp-Spectra.ps";
89    this->flagTextSpectra   = false;
90    this->spectraTextFile   = "duchamp-Spectra.txt";
91    this->flagOutputMask    = false;
92    this->fileOutputMask    = "";
93    this->flagMaskWithObjectNum = false;
94    this->flagOutputSmooth  = false;
95    this->fileOutputSmooth  = "";
96    this->flagOutputRecon   = false;
97    this->fileOutputRecon   = "";
98    this->flagOutputResid   = false;
99    this->fileOutputResid   = "";
100    this->flagVOT           = false;
101    this->votFile           = "duchamp-Results.xml";
102    this->flagKarma         = false;
103    this->karmaFile         = "duchamp-Results.ann";
104    this->annotationType    = "borders";
105    this->flagMaps          = true;
106    this->detectionMap      = "duchamp-DetectionMap.ps";
107    this->momentMap         = "duchamp-MomentMap.ps";
108    this->flagXOutput       = true;
109    this->precFlux          = Column::prFLUX;
110    this->precVel           = Column::prVEL;
111    this->precSNR           = Column::prSNR;
112    // Cube related parameters
113    this->flagBlankPix      = true;
114    this->blankPixValue     = -8.00061;
115    this->blankKeyword      = 1;
116    this->bscaleKeyword     = -8.00061;
117    this->bzeroKeyword      = 0.;
118    this->newFluxUnits      = "";
119    // Milky-Way parameters
120    this->flagMW            = false;
121    this->maxMW             = 112;
122    this->minMW             = 75;
123    this->numPixBeam        = 10.;
124    this->flagUsingBeam     = false;
125    // Trim-related         
126    this->flagTrim          = false;
127    this->hasBeenTrimmed    = false;
128    this->borderLeft        = 0;
129    this->borderRight       = 0;
130    this->borderBottom      = 0;
131    this->borderTop         = 0;
132    // Subsection offsets
133    this->sizeOffsets       = 0;
134    this->xSubOffset        = 0;
135    this->ySubOffset        = 0;
136    this->zSubOffset        = 0;
137    // Baseline related
138    this->flagBaseline      = false;
139    // Detection-related   
140    this->flagNegative      = false;
141    // Object growth       
142    this->flagGrowth        = false;
143    this->growthCut         = 3.;
144    this->flagUserGrowthThreshold = false;
145    this->growthThreshold   = 0.;
146    // FDR analysis         
147    this->flagFDR           = false;
148    this->alphaFDR          = 0.01;
149    this->FDRnumCorChan     = 2;
150    // Other detection     
151    this->flagStatSec       = false;
152    this->statSec.setSection(baseSection);
153    this->flagRobustStats   = true;
154    this->snrCut            = 3.;
155    this->threshold         = 0.;
156    this->flagUserThreshold = false;
157    // Smoothing
158    this->flagSmooth        = false;
159    this->smoothType        = "spectral";
160    this->hanningWidth      = 5;
161    this->kernMaj           = 3.;
162    this->kernMin           = -1.;
163    this->kernPA            = 0.;
164    // A trous reconstruction parameters
165    this->flagATrous        = false;
166    this->reconDim          = 1;
167    this->scaleMin          = 1;
168    this->scaleMax          = 0;
169    this->snrRecon          = 4.;
170    this->filterCode        = 1;
171    this->reconFilter.define(this->filterCode);
172    // Volume-merging parameters
173    this->flagAdjacent      = true;
174    this->threshSpatial     = 3.;
175    this->threshVelocity    = 7.;
176    this->minChannels       = 3;
177    this->minPix            = 2;
178    // Input-Output related
179    this->spectralMethod    = "peak";
180    this->spectralUnits     = "km/s";
181    this->pixelCentre       = "centroid";
182    this->sortingParam      = "vel";
183    this->borders           = true;
184    this->blankEdge         = true;
185    this->verbose           = true;
186  }
187
188  Param::Param (const Param& p)
189  {
190    operator=(p);
191  }
192
193  Param& Param::operator= (const Param& p)
194  {
195    if(this == &p) return *this;
196    this->imageFile         = p.imageFile;
197    this->flagSubsection    = p.flagSubsection;
198    this->pixelSec          = p.pixelSec;
199    this->flagReconExists   = p.flagReconExists;
200    this->reconFile         = p.reconFile;     
201    this->flagSmoothExists  = p.flagSmoothExists;
202    this->smoothFile        = p.smoothFile;     
203    this->usePrevious       = p.usePrevious;
204    this->objectList        = p.objectList;
205    this->flagLog           = p.flagLog;       
206    this->logFile           = p.logFile;       
207    this->outFile           = p.outFile;       
208    this->flagSeparateHeader= p.flagSeparateHeader;
209    this->headerFile        = p.headerFile;
210    this->spectraFile       = p.spectraFile;   
211    this->flagTextSpectra   = p.flagTextSpectra;   
212    this->spectraTextFile   = p.spectraTextFile;   
213    this->flagOutputMask    = p.flagOutputMask;
214    this->fileOutputMask    = p.fileOutputMask;
215    this->flagMaskWithObjectNum = p.flagMaskWithObjectNum;
216    this->flagOutputSmooth  = p.flagOutputSmooth;
217    this->fileOutputSmooth  = p.fileOutputSmooth;
218    this->flagOutputRecon   = p.flagOutputRecon;
219    this->fileOutputRecon   = p.fileOutputRecon;
220    this->flagOutputResid   = p.flagOutputResid;
221    this->fileOutputResid   = p.fileOutputResid;
222    this->flagVOT           = p.flagVOT;         
223    this->votFile           = p.votFile;       
224    this->flagKarma         = p.flagKarma;     
225    this->karmaFile         = p.karmaFile;     
226    this->annotationType    = p.annotationType;
227    this->flagMaps          = p.flagMaps;       
228    this->detectionMap      = p.detectionMap;   
229    this->momentMap         = p.momentMap;     
230    this->flagXOutput       = p.flagXOutput;       
231    this->precFlux          = p.precFlux;
232    this->precVel           = p.precVel;
233    this->precSNR           = p.precSNR;
234    this->flagBlankPix      = p.flagBlankPix;   
235    this->blankPixValue     = p.blankPixValue; 
236    this->blankKeyword      = p.blankKeyword;   
237    this->bscaleKeyword     = p.bscaleKeyword; 
238    this->bzeroKeyword      = p.bzeroKeyword;   
239    this->newFluxUnits      = p.newFluxUnits;
240    this->flagMW            = p.flagMW;         
241    this->maxMW             = p.maxMW;         
242    this->minMW             = p.minMW;         
243    this->numPixBeam        = p.numPixBeam;     
244    this->flagTrim          = p.flagTrim;   
245    this->hasBeenTrimmed    = p.hasBeenTrimmed;   
246    this->borderLeft        = p.borderLeft;     
247    this->borderRight       = p.borderRight;   
248    this->borderBottom      = p.borderBottom;   
249    this->borderTop         = p.borderTop;     
250    if(this->sizeOffsets>0) delete [] this->offsets;
251    this->sizeOffsets       = p.sizeOffsets;
252    if(this->sizeOffsets>0){
253      this->offsets           = new long[this->sizeOffsets];
254      for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
255    }
256    this->xSubOffset        = p.xSubOffset;     
257    this->ySubOffset        = p.ySubOffset;     
258    this->zSubOffset        = p.zSubOffset;
259    this->flagBaseline      = p.flagBaseline;
260    this->flagNegative      = p.flagNegative;
261    this->flagGrowth        = p.flagGrowth;
262    this->growthCut         = p.growthCut;
263    this->growthThreshold   = p.growthThreshold;
264    this->flagUserGrowthThreshold = p.flagUserGrowthThreshold;
265    this->flagFDR           = p.flagFDR;
266    this->alphaFDR          = p.alphaFDR;
267    this->FDRnumCorChan     = p.FDRnumCorChan;
268    this->flagStatSec       = p.flagStatSec;
269    this->statSec           = p.statSec;
270    this->flagRobustStats   = p.flagRobustStats;
271    this->snrCut            = p.snrCut;
272    this->threshold         = p.threshold;
273    this->flagUserThreshold = p.flagUserThreshold;
274    this->flagSmooth        = p.flagSmooth;
275    this->smoothType        = p.smoothType;
276    this->hanningWidth      = p.hanningWidth;
277    this->kernMaj           = p.kernMaj;
278    this->kernMin           = p.kernMin;
279    this->kernPA            = p.kernPA;
280    this->flagATrous        = p.flagATrous;
281    this->reconDim          = p.reconDim;
282    this->scaleMin          = p.scaleMin;
283    this->scaleMax          = p.scaleMax;
284    this->snrRecon          = p.snrRecon;
285    this->filterCode        = p.filterCode;
286    this->reconFilter       = p.reconFilter;
287    this->flagAdjacent      = p.flagAdjacent;
288    this->threshSpatial     = p.threshSpatial;
289    this->threshVelocity    = p.threshVelocity;
290    this->minChannels       = p.minChannels;
291    this->minPix            = p.minPix;
292    this->spectralMethod    = p.spectralMethod;
293    this->spectralUnits     = p.spectralUnits;
294    this->pixelCentre       = p.pixelCentre;
295    this->sortingParam      = p.sortingParam;
296    this->borders           = p.borders;
297    this->blankEdge         = p.blankEdge;
298    this->verbose           = p.verbose;
299    return *this;
300  }
301  //--------------------------------------------------------------------
302
303  int Param::getopts(int argc, char ** argv, std::string progname)
304  {
305    ///   A function that reads in the command-line options, in a manner
306    ///    tailored for use with the main Duchamp program.
307    ///
308    ///   \param argc The number of command line arguments.
309    ///   \param argv The array of command line arguments.
310
311    int returnValue = FAILURE;
312    if(argc==1){
313      if(progname=="Selavy") std::cout << SELAVY_ERR_USAGE_MSG;
314      else if(progname=="Duchamp") std::cout << ERR_USAGE_MSG;
315      else std::cout << ERR_USAGE_MSG;
316      returnValue = FAILURE;
317    }
318    else {
319      std::string file;
320      bool changeX = false;
321      this->defaultValues();
322      char c;
323      while( ( c = getopt(argc,argv,"p:f:hvx") )!=-1){
324        switch(c) {
325        case 'p':
326          file = optarg;
327          if(this->readParams(file)==FAILURE){
328            std::stringstream errmsg;
329            errmsg << "Could not open parameter file " << file << ".\n";
330            duchampError(progname,errmsg.str());
331          }
332          else returnValue = SUCCESS;
333          break;
334        case 'f':
335          file = optarg;
336          this->imageFile = file;
337          returnValue = SUCCESS;
338          break;
339        case 'v':
340          std::cout << PROGNAME << " version " << VERSION << std::endl;
341          break;
342        case 'x':
343          changeX = true;
344          break;
345        case 'h':
346        default :
347          if(progname=="Selavy") std::cout << SELAVY_ERR_USAGE_MSG;
348          else if(progname=="Duchamp") std::cout << ERR_USAGE_MSG;
349          else std::cout << ERR_USAGE_MSG;
350          break;
351        }
352      }
353      if(changeX){
354        if(returnValue == SUCCESS) this->setFlagXOutput(false);
355        else {
356          duchampError(progname,
357                       "You need to specify either a parameter file or FITS image.\n");
358          std::cout << "\n" << ERR_USAGE_MSG;
359        }
360      }
361    }
362    return returnValue;
363  }
364  //--------------------------------------------------------------------
365
366  bool Param::isBlank(float &value)
367  {
368    ///  Tests whether the value passed as the argument is BLANK or not.
369    ///  \param value Pixel value to be tested.
370    ///  \return False if flagBlankPix is false. Else, compare to the
371    ///  relevant FITS keywords, using integer comparison.
372
373    return this->flagBlankPix &&
374      (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
375  }
376
377  bool *Param::makeBlankMask(float *array, int size)
378  {
379    ///  This returns an array of bools, saying whether each pixel in the
380    ///  given array is BLANK or not. If the pixel is BLANK, set mask to
381    ///  false, else set to true. The array is allocated by the function.
382
383    bool *mask = new bool[size];
384    for(int i=0;i<size;i++) mask[i] = !this->isBlank(array[i]);
385    return mask;
386  }
387
388
389  bool *Param::makeStatMask(float *array, long *dim)
390  {
391    ///  This returns an array of bools, saying whether each pixel in
392    ///  the given array is suitable for a stats calculation. It needs
393    ///  to be in the StatSec (if defined), not blank and not a MW
394    ///  channel. The array is allocated by the function with a 'new' call.
395
396    bool *mask = new bool[dim[0]*dim[1]*dim[2]];
397    for(int x=0;x<dim[0];x++) {
398      for(int y=0;y<dim[1];y++) {
399        for(int z=0;z<dim[2];z++) {
400          int i = x+y*dim[0]+z*dim[0]*dim[1];
401          mask[i] = !this->isBlank(array[i]) && !this->isInMW(z) && this->isStatOK(x,y,z);
402        }
403      }
404    }
405    return mask;
406  }
407
408
409  bool Param::isInMW(int z)
410  {
411    ///  Tests whether we are flagging Milky Way channels, and if so
412    /// whether the given channel number is in the Milky Way range. The
413    /// channels are assumed to start at number 0. 
414    /// \param z The channel number
415    /// \return True if we are flagging Milky Way channels and z is in
416    ///  the range.
417
418    return ( flagMW && (z>=minMW) && (z<=maxMW) );
419  }
420
421  bool Param::isStatOK(int x, int y, int z)
422  {
423   /// Test whether a given pixel position lies within the subsection
424   /// given by the statSec parameter. Only tested if the flagSubsection
425   /// parameter is true -- if it isn't, we just return true since all
426   /// pixels are therefore available for statstical calculations.
427   /// \param x X-value of pixel being tested.
428   /// \param y Y-value of pixel being tested.
429   /// \param z Z-value of pixel being tested.
430   /// \return True if pixel is able to be used for statistical
431   /// calculations. False otherwise.
432
433    int xval=x,yval=y,zval=z;
434    if(flagSubsection){
435      xval += pixelSec.getStart(0);
436      yval += pixelSec.getStart(1);
437      zval += pixelSec.getStart(2);
438    }
439    return !flagStatSec || statSec.isInside(xval,yval,zval);
440  }
441
442  std::vector<int> Param::getObjectRequest()
443  {
444    ///  Returns a list of the object numbers requested via the objectList parameter.
445    /// \return a vector of integers, one for each number in the objectList set.
446
447    std::stringstream ss1;
448    std::string tmp;
449    std::vector<int> tmplist;
450    ss1.str(this->objectList);
451    while(!ss1.eof()){
452      getline(ss1,tmp,',');
453      for(size_t i=0;i<tmp.size();i++) if(tmp[i]=='-') tmp[i]=' ';
454      int a,b;
455      std::stringstream ss2;
456      ss2.str(tmp);
457      ss2 >>a;
458      if(!ss2.eof()) ss2 >> b;
459      else b=a;
460      for(int n=a;n<=b;n++){
461        tmplist.push_back(n);
462      }     
463    }
464    return tmplist;
465  }
466
467  std::vector<bool> Param::getObjectChoices()
468  {
469    ///  Returns a list of bool values, indicating whether a given
470    ///  object was requested or not. The size of the vector is
471    ///  determined by the maximum value in objectList. For instance,
472    ///  if objectList="2,3,5-8", then the returned vector will be
473    ///  [0,1,1,0,1,1,1,1].
474    ///  \return Vector of bool values.
475
476    std::vector<int> objectChoices = this->getObjectRequest();
477    int maxNum = *std::max_element(objectChoices.begin(), objectChoices.end());
478    std::vector<bool> choices(maxNum,false);
479    for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++)
480      choices[*obj-1] = true;
481    return choices;
482  }
483
484  std::vector<bool> Param::getObjectChoices(int numObjects)
485  {
486    ///  Returns a list of bool values, indicating whether a given
487    ///  object was requested or not. The size of the vector is given
488    ///  by the numObjects parameter. So, if objectList="2,3,5-8", then
489    ///  the returned vector from a getObjectChoices(10) call will be
490    ///  [0,1,1,0,1,1,1,1,0,0].
491    ///  \param numObjects How many objects there are in total.
492    ///  \return Vector of bool values.
493
494    if(this->objectList==""){
495      std::vector<bool> choices(numObjects,true);
496      return choices;
497    }
498    else{
499      std::vector<int> objectChoices = this->getObjectRequest();
500      std::vector<bool> choices(numObjects,false);
501      for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++)
502        if(*obj<=numObjects) choices[*obj-1] = true;
503      return choices;
504    }
505  }
506
507  /****************************************************************/
508  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
509  /// / Other Functions using the  Parameter class:
510  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
511
512  std::string makelower( std::string s )
513  {
514    // "borrowed" from Matt Howlett's 'fred'
515    std::string out = "";
516    for( size_t i=0; i<s.size(); ++i ) {
517      out += tolower(s[i]);
518    }
519    return out;
520  }
521
522  inline std::string stringize(bool b)
523  {
524   /// Convert a bool variable to the textual equivalent.
525   /// \return A std::string with the english equivalent of the bool.
526
527    std::string output;
528    if(b) output="true";
529    else output="false";
530    return output;
531  }
532
533  inline bool boolify( std::string s )
534  {
535    ///  Convert a std::string to a bool variable:
536    ///  "1" and "true" get converted to true;
537    ///  "0" and "false" (and anything else) get converted to false.
538    /// \return The bool equivalent of the string.
539
540    if((s=="1") || (makelower(s)=="true")) return true;
541    else if((s=="0") || (makelower(s)=="false")) return false;
542    else return false;
543  }
544
545  inline std::string readSval(std::stringstream& ss)
546  {
547    std::string val; ss >> val; return val;
548  }
549
550  inline bool readFlag(std::stringstream& ss)
551  {
552    std::string val; ss >> val; return boolify(val);
553  }
554
555  inline float readFval(std::stringstream& ss)
556  {
557    float val; ss >> val; return val;
558  }
559
560  inline int readIval(std::stringstream& ss)
561  {
562    int val; ss >> val; return val;
563  }
564
565  int Param::readParams(std::string paramfile)
566  {
567    /// The parameters are read in from a disk file, on the assumption that each
568    ///  line of the file has the format "parameter value" (eg. alphafdr 0.1)
569    ///
570    /// The case of the parameter name does not matter, nor does the
571    /// formatting of the spaces (it can be any amount of whitespace or
572    /// tabs).
573    ///
574    /// \param paramfile A std::string containing the parameter filename.
575    ///
576    /// \return FAILURE if the parameter file does not exist. SUCCESS if
577    /// it is able to read it.
578
579    std::ifstream fin(paramfile.c_str());
580    if(!fin.is_open()) return FAILURE;
581    std::string line;
582    while( !std::getline(fin,line,'\n').eof()){
583
584      if(line[0]!='#'){
585        std::stringstream ss;
586        ss.str(line);
587        std::string arg;
588        ss >> arg;
589        arg = makelower(arg);
590        if(arg=="imagefile")       this->imageFile = readSval(ss);
591        if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
592        if(arg=="subsection")      this->pixelSec.setSection(readSval(ss));
593        if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
594        if(arg=="reconfile")       this->reconFile = readSval(ss);
595        if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
596        if(arg=="smoothfile")      this->smoothFile = readSval(ss);
597        if(arg=="beamsize")        this->numPixBeam = readFval(ss);
598        if(arg=="useprevious")     this->usePrevious = readFlag(ss);
599        if(arg=="objectlist")      this->objectList = readSval(ss);
600
601        if(arg=="flaglog")         this->flagLog = readFlag(ss);
602        if(arg=="logfile")         this->logFile = readSval(ss);
603        if(arg=="outfile")         this->outFile = readSval(ss);
604        if(arg=="flagseparateheader") this->flagSeparateHeader = readFlag(ss);
605        if(arg=="headerfile")      this->headerFile = readSval(ss);
606        if(arg=="spectrafile")     this->spectraFile = readSval(ss);
607        if(arg=="flagtextspectra") this->flagTextSpectra = readFlag(ss);
608        if(arg=="spectratextfile") this->spectraTextFile = readSval(ss);
609        if(arg=="flagoutputmask")  this->flagOutputMask = readFlag(ss);
610        if(arg=="fileoutputmask")  this->fileOutputMask = readSval(ss);
611        if(arg=="flagmaskwithobjectnum") this->flagMaskWithObjectNum = readFlag(ss);
612        if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
613        if(arg=="fileoutputsmooth")this->fileOutputSmooth = readSval(ss);
614        if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
615        if(arg=="fileoutputrecon") this->fileOutputRecon = readSval(ss);
616        if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
617        if(arg=="fileoutputresid") this->fileOutputResid = readSval(ss);
618        if(arg=="flagvot")         this->flagVOT = readFlag(ss);
619        if(arg=="votfile")         this->votFile = readSval(ss);
620        if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
621        if(arg=="karmafile")       this->karmaFile = readSval(ss);
622        if(arg=="annotationtype")  this->annotationType = readSval(ss);
623        if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
624        if(arg=="detectionmap")    this->detectionMap = readSval(ss);
625        if(arg=="momentmap")       this->momentMap = readSval(ss);
626        if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
627        if(arg=="newfluxunits")    this->newFluxUnits = readSval(ss);
628        if(arg=="precflux")        this->precFlux = readIval(ss);
629        if(arg=="precvel")         this->precVel = readIval(ss);
630        if(arg=="precsnr")         this->precSNR = readIval(ss);
631
632        if(arg=="flagtrim")        this->flagTrim = readFlag(ss);
633        if(arg=="flagmw")          this->flagMW = readFlag(ss);
634        if(arg=="maxmw")           this->maxMW = readIval(ss);
635        if(arg=="minmw")           this->minMW = readIval(ss);
636        if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
637
638        if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
639        if(arg=="minpix")          this->minPix = readIval(ss);
640        if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
641        if(arg=="growthcut")       this->growthCut = readFval(ss);
642        if(arg=="growththreshold"){
643          this->growthThreshold = readFval(ss);
644          this->flagUserGrowthThreshold = true;
645        }
646
647        if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
648        if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
649        if(arg=="fdrnumcorchan")   this->FDRnumCorChan = readIval(ss);
650        if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
651        if(arg=="statsec")         this->statSec.setSection(readSval(ss));
652        if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss);
653        if(arg=="snrcut")          this->snrCut = readFval(ss);
654        if(arg=="threshold"){
655          this->threshold = readFval(ss);
656          this->flagUserThreshold = true;
657        }
658     
659        if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
660        if(arg=="smoothtype")      this->smoothType = readSval(ss);
661        if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
662        if(arg=="kernmaj")         this->kernMaj = readFval(ss);
663        if(arg=="kernmin")         this->kernMin = readFval(ss);
664        if(arg=="kernpa")          this->kernPA = readFval(ss);
665
666        if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
667        if(arg=="recondim")        this->reconDim = readIval(ss);
668        if(arg=="scalemin")        this->scaleMin = readIval(ss);
669        if(arg=="scalemax")        this->scaleMax = readIval(ss);
670        if(arg=="snrrecon")        this->snrRecon = readFval(ss);
671        if(arg=="filtercode"){
672          this->filterCode = readIval(ss);
673          this->reconFilter.define(this->filterCode);
674        }
675
676        if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
677        if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
678        if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
679        if(arg=="minchannels")     this->minChannels = readIval(ss);
680
681        if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
682        if(arg=="spectralunits")   this->spectralUnits = makelower(readSval(ss));
683        if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
684        if(arg=="sortingparam")    this->sortingParam = makelower(readSval(ss));
685        if(arg=="drawborders")     this->borders = readFlag(ss);
686        if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
687        if(arg=="verbose")         this->verbose = readFlag(ss);
688
689        // Dealing with deprecated parameters.
690        if(arg=="flagblankpix"){
691          this->flagTrim = readFlag(ss);
692          std::stringstream errmsg;
693          errmsg <<"The parameter flagBlankPix is deprecated. "
694                 <<"Please use the flagTrim parameter in future.\n"
695                 <<"Setting flagTrim = " << stringize(this->flagTrim) << ".\n";
696          duchampWarning("Reading parameters",errmsg.str());
697        }
698        if(arg=="blankpixvalue"){
699          std::stringstream errmsg;
700          errmsg <<"The parameter blankPixValue is deprecated.\n"
701                 <<"This value is only taken from the FITS header.\n";
702          duchampWarning("Reading parameters",errmsg.str());
703        }
704
705      }
706    }
707
708    this->checkPars();
709
710    return SUCCESS;
711
712  }
713 
714  void Param::checkPars()
715  {
716
717    // If we have usePrevious=false, set the objectlist to blank so that we use all of them
718    if(!this->usePrevious) this->objectList = "";
719
720    // If pgplot was not included in the compilation, need to set flagXOutput to false
721    if(!USE_PGPLOT) this->flagXOutput = false;
722
723    // Correcting bad precision values -- if negative, set to 0
724    if(this->precFlux<0) this->precFlux = 0;
725    if(this->precVel<0)  this->precVel = 0;
726    if(this->precSNR<0)  this->precSNR = 0;
727
728    // The wavelet reconstruction takes precendence over the smoothing.
729    if(this->flagATrous) this->flagSmooth = false;
730
731    if(this->flagUserThreshold){
732
733      // If we specify a manual threshold, need to also specify a manual growth threshold
734      // If we haven't done so, turn growing off
735      if(this->flagGrowth && !this->flagUserGrowthThreshold){
736        std::stringstream errmsg;
737        errmsg << "You have specified a manual search threshold, but not a manual growth threshold.\n"
738               << "You need to do so using the \"growthThreshold\" parameter.\n"
739               << "The growth function is being turned off.\n";
740        duchampWarning("Reading parameters",errmsg.str());
741        this->flagGrowth = false;
742      }
743
744      // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested.
745      if(this->flagFDR){
746        std::stringstream errmsg;
747        errmsg << "You have specified a manual search threshold, so we don't need to use the FDR method.\n"
748               << "Setting \"flagFDR=false\".\n";
749        duchampWarning("Reading parameters",errmsg.str());
750        this->flagFDR = false;
751      }
752
753    }   
754
755    // Make sure the growth level is less than the detection level. Else turn off growing.
756    if(this->flagGrowth){
757      std::stringstream errmsg;
758      bool doWarn = false;
759      if(this->flagUserThreshold &&
760         ( (this->threshold < this->growthThreshold)
761           || (this->snrCut < this->growthCut) ) ){
762        errmsg << "Your \"growthThreshold\" parameter is larger than your \"threshold\".\n"
763               << "The growth function is being turned off.\n";
764        doWarn = true;
765      }
766     
767      if(!this->flagUserThreshold &&
768         (this->snrCut < this->growthCut)) {
769        errmsg << "Your \"growthCut\" parameter is larger than your \"snrCut\".\n"
770               << "The growth function is being turned off.\n";
771        doWarn = true;
772      }
773
774      if(doWarn) duchampWarning("Reading parameters",errmsg.str());
775
776    }
777
778    // Make sure the annnotationType is an acceptable option -- default is "borders"
779    if((this->annotationType != "borders") && (this->annotationType!="circles")){
780      std::stringstream errmsg;
781      errmsg << "The requested value of the parameter annotationType, \""
782             << this->annotationType << "\", is invalid.\n"
783             << "Changing to \"borders\".\n";
784      duchampWarning("Reading parameters",errmsg.str());
785      this->annotationType = "borders";
786    }
787     
788    // Make sure smoothType is an acceptable type -- default is "spectral"
789    if((this->smoothType!="spectral")&&
790       (this->smoothType!="spatial")){
791      std::stringstream errmsg;
792      errmsg << "The requested value of the parameter smoothType, \""
793             << this->smoothType << "\", is invalid.\n"
794             << "Changing to \"spectral\".\n";
795      duchampWarning("Reading parameters",errmsg.str());
796      this->smoothType = "spectral";
797    }
798    // If kernMin has not been given, or is negative, make it equal to kernMaj
799    if(this->kernMin < 0) this->kernMin = this->kernMaj;
800
801    // Make sure spectralMethod is an acceptable type -- default is "peak"
802    if((this->spectralMethod!="peak")&&
803       (this->spectralMethod!="sum")){
804      std::stringstream errmsg;
805      errmsg << "The requested value of the parameter spectralMethod, \""
806             << this->spectralMethod << "\", is invalid.\n"
807             << "Changing to \"peak\".\n";
808      duchampWarning("Reading parameters",errmsg.str());
809      this->spectralMethod = "peak";
810    }
811
812    // Make sure pixelCentre is an acceptable type -- default is "peak"
813    if((this->pixelCentre!="centroid")&&
814       (this->pixelCentre!="average") &&
815       (this->pixelCentre!="peak")       ){
816      std::stringstream errmsg;
817      errmsg << "The requested value of the parameter pixelCentre, \""
818             << this->pixelCentre << "\", is invalid.\n"
819             << "Changing to \"centroid\".\n";
820      duchampWarning("Reading parameters",errmsg.str());
821      this->pixelCentre = "centroid";
822    }
823
824    // Make sure sortingParam is an acceptable type -- default is "vel"
825    bool OK = false;
826    for(int i=0;i<numSortingParamOptions;i++)
827      OK = OK || this->sortingParam==sortingParamOptions[i];
828    if(!OK){
829      std::stringstream errmsg;
830      errmsg << "The requested value of the parameter sortingParam, \""
831             << this->sortingParam << "\", is invalid.\n"
832             << "Changing to \"vel\".\n";
833      duchampWarning("Reading parameters",errmsg.str());
834      this->sortingParam = "vel";
835    }
836     
837  }
838
839
840  std::ostream& operator<< ( std::ostream& theStream, Param& par)
841  {
842    /// Print out the parameter set in a formatted, easy to read style.
843    /// Lists the parameters, a description of them, and their value.
844
845    // Only show the [beamSize] bit if we are using the parameter
846    // otherwise we have read it from the FITS header.
847    std::string beamParam = "";
848    if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
849
850    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
851    //   theStream.setf(std::ios::boolalpha);
852    theStream.setf(std::ios::left);
853    theStream  <<"\n---- Parameters ----"<<std::endl;
854    theStream  << std::setfill('.');
855    const int widthText = 38;
856    const int widthPar  = 18;
857    if(par.getFlagSubsection())
858      theStream<<std::setw(widthText)<<"Image to be analysed"                 
859               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
860               <<"  =  " <<resetiosflags(std::ios::right)
861               <<(par.getImageFile()+par.getSubsection()) <<std::endl;
862    else
863      theStream<<std::setw(widthText)<<"Image to be analysed"                 
864               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
865               <<"  =  " <<resetiosflags(std::ios::right)
866               <<par.getImageFile()      <<std::endl;
867    if(par.getFlagReconExists() && par.getFlagATrous()){
868      theStream<<std::setw(widthText)<<"Reconstructed array exists?"         
869               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
870               <<"  =  " <<resetiosflags(std::ios::right)
871               <<stringize(par.getFlagReconExists())<<std::endl;
872      theStream<<std::setw(widthText)<<"FITS file containing reconstruction" 
873               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
874               <<"  =  " <<resetiosflags(std::ios::right)
875               <<par.getReconFile()      <<std::endl;
876    }
877    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
878      theStream<<std::setw(widthText)<<"Smoothed array exists?"         
879               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
880               <<"  =  " <<resetiosflags(std::ios::right)
881               <<stringize(par.getFlagSmoothExists())<<std::endl;
882      theStream<<std::setw(widthText)<<"FITS file containing smoothed array" 
883               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
884               <<"  =  " <<resetiosflags(std::ios::right)
885               <<par.getSmoothFile()      <<std::endl;
886    }
887    theStream  <<std::setw(widthText)<<"Intermediate Logfile"
888               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
889               <<"  =  " <<resetiosflags(std::ios::right)
890               <<par.getLogFile()        <<std::endl;
891    theStream  <<std::setw(widthText)<<"Final Results file"                   
892               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
893               <<"  =  " <<resetiosflags(std::ios::right)
894               <<par.getOutFile()        <<std::endl;
895    if(par.getFlagSeparateHeader())
896      theStream <<std::setw(widthText)<<"Header for results file"
897                <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[headerFile]"
898                <<"  =  " <<resetiosflags(std::ios::right)
899                <<par.getHeaderFile()        <<std::endl;
900    theStream  <<std::setw(widthText)<<"Spectrum file"                       
901               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
902               <<"  =  " <<resetiosflags(std::ios::right)
903               <<par.getSpectraFile()    <<std::endl;
904    if(par.getFlagTextSpectra()){
905      theStream<<std::setw(widthText)<<"Text file with ascii spectral data"                         
906               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraTextFile]"
907               <<"  =  " <<resetiosflags(std::ios::right)
908               <<par.getSpectraTextFile()<<std::endl;
909    }
910    if(par.getFlagVOT()){
911      theStream<<std::setw(widthText)<<"VOTable file"                         
912               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
913               <<"  =  " <<resetiosflags(std::ios::right)
914               <<par.getVOTFile()        <<std::endl;
915    }
916    if(par.getFlagKarma()){
917      theStream<<std::setw(widthText)<<"Karma annotation file"               
918               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
919               <<"  =  " <<resetiosflags(std::ios::right)
920               <<par.getKarmaFile()      <<std::endl;
921    }
922    if(par.getFlagMaps()){
923      theStream<<std::setw(widthText)<<"0th Moment Map"                       
924               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
925               <<"  =  " <<resetiosflags(std::ios::right)
926               <<par.getMomentMap()      <<std::endl;
927      theStream<<std::setw(widthText)<<"Detection Map"                       
928               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
929               <<"  =  " <<resetiosflags(std::ios::right)
930               <<par.getDetectionMap()   <<std::endl;
931    }
932    theStream  <<std::setw(widthText)<<"Display a map in a pgplot xwindow?"
933               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
934               <<"  =  " <<resetiosflags(std::ios::right)
935               <<stringize(par.getFlagXOutput())     <<std::endl;
936    if(par.getFlagATrous()){                           
937      theStream<<std::setw(widthText)<<"Saving reconstructed cube?"           
938               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputRecon]"
939               <<"  =  " <<resetiosflags(std::ios::right)
940               <<stringize(par.getFlagOutputRecon());
941      if(par.getFlagOutputRecon()) theStream << " --> " << par.outputReconFile();
942      theStream<<std::endl;
943      theStream<<std::setw(widthText)<<"Saving residuals from reconstruction?"
944               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputResid]"
945               <<"  =  " <<resetiosflags(std::ios::right)
946               <<stringize(par.getFlagOutputResid());
947      if(par.getFlagOutputResid()) theStream << " --> " << par.outputResidFile();
948      theStream<<std::endl;
949    }                                                 
950    if(par.getFlagSmooth()){                           
951      theStream<<std::setw(widthText)<<"Saving smoothed cube?"           
952               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputSmooth]"
953               <<"  =  " <<resetiosflags(std::ios::right)
954               <<stringize(par.getFlagOutputSmooth());
955      if(par.getFlagOutputSmooth()) theStream << " --> " << par.outputSmoothFile();
956      theStream<<std::endl;
957    }                                                 
958    theStream<<std::setw(widthText)<<"Saving mask cube?"           
959             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputMask]"
960             <<"  =  " <<resetiosflags(std::ios::right)
961             <<stringize(par.getFlagOutputMask());
962    if(par.getFlagOutputMask()) theStream << " --> " << par.outputMaskFile();
963    theStream<<std::endl;
964    theStream  <<"------"<<std::endl;
965    if(par.getFlagBlankPix()){
966      theStream<<std::setw(widthText)<<"Blank Pixel Value"                   
967               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< ""
968               <<"  =  " <<resetiosflags(std::ios::right)
969               <<par.getBlankPixVal()    <<std::endl;
970    }
971    theStream  <<std::setw(widthText)<<"Trimming Blank Pixels?"                 
972               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagTrim]"
973               <<"  =  " <<resetiosflags(std::ios::right)
974               <<stringize(par.getFlagTrim())   <<std::endl;
975    theStream  <<std::setw(widthText)<<"Searching for Negative features?"     
976               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
977               <<"  =  " <<resetiosflags(std::ios::right)
978               <<stringize(par.getFlagNegative())   <<std::endl;
979    theStream  <<std::setw(widthText)<<"Removing Milky Way channels?"         
980               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
981               <<"  =  " <<resetiosflags(std::ios::right)
982               <<stringize(par.getFlagMW())         <<std::endl;
983    if(par.getFlagMW()){
984      theStream<<std::setw(widthText)<<"Milky Way Channels"                   
985               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
986               <<"  =  " <<resetiosflags(std::ios::right)
987               <<par.getMinMW()
988               <<"-" <<par.getMaxMW()          <<std::endl;
989    }
990    theStream  <<std::setw(widthText)<<"Beam Size (pixels)"                   
991               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
992               <<"  =  " <<resetiosflags(std::ios::right)
993               <<par.getBeamSize()       <<std::endl;
994    theStream  <<std::setw(widthText)<<"Removing baselines before search?"   
995               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
996               <<"  =  " <<resetiosflags(std::ios::right)
997               <<stringize(par.getFlagBaseline())   <<std::endl;
998    theStream  <<std::setw(widthText)<<"Smoothing data prior to searching?"       
999               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
1000               <<"  =  " <<resetiosflags(std::ios::right)
1001               <<stringize(par.getFlagSmooth())     <<std::endl;
1002    if(par.getFlagSmooth()){           
1003      theStream<<std::setw(widthText)<<"Type of smoothing"     
1004               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothType]"
1005               <<"  =  " <<resetiosflags(std::ios::right)
1006               <<par.getSmoothType()       <<std::endl;
1007      if(par.getSmoothType()=="spectral")
1008        theStream<<std::setw(widthText)<<"Width of hanning filter"     
1009                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
1010                 <<"  =  " <<resetiosflags(std::ios::right)
1011                 <<par.getHanningWidth()       <<std::endl;
1012      else{
1013        theStream<<std::setw(widthText)<<"Gaussian kernel semi-major axis [pix]"
1014                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMaj]"
1015                 <<"  =  " <<resetiosflags(std::ios::right)
1016                 <<par.getKernMaj() << std::endl;
1017        theStream<<std::setw(widthText)<<"Gaussian kernel semi-minor axis [pix]"
1018                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMin]"
1019                 <<"  =  " <<resetiosflags(std::ios::right)
1020                 <<par.getKernMin() << std::endl;
1021        theStream<<std::setw(widthText)<<"Gaussian kernel position angle [deg]"
1022                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernPA]"
1023                 <<"  =  " <<resetiosflags(std::ios::right)
1024                 <<par.getKernPA() << std::endl;
1025      }
1026    }
1027    theStream  <<std::setw(widthText)<<"Using A Trous reconstruction?"       
1028               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
1029               <<"  =  " <<resetiosflags(std::ios::right)
1030               <<stringize(par.getFlagATrous())     <<std::endl;
1031    if(par.getFlagATrous()){                           
1032      theStream<<std::setw(widthText)<<"Number of dimensions in reconstruction"     
1033               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
1034               <<"  =  " <<resetiosflags(std::ios::right)
1035               <<par.getReconDim()       <<std::endl;
1036      if(par.getMaxScale()>0){
1037        theStream<<std::setw(widthText-1)<<"Scales used in reconstruction"     
1038                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin-scaleMax]"
1039                 <<"  =  " <<resetiosflags(std::ios::right)
1040                 <<par.getMinScale() << "-" << par.getMaxScale()   <<std::endl;
1041      }
1042      else{
1043        theStream<<std::setw(widthText)<<"Minimum scale in reconstruction"     
1044                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
1045                 <<"  =  " <<resetiosflags(std::ios::right)
1046                 <<par.getMinScale()      <<std::endl;
1047      }
1048      theStream<<std::setw(widthText)<<"SNR Threshold within reconstruction" 
1049               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
1050               <<"  =  " <<resetiosflags(std::ios::right)
1051               <<par.getAtrousCut()      <<std::endl;
1052      theStream<<std::setw(widthText)<<"Filter being used for reconstruction"
1053               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
1054               <<"  =  " <<resetiosflags(std::ios::right)
1055               <<par.getFilterCode()
1056               << " (" << par.getFilterName()  << ")" <<std::endl;
1057    }                                                 
1058    theStream  <<std::setw(widthText)<<"Using Robust statistics?"                 
1059               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagRobustStats]"
1060               <<"  =  " <<resetiosflags(std::ios::right)
1061               <<stringize(par.getFlagRobustStats()) <<std::endl;
1062    if(par.getFlagStatSec()){
1063      theStream<<std::setw(widthText)<<"Section used by statistics calculation"
1064               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[statSec]"
1065               <<"  =  " <<resetiosflags(std::ios::right)
1066               <<par.statSec.getSection()          <<std::endl;
1067    }
1068    theStream  <<std::setw(widthText)<<"Using FDR analysis?"                 
1069               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
1070               <<"  =  " <<resetiosflags(std::ios::right)
1071               <<stringize(par.getFlagFDR())        <<std::endl;
1072    if(par.getFlagFDR()){                                     
1073      theStream<<std::setw(widthText)<<"Alpha value for FDR analysis"         
1074               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
1075               <<"  =  " <<resetiosflags(std::ios::right)
1076               <<par.getAlpha()          <<std::endl;
1077      theStream<<std::setw(widthText)<<"Number of correlated channels for FDR"         
1078               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[FDRnumCorChan]"
1079               <<"  =  " <<resetiosflags(std::ios::right)
1080               <<par.getFDRnumCorChan()          <<std::endl;
1081    }                                                 
1082    else {
1083      if(par.getFlagUserThreshold()){
1084        theStream<<std::setw(widthText)<<"Detection Threshold"                       
1085                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
1086                 <<"  =  " <<resetiosflags(std::ios::right)
1087                 <<par.getThreshold()            <<std::endl;
1088      }
1089      else{
1090        theStream<<std::setw(widthText)<<"SNR Threshold (in sigma)"
1091                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
1092                 <<"  =  " <<resetiosflags(std::ios::right)
1093                 <<par.getCut()            <<std::endl;
1094      }
1095    }
1096    theStream  <<std::setw(widthText)<<"Minimum # Pixels in a detection"     
1097               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
1098               <<"  =  " <<resetiosflags(std::ios::right)
1099               <<par.getMinPix()         <<std::endl;
1100    theStream  <<std::setw(widthText)<<"Minimum # Channels in a detection"   
1101               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
1102               <<"  =  " <<resetiosflags(std::ios::right)
1103               <<par.getMinChannels()    <<std::endl;
1104    theStream  <<std::setw(widthText)<<"Growing objects after detection?"     
1105               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
1106               <<"  =  " <<resetiosflags(std::ios::right)
1107               <<stringize(par.getFlagGrowth())     <<std::endl;
1108    if(par.getFlagGrowth()) {                         
1109      if(par.getFlagUserGrowthThreshold()){
1110        theStream<<std::setw(widthText)<<"Threshold for growth"                       
1111                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthThreshold]"
1112                 <<"  =  " <<resetiosflags(std::ios::right)
1113                 <<par.getGrowthThreshold()        <<std::endl;
1114      }
1115      else{
1116        theStream<<std::setw(widthText)<<"SNR Threshold for growth"             
1117                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
1118                 <<"  =  " <<resetiosflags(std::ios::right)
1119                 <<par.getGrowthCut()      <<std::endl;
1120      }
1121    }
1122    theStream  <<std::setw(widthText)<<"Using Adjacent-pixel criterion?"     
1123               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
1124               <<"  =  " <<resetiosflags(std::ios::right)
1125               <<stringize(par.getFlagAdjacent())   <<std::endl;
1126    if(!par.getFlagAdjacent()){
1127      theStream<<std::setw(widthText)<<"Max. spatial separation for merging" 
1128               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
1129               <<"  =  " <<resetiosflags(std::ios::right)
1130               <<par.getThreshS()        <<std::endl;
1131    }
1132    theStream  <<std::setw(widthText)<<"Max. velocity separation for merging"
1133               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
1134               <<"  =  " <<resetiosflags(std::ios::right)
1135               <<par.getThreshV()        <<std::endl;
1136    theStream  <<std::setw(widthText)<<"Method of spectral plotting"         
1137               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
1138               <<"  =  " <<resetiosflags(std::ios::right)
1139               <<par.getSpectralMethod() <<std::endl;
1140    theStream  <<std::setw(widthText)<<"Type of object centre used in results"
1141               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[pixelCentre]"
1142               <<"  =  " <<resetiosflags(std::ios::right)
1143               <<par.getPixelCentre() <<std::endl;
1144    theStream  <<"--------------------\n\n";
1145    theStream  << std::setfill(' ');
1146    theStream.unsetf(std::ios::left);
1147    //  theStream.unsetf(std::ios::boolalpha);
1148    return theStream;
1149  }
1150
1151
1152  void Param::copyHeaderInfo(FitsHeader &head)
1153  {
1154    ///  A function to copy across relevant header keywords from the
1155    ///  FitsHeader class to the Param class, as they are needed by
1156    ///  functions in the Param class.
1157    ///  The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
1158
1159    this->blankKeyword  = head.getBlankKeyword();
1160    this->bscaleKeyword = head.getBscaleKeyword();
1161    this->bzeroKeyword  = head.getBzeroKeyword();
1162    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
1163      this->bzeroKeyword;
1164
1165    this->numPixBeam    = head.getBeamSize();
1166  }
1167
1168  std::string Param::outputMaskFile()
1169  {
1170    ///  This function produces the required filename in which to save
1171    ///  the mask image, indicating which pixels have been detected as
1172    ///  part of an object. If the input image is image.fits, then the
1173    ///  output will be image.MASK.fits.
1174
1175    if(this->fileOutputMask==""){
1176      std::string inputName = this->imageFile;
1177      std::stringstream ss;
1178      ss << inputName.substr(0,inputName.size()-5); 
1179      // remove the ".fits" on the end.
1180      ss << ".MASK.fits";
1181      return ss.str();
1182    }
1183    else return this->fileOutputMask;
1184  }
1185
1186  std::string Param::outputSmoothFile()
1187  {
1188    ///  This function produces the required filename in which to save
1189    ///   the smoothed array. If the input image is image.fits, then
1190    ///   the output will be:
1191    ///    <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
1192    ///             width of the Hanning filter was 3 pixels.
1193    ///        <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
1194    ///             kernMaj=3, kernMin=2 and kernPA=20 degrees.
1195    ///    </ul>
1196
1197    if(this->fileOutputSmooth==""){
1198      std::string inputName = this->imageFile;
1199      std::stringstream ss;
1200      ss << inputName.substr(0,inputName.size()-5); 
1201      // remove the ".fits" on the end.
1202      if(this->flagSubsection) ss<<".sub";
1203      if(this->smoothType=="spectral")
1204        ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
1205      else if(this->smoothType=="spatial")
1206        ss << ".SMOOTH-2D-"
1207           << this->kernMaj << "-"
1208           << this->kernMin << "-"
1209           << this->kernPA  << ".fits";
1210      return ss.str();
1211    }
1212    else return this->fileOutputSmooth;
1213  }
1214
1215  std::string Param::outputReconFile()
1216  {
1217    /// This function produces the required filename in which to save
1218    ///  the reconstructed array. If the input image is image.fits, then
1219    ///  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
1220    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
1221
1222    if(this->fileOutputRecon==""){
1223      std::string inputName = this->imageFile;
1224      std::stringstream ss;
1225      // First we remove the ".fits" from the end of the filename.
1226      ss << inputName.substr(0,inputName.size()-5); 
1227      if(this->flagSubsection) ss<<".sub";
1228      ss << ".RECON-" << this->reconDim
1229         << "-"       << this->filterCode
1230         << "-"       << this->snrRecon
1231         << "-"       << this->scaleMin
1232         << ".fits";
1233      return ss.str();
1234    }
1235    else return this->fileOutputRecon;
1236  }
1237
1238  std::string Param::outputResidFile()
1239  {
1240    /// This function produces the required filename in which to save
1241    ///  the reconstructed array. If the input image is image.fits, then
1242    ///  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
1243    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
1244
1245    if(this->fileOutputResid==""){
1246      std::string inputName = this->imageFile;
1247      std::stringstream ss;
1248      // First we remove the ".fits" from the end of the filename.
1249      ss << inputName.substr(0,inputName.size()-5);
1250      if(this->flagSubsection) ss<<".sub";
1251      ss << ".RESID-" << this->reconDim
1252         << "-"       << this->filterCode
1253         << "-"       << this->snrRecon
1254         << "-"       << this->scaleMin
1255         << ".fits";
1256      return ss.str();
1257    }
1258    else return this->fileOutputResid;
1259  }
1260
1261}
Note: See TracBrowser for help on using the repository browser.