source: branches/pixelmap-refactor-branch/src/param.cc @ 1441

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

Adding a new parameter to allow user-specification of the number of correlated spectral channels, following ticket #41. Have also updated all the documentation to go with it.

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