source: tags/release-1.1.8/src/param.cc @ 1391

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

The three bugfixes for changesets [586],[587],[588].

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->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(unsigned int 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(unsigned int i=0;i<objectChoices.size();i++) choices[objectChoices[i]-1] = true;
480    return choices;
481  }
482
483  std::vector<bool> Param::getObjectChoices(int numObjects)
484  {
485    ///  Returns a list of bool values, indicating whether a given
486    ///  object was requested or not. The size of the vector is given
487    ///  by the numObjects parameter. So, if objectList="2,3,5-8", then
488    ///  the returned vector from a getObjectChoices(10) call will be
489    ///  [0,1,1,0,1,1,1,1,0,0].
490    ///  \param numObjects How many objects there are in total.
491    ///  \return Vector of bool values.
492
493    if(this->objectList==""){
494      std::vector<bool> choices(numObjects,true);
495      return choices;
496    }
497    else{
498      std::vector<int> objectChoices = this->getObjectRequest();
499      std::vector<bool> choices(numObjects,false);
500      for(unsigned int i=0;i<objectChoices.size();i++)
501        if(objectChoices[i]<=numObjects) choices[objectChoices[i]-1] = true;
502      return choices;
503    }
504  }
505
506  /****************************************************************/
507  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
508  /// / Other Functions using the  Parameter class:
509  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
510
511  std::string makelower( std::string s )
512  {
513    // "borrowed" from Matt Howlett's 'fred'
514    std::string out = "";
515    for( unsigned int i=0; i<s.size(); ++i ) {
516      out += tolower(s[i]);
517    }
518    return out;
519  }
520
521  inline std::string stringize(bool b)
522  {
523   /// Convert a bool variable to the textual equivalent.
524   /// \return A std::string with the english equivalent of the bool.
525
526    std::string output;
527    if(b) output="true";
528    else output="false";
529    return output;
530  }
531
532  inline bool boolify( std::string s )
533  {
534    ///  Convert a std::string to a bool variable:
535    ///  "1" and "true" get converted to true;
536    ///  "0" and "false" (and anything else) get converted to false.
537    /// \return The bool equivalent of the string.
538
539    if((s=="1") || (makelower(s)=="true")) return true;
540    else if((s=="0") || (makelower(s)=="false")) return false;
541    else return false;
542  }
543
544  inline std::string readSval(std::stringstream& ss)
545  {
546    std::string val; ss >> val; return val;
547  }
548
549  inline bool readFlag(std::stringstream& ss)
550  {
551    std::string val; ss >> val; return boolify(val);
552  }
553
554  inline float readFval(std::stringstream& ss)
555  {
556    float val; ss >> val; return val;
557  }
558
559  inline int readIval(std::stringstream& ss)
560  {
561    int val; ss >> val; return val;
562  }
563
564  int Param::readParams(std::string paramfile)
565  {
566    /// The parameters are read in from a disk file, on the assumption that each
567    ///  line of the file has the format "parameter value" (eg. alphafdr 0.1)
568    ///
569    /// The case of the parameter name does not matter, nor does the
570    /// formatting of the spaces (it can be any amount of whitespace or
571    /// tabs).
572    ///
573    /// \param paramfile A std::string containing the parameter filename.
574    ///
575    /// \return FAILURE if the parameter file does not exist. SUCCESS if
576    /// it is able to read it.
577
578    std::ifstream fin(paramfile.c_str());
579    if(!fin.is_open()) return FAILURE;
580    std::string line;
581    while( !std::getline(fin,line,'\n').eof()){
582
583      if(line[0]!='#'){
584        std::stringstream ss;
585        ss.str(line);
586        std::string arg;
587        ss >> arg;
588        arg = makelower(arg);
589        if(arg=="imagefile")       this->imageFile = readSval(ss);
590        if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
591        if(arg=="subsection")      this->pixelSec.setSection(readSval(ss));
592        if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
593        if(arg=="reconfile")       this->reconFile = readSval(ss);
594        if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
595        if(arg=="smoothfile")      this->smoothFile = readSval(ss);
596        if(arg=="beamsize")        this->numPixBeam = readFval(ss);
597        if(arg=="useprevious")     this->usePrevious = readFlag(ss);
598        if(arg=="objectlist")      this->objectList = readSval(ss);
599
600        if(arg=="flaglog")         this->flagLog = readFlag(ss);
601        if(arg=="logfile")         this->logFile = readSval(ss);
602        if(arg=="outfile")         this->outFile = readSval(ss);
603        if(arg=="flagseparateheader") this->flagSeparateHeader = readFlag(ss);
604        if(arg=="headerfile")      this->headerFile = readSval(ss);
605        if(arg=="spectrafile")     this->spectraFile = readSval(ss);
606        if(arg=="flagtextspectra") this->flagTextSpectra = readFlag(ss);
607        if(arg=="spectratextfile") this->spectraTextFile = readSval(ss);
608        if(arg=="flagoutputmask")  this->flagOutputMask = readFlag(ss);
609        if(arg=="fileoutputmask")  this->fileOutputMask = readSval(ss);
610        if(arg=="flagmaskwithobjectnum") this->flagMaskWithObjectNum = readFlag(ss);
611        if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
612        if(arg=="fileoutputsmooth")this->fileOutputSmooth = readSval(ss);
613        if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
614        if(arg=="fileoutputrecon") this->fileOutputRecon = readSval(ss);
615        if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
616        if(arg=="fileoutputresid") this->fileOutputResid = readSval(ss);
617        if(arg=="flagvot")         this->flagVOT = readFlag(ss);
618        if(arg=="votfile")         this->votFile = readSval(ss);
619        if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
620        if(arg=="karmafile")       this->karmaFile = readSval(ss);
621        if(arg=="annotationtype")  this->annotationType = readSval(ss);
622        if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
623        if(arg=="detectionmap")    this->detectionMap = readSval(ss);
624        if(arg=="momentmap")       this->momentMap = readSval(ss);
625        if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
626        if(arg=="newfluxunits")    this->newFluxUnits = readSval(ss);
627        if(arg=="precflux")        this->precFlux = readIval(ss);
628        if(arg=="precvel")         this->precVel = readIval(ss);
629        if(arg=="precsnr")         this->precSNR = readIval(ss);
630
631        if(arg=="flagtrim")        this->flagTrim = readFlag(ss);
632        if(arg=="flagmw")          this->flagMW = readFlag(ss);
633        if(arg=="maxmw")           this->maxMW = readIval(ss);
634        if(arg=="minmw")           this->minMW = readIval(ss);
635        if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
636
637        if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
638        if(arg=="minpix")          this->minPix = readIval(ss);
639        if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
640        if(arg=="growthcut")       this->growthCut = readFval(ss);
641        if(arg=="growththreshold"){
642          this->growthThreshold = readFval(ss);
643          this->flagUserGrowthThreshold = true;
644        }
645
646        if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
647        if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
648        if(arg=="fdrnumcorchan")   this->FDRnumCorChan = readIval(ss);
649        if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
650        if(arg=="statsec")         this->statSec.setSection(readSval(ss));
651        if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss);
652        if(arg=="snrcut")          this->snrCut = readFval(ss);
653        if(arg=="threshold"){
654          this->threshold = readFval(ss);
655          this->flagUserThreshold = true;
656        }
657     
658        if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
659        if(arg=="smoothtype")      this->smoothType = readSval(ss);
660        if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
661        if(arg=="kernmaj")         this->kernMaj = readFval(ss);
662        if(arg=="kernmin")         this->kernMin = readFval(ss);
663        if(arg=="kernpa")          this->kernPA = readFval(ss);
664
665        if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
666        if(arg=="recondim")        this->reconDim = readIval(ss);
667        if(arg=="scalemin")        this->scaleMin = readIval(ss);
668        if(arg=="scalemax")        this->scaleMax = readIval(ss);
669        if(arg=="snrrecon")        this->snrRecon = readFval(ss);
670        if(arg=="filtercode"){
671          this->filterCode = readIval(ss);
672          this->reconFilter.define(this->filterCode);
673        }
674
675        if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
676        if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
677        if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
678        if(arg=="minchannels")     this->minChannels = readIval(ss);
679
680        if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
681        if(arg=="spectralunits")   this->spectralUnits = makelower(readSval(ss));
682        if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
683        if(arg=="sortingparam")    this->sortingParam = makelower(readSval(ss));
684        if(arg=="drawborders")     this->borders = readFlag(ss);
685        if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
686        if(arg=="verbose")         this->verbose = readFlag(ss);
687
688        // Dealing with deprecated parameters.
689        if(arg=="flagblankpix"){
690          this->flagTrim = readFlag(ss);
691          std::stringstream errmsg;
692          errmsg <<"The parameter flagBlankPix is deprecated. "
693                 <<"Please use the flagTrim parameter in future.\n"
694                 <<"Setting flagTrim = " << stringize(this->flagTrim) << ".\n";
695          duchampWarning("Reading parameters",errmsg.str());
696        }
697        if(arg=="blankpixvalue"){
698          std::stringstream errmsg;
699          errmsg <<"The parameter blankPixValue is deprecated.\n"
700                 <<"This value is only taken from the FITS header.\n";
701          duchampWarning("Reading parameters",errmsg.str());
702        }
703
704      }
705    }
706
707    this->checkPars();
708
709    return SUCCESS;
710
711  }
712 
713  void Param::checkPars()
714  {
715
716    // If we have usePrevious=false, set the objectlist to blank so that we use all of them
717    if(!this->usePrevious) this->objectList = "";
718
719    // If pgplot was not included in the compilation, need to set flagXOutput to false
720    if(!USE_PGPLOT) this->flagXOutput = false;
721
722    // Correcting bad precision values -- if negative, set to 0
723    if(this->precFlux<0) this->precFlux = 0;
724    if(this->precVel<0)  this->precVel = 0;
725    if(this->precSNR<0)  this->precSNR = 0;
726
727    // The wavelet reconstruction takes precendence over the smoothing.
728    if(this->flagATrous) this->flagSmooth = false;
729
730    if(this->flagUserThreshold){
731
732      // If we specify a manual threshold, need to also specify a manual growth threshold
733      // If we haven't done so, turn growing off
734      if(this->flagGrowth && !this->flagUserGrowthThreshold){
735        std::stringstream errmsg;
736        errmsg << "You have specified a manual search threshold, but not a manual growth threshold.\n"
737               << "You need to do so using the \"growthThreshold\" parameter.\n"
738               << "The growth function is being turned off.\n";
739        duchampWarning("Reading parameters",errmsg.str());
740        this->flagGrowth = false;
741      }
742
743      // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested.
744      if(this->flagFDR){
745        std::stringstream errmsg;
746        errmsg << "You have specified a manual search threshold, so we don't need to use the FDR method.\n"
747               << "Setting \"flagFDR=false\".\n";
748        duchampWarning("Reading parameters",errmsg.str());
749        this->flagFDR = false;
750      }
751
752    }   
753
754    // Make sure the annnotationType is an acceptable option -- default is "borders"
755    if((this->annotationType != "borders") && (this->annotationType!="circles")){
756      std::stringstream errmsg;
757      errmsg << "The requested value of the parameter annotationType, \""
758             << this->annotationType << "\", is invalid.\n"
759             << "Changing to \"borders\".\n";
760      duchampWarning("Reading parameters",errmsg.str());
761      this->annotationType = "borders";
762    }
763     
764    // Make sure smoothType is an acceptable type -- default is "spectral"
765    if((this->smoothType!="spectral")&&
766       (this->smoothType!="spatial")){
767      std::stringstream errmsg;
768      errmsg << "The requested value of the parameter smoothType, \""
769             << this->smoothType << "\", is invalid.\n"
770             << "Changing to \"spectral\".\n";
771      duchampWarning("Reading parameters",errmsg.str());
772      this->smoothType = "spectral";
773    }
774    // If kernMin has not been given, or is negative, make it equal to kernMaj
775    if(this->kernMin < 0) this->kernMin = this->kernMaj;
776
777    // Make sure spectralMethod is an acceptable type -- default is "peak"
778    if((this->spectralMethod!="peak")&&
779       (this->spectralMethod!="sum")){
780      std::stringstream errmsg;
781      errmsg << "The requested value of the parameter spectralMethod, \""
782             << this->spectralMethod << "\", is invalid.\n"
783             << "Changing to \"peak\".\n";
784      duchampWarning("Reading parameters",errmsg.str());
785      this->spectralMethod = "peak";
786    }
787
788    // Make sure pixelCentre is an acceptable type -- default is "peak"
789    if((this->pixelCentre!="centroid")&&
790       (this->pixelCentre!="average") &&
791       (this->pixelCentre!="peak")       ){
792      std::stringstream errmsg;
793      errmsg << "The requested value of the parameter pixelCentre, \""
794             << this->pixelCentre << "\", is invalid.\n"
795             << "Changing to \"centroid\".\n";
796      duchampWarning("Reading parameters",errmsg.str());
797      this->pixelCentre = "centroid";
798    }
799
800    // Make sure sortingParam is an acceptable type -- default is "vel"
801    bool OK = false;
802    for(int i=0;i<numSortingParamOptions;i++)
803      OK = OK || this->sortingParam==sortingParamOptions[i];
804    if(!OK){
805      std::stringstream errmsg;
806      errmsg << "The requested value of the parameter sortingParam, \""
807             << this->sortingParam << "\", is invalid.\n"
808             << "Changing to \"vel\".\n";
809      duchampWarning("Reading parameters",errmsg.str());
810      this->sortingParam = "vel";
811    }
812     
813  }
814
815
816  std::ostream& operator<< ( std::ostream& theStream, Param& par)
817  {
818    /// Print out the parameter set in a formatted, easy to read style.
819    /// Lists the parameters, a description of them, and their value.
820
821    // Only show the [beamSize] bit if we are using the parameter
822    // otherwise we have read it from the FITS header.
823    std::string beamParam = "";
824    if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
825
826    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
827    //   theStream.setf(std::ios::boolalpha);
828    theStream.setf(std::ios::left);
829    theStream  <<"\n---- Parameters ----"<<std::endl;
830    theStream  << std::setfill('.');
831    const int widthText = 38;
832    const int widthPar  = 18;
833    if(par.getFlagSubsection())
834      theStream<<std::setw(widthText)<<"Image to be analysed"                 
835               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
836               <<"  =  " <<resetiosflags(std::ios::right)
837               <<(par.getImageFile()+par.getSubsection()) <<std::endl;
838    else
839      theStream<<std::setw(widthText)<<"Image to be analysed"                 
840               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
841               <<"  =  " <<resetiosflags(std::ios::right)
842               <<par.getImageFile()      <<std::endl;
843    if(par.getFlagReconExists() && par.getFlagATrous()){
844      theStream<<std::setw(widthText)<<"Reconstructed array exists?"         
845               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
846               <<"  =  " <<resetiosflags(std::ios::right)
847               <<stringize(par.getFlagReconExists())<<std::endl;
848      theStream<<std::setw(widthText)<<"FITS file containing reconstruction" 
849               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
850               <<"  =  " <<resetiosflags(std::ios::right)
851               <<par.getReconFile()      <<std::endl;
852    }
853    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
854      theStream<<std::setw(widthText)<<"Smoothed array exists?"         
855               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
856               <<"  =  " <<resetiosflags(std::ios::right)
857               <<stringize(par.getFlagSmoothExists())<<std::endl;
858      theStream<<std::setw(widthText)<<"FITS file containing smoothed array" 
859               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
860               <<"  =  " <<resetiosflags(std::ios::right)
861               <<par.getSmoothFile()      <<std::endl;
862    }
863    theStream  <<std::setw(widthText)<<"Intermediate Logfile"
864               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
865               <<"  =  " <<resetiosflags(std::ios::right)
866               <<par.getLogFile()        <<std::endl;
867    theStream  <<std::setw(widthText)<<"Final Results file"                   
868               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
869               <<"  =  " <<resetiosflags(std::ios::right)
870               <<par.getOutFile()        <<std::endl;
871    if(par.getFlagSeparateHeader())
872      theStream <<std::setw(widthText)<<"Header for results file"
873                <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[headerFile]"
874                <<"  =  " <<resetiosflags(std::ios::right)
875                <<par.getHeaderFile()        <<std::endl;
876    theStream  <<std::setw(widthText)<<"Spectrum file"                       
877               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
878               <<"  =  " <<resetiosflags(std::ios::right)
879               <<par.getSpectraFile()    <<std::endl;
880    if(par.getFlagTextSpectra()){
881      theStream<<std::setw(widthText)<<"Text file with ascii spectral data"                         
882               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraTextFile]"
883               <<"  =  " <<resetiosflags(std::ios::right)
884               <<par.getSpectraTextFile()<<std::endl;
885    }
886    if(par.getFlagVOT()){
887      theStream<<std::setw(widthText)<<"VOTable file"                         
888               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
889               <<"  =  " <<resetiosflags(std::ios::right)
890               <<par.getVOTFile()        <<std::endl;
891    }
892    if(par.getFlagKarma()){
893      theStream<<std::setw(widthText)<<"Karma annotation file"               
894               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
895               <<"  =  " <<resetiosflags(std::ios::right)
896               <<par.getKarmaFile()      <<std::endl;
897    }
898    if(par.getFlagMaps()){
899      theStream<<std::setw(widthText)<<"0th Moment Map"                       
900               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
901               <<"  =  " <<resetiosflags(std::ios::right)
902               <<par.getMomentMap()      <<std::endl;
903      theStream<<std::setw(widthText)<<"Detection Map"                       
904               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
905               <<"  =  " <<resetiosflags(std::ios::right)
906               <<par.getDetectionMap()   <<std::endl;
907    }
908    theStream  <<std::setw(widthText)<<"Display a map in a pgplot xwindow?"
909               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
910               <<"  =  " <<resetiosflags(std::ios::right)
911               <<stringize(par.getFlagXOutput())     <<std::endl;
912    if(par.getFlagATrous()){                           
913      theStream<<std::setw(widthText)<<"Saving reconstructed cube?"           
914               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputRecon]"
915               <<"  =  " <<resetiosflags(std::ios::right)
916               <<stringize(par.getFlagOutputRecon());
917      if(par.getFlagOutputRecon()) theStream << " --> " << par.outputReconFile();
918      theStream<<std::endl;
919      theStream<<std::setw(widthText)<<"Saving residuals from reconstruction?"
920               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputResid]"
921               <<"  =  " <<resetiosflags(std::ios::right)
922               <<stringize(par.getFlagOutputResid());
923      if(par.getFlagOutputResid()) theStream << " --> " << par.outputResidFile();
924      theStream<<std::endl;
925    }                                                 
926    if(par.getFlagSmooth()){                           
927      theStream<<std::setw(widthText)<<"Saving smoothed cube?"           
928               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputSmooth]"
929               <<"  =  " <<resetiosflags(std::ios::right)
930               <<stringize(par.getFlagOutputSmooth());
931      if(par.getFlagOutputSmooth()) theStream << " --> " << par.outputSmoothFile();
932      theStream<<std::endl;
933    }                                                 
934    theStream<<std::setw(widthText)<<"Saving mask cube?"           
935             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputMask]"
936             <<"  =  " <<resetiosflags(std::ios::right)
937             <<stringize(par.getFlagOutputMask());
938    if(par.getFlagOutputMask()) theStream << " --> " << par.outputMaskFile();
939    theStream<<std::endl;
940    theStream  <<"------"<<std::endl;
941    if(par.getFlagBlankPix()){
942      theStream<<std::setw(widthText)<<"Blank Pixel Value"                   
943               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< ""
944               <<"  =  " <<resetiosflags(std::ios::right)
945               <<par.getBlankPixVal()    <<std::endl;
946    }
947    theStream  <<std::setw(widthText)<<"Trimming Blank Pixels?"                 
948               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagTrim]"
949               <<"  =  " <<resetiosflags(std::ios::right)
950               <<stringize(par.getFlagTrim())   <<std::endl;
951    theStream  <<std::setw(widthText)<<"Searching for Negative features?"     
952               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
953               <<"  =  " <<resetiosflags(std::ios::right)
954               <<stringize(par.getFlagNegative())   <<std::endl;
955    theStream  <<std::setw(widthText)<<"Removing Milky Way channels?"         
956               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
957               <<"  =  " <<resetiosflags(std::ios::right)
958               <<stringize(par.getFlagMW())         <<std::endl;
959    if(par.getFlagMW()){
960      theStream<<std::setw(widthText)<<"Milky Way Channels"                   
961               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
962               <<"  =  " <<resetiosflags(std::ios::right)
963               <<par.getMinMW()
964               <<"-" <<par.getMaxMW()          <<std::endl;
965    }
966    theStream  <<std::setw(widthText)<<"Beam Size (pixels)"                   
967               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
968               <<"  =  " <<resetiosflags(std::ios::right)
969               <<par.getBeamSize()       <<std::endl;
970    theStream  <<std::setw(widthText)<<"Removing baselines before search?"   
971               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
972               <<"  =  " <<resetiosflags(std::ios::right)
973               <<stringize(par.getFlagBaseline())   <<std::endl;
974    theStream  <<std::setw(widthText)<<"Smoothing data prior to searching?"       
975               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
976               <<"  =  " <<resetiosflags(std::ios::right)
977               <<stringize(par.getFlagSmooth())     <<std::endl;
978    if(par.getFlagSmooth()){           
979      theStream<<std::setw(widthText)<<"Type of smoothing"     
980               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothType]"
981               <<"  =  " <<resetiosflags(std::ios::right)
982               <<par.getSmoothType()       <<std::endl;
983      if(par.getSmoothType()=="spectral")
984        theStream<<std::setw(widthText)<<"Width of hanning filter"     
985                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
986                 <<"  =  " <<resetiosflags(std::ios::right)
987                 <<par.getHanningWidth()       <<std::endl;
988      else{
989        theStream<<std::setw(widthText)<<"Gaussian kernel semi-major axis [pix]"
990                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMaj]"
991                 <<"  =  " <<resetiosflags(std::ios::right)
992                 <<par.getKernMaj() << std::endl;
993        theStream<<std::setw(widthText)<<"Gaussian kernel semi-minor axis [pix]"
994                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMin]"
995                 <<"  =  " <<resetiosflags(std::ios::right)
996                 <<par.getKernMin() << std::endl;
997        theStream<<std::setw(widthText)<<"Gaussian kernel position angle [deg]"
998                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernPA]"
999                 <<"  =  " <<resetiosflags(std::ios::right)
1000                 <<par.getKernPA() << std::endl;
1001      }
1002    }
1003    theStream  <<std::setw(widthText)<<"Using A Trous reconstruction?"       
1004               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
1005               <<"  =  " <<resetiosflags(std::ios::right)
1006               <<stringize(par.getFlagATrous())     <<std::endl;
1007    if(par.getFlagATrous()){                           
1008      theStream<<std::setw(widthText)<<"Number of dimensions in reconstruction"     
1009               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
1010               <<"  =  " <<resetiosflags(std::ios::right)
1011               <<par.getReconDim()       <<std::endl;
1012      if(par.getMaxScale()>0){
1013        theStream<<std::setw(widthText-1)<<"Scales used in reconstruction"     
1014                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin-scaleMax]"
1015                 <<"  =  " <<resetiosflags(std::ios::right)
1016                 <<par.getMinScale() << "-" << par.getMaxScale()   <<std::endl;
1017      }
1018      else{
1019        theStream<<std::setw(widthText)<<"Minimum scale in reconstruction"     
1020                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
1021                 <<"  =  " <<resetiosflags(std::ios::right)
1022                 <<par.getMinScale()      <<std::endl;
1023      }
1024      theStream<<std::setw(widthText)<<"SNR Threshold within reconstruction" 
1025               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
1026               <<"  =  " <<resetiosflags(std::ios::right)
1027               <<par.getAtrousCut()      <<std::endl;
1028      theStream<<std::setw(widthText)<<"Filter being used for reconstruction"
1029               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
1030               <<"  =  " <<resetiosflags(std::ios::right)
1031               <<par.getFilterCode()
1032               << " (" << par.getFilterName()  << ")" <<std::endl;
1033    }                                                 
1034    theStream  <<std::setw(widthText)<<"Using Robust statistics?"                 
1035               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagRobustStats]"
1036               <<"  =  " <<resetiosflags(std::ios::right)
1037               <<stringize(par.getFlagRobustStats()) <<std::endl;
1038    if(par.getFlagStatSec()){
1039      theStream<<std::setw(widthText)<<"Section used by statistics calculation"
1040               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[statSec]"
1041               <<"  =  " <<resetiosflags(std::ios::right)
1042               <<par.statSec.getSection()          <<std::endl;
1043    }
1044    theStream  <<std::setw(widthText)<<"Using FDR analysis?"                 
1045               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
1046               <<"  =  " <<resetiosflags(std::ios::right)
1047               <<stringize(par.getFlagFDR())        <<std::endl;
1048    if(par.getFlagFDR()){                                     
1049      theStream<<std::setw(widthText)<<"Alpha value for FDR analysis"         
1050               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
1051               <<"  =  " <<resetiosflags(std::ios::right)
1052               <<par.getAlpha()          <<std::endl;
1053      theStream<<std::setw(widthText)<<"Number of correlated channels for FDR"         
1054               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[FDRnumCorChan]"
1055               <<"  =  " <<resetiosflags(std::ios::right)
1056               <<par.getFDRnumCorChan()          <<std::endl;
1057    }                                                 
1058    else {
1059      if(par.getFlagUserThreshold()){
1060        theStream<<std::setw(widthText)<<"Detection Threshold"                       
1061                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
1062                 <<"  =  " <<resetiosflags(std::ios::right)
1063                 <<par.getThreshold()            <<std::endl;
1064      }
1065      else{
1066        theStream<<std::setw(widthText)<<"SNR Threshold (in sigma)"
1067                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
1068                 <<"  =  " <<resetiosflags(std::ios::right)
1069                 <<par.getCut()            <<std::endl;
1070      }
1071    }
1072    theStream  <<std::setw(widthText)<<"Minimum # Pixels in a detection"     
1073               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
1074               <<"  =  " <<resetiosflags(std::ios::right)
1075               <<par.getMinPix()         <<std::endl;
1076    theStream  <<std::setw(widthText)<<"Minimum # Channels in a detection"   
1077               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
1078               <<"  =  " <<resetiosflags(std::ios::right)
1079               <<par.getMinChannels()    <<std::endl;
1080    theStream  <<std::setw(widthText)<<"Growing objects after detection?"     
1081               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
1082               <<"  =  " <<resetiosflags(std::ios::right)
1083               <<stringize(par.getFlagGrowth())     <<std::endl;
1084    if(par.getFlagGrowth()) {                         
1085      if(par.getFlagUserGrowthThreshold()){
1086        theStream<<std::setw(widthText)<<"Threshold for growth"                       
1087                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthThreshold]"
1088                 <<"  =  " <<resetiosflags(std::ios::right)
1089                 <<par.getGrowthThreshold()        <<std::endl;
1090      }
1091      else{
1092        theStream<<std::setw(widthText)<<"SNR Threshold for growth"             
1093                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
1094                 <<"  =  " <<resetiosflags(std::ios::right)
1095                 <<par.getGrowthCut()      <<std::endl;
1096      }
1097    }
1098    theStream  <<std::setw(widthText)<<"Using Adjacent-pixel criterion?"     
1099               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
1100               <<"  =  " <<resetiosflags(std::ios::right)
1101               <<stringize(par.getFlagAdjacent())   <<std::endl;
1102    if(!par.getFlagAdjacent()){
1103      theStream<<std::setw(widthText)<<"Max. spatial separation for merging" 
1104               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
1105               <<"  =  " <<resetiosflags(std::ios::right)
1106               <<par.getThreshS()        <<std::endl;
1107    }
1108    theStream  <<std::setw(widthText)<<"Max. velocity separation for merging"
1109               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
1110               <<"  =  " <<resetiosflags(std::ios::right)
1111               <<par.getThreshV()        <<std::endl;
1112    theStream  <<std::setw(widthText)<<"Method of spectral plotting"         
1113               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
1114               <<"  =  " <<resetiosflags(std::ios::right)
1115               <<par.getSpectralMethod() <<std::endl;
1116    theStream  <<std::setw(widthText)<<"Type of object centre used in results"
1117               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[pixelCentre]"
1118               <<"  =  " <<resetiosflags(std::ios::right)
1119               <<par.getPixelCentre() <<std::endl;
1120    theStream  <<"--------------------\n\n";
1121    theStream  << std::setfill(' ');
1122    theStream.unsetf(std::ios::left);
1123    //  theStream.unsetf(std::ios::boolalpha);
1124    return theStream;
1125  }
1126
1127
1128  void Param::copyHeaderInfo(FitsHeader &head)
1129  {
1130    ///  A function to copy across relevant header keywords from the
1131    ///  FitsHeader class to the Param class, as they are needed by
1132    ///  functions in the Param class.
1133    ///  The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
1134
1135    this->blankKeyword  = head.getBlankKeyword();
1136    this->bscaleKeyword = head.getBscaleKeyword();
1137    this->bzeroKeyword  = head.getBzeroKeyword();
1138    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
1139      this->bzeroKeyword;
1140
1141    this->numPixBeam    = head.getBeamSize();
1142  }
1143
1144  std::string Param::outputMaskFile()
1145  {
1146    ///  This function produces the required filename in which to save
1147    ///  the mask image, indicating which pixels have been detected as
1148    ///  part of an object. If the input image is image.fits, then the
1149    ///  output will be image.MASK.fits.
1150
1151    if(this->fileOutputMask==""){
1152      std::string inputName = this->imageFile;
1153      std::stringstream ss;
1154      ss << inputName.substr(0,inputName.size()-5); 
1155      // remove the ".fits" on the end.
1156      ss << ".MASK.fits";
1157      return ss.str();
1158    }
1159    else return this->fileOutputMask;
1160  }
1161
1162  std::string Param::outputSmoothFile()
1163  {
1164    ///  This function produces the required filename in which to save
1165    ///   the smoothed array. If the input image is image.fits, then
1166    ///   the output will be:
1167    ///    <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
1168    ///             width of the Hanning filter was 3 pixels.
1169    ///        <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
1170    ///             kernMaj=3, kernMin=2 and kernPA=20 degrees.
1171    ///    </ul>
1172
1173    if(this->fileOutputSmooth==""){
1174      std::string inputName = this->imageFile;
1175      std::stringstream ss;
1176      ss << inputName.substr(0,inputName.size()-5); 
1177      // remove the ".fits" on the end.
1178      if(this->flagSubsection) ss<<".sub";
1179      if(this->smoothType=="spectral")
1180        ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
1181      else if(this->smoothType=="spatial")
1182        ss << ".SMOOTH-2D-"
1183           << this->kernMaj << "-"
1184           << this->kernMin << "-"
1185           << this->kernPA  << ".fits";
1186      return ss.str();
1187    }
1188    else return this->fileOutputSmooth;
1189  }
1190
1191  std::string Param::outputReconFile()
1192  {
1193    /// This function produces the required filename in which to save
1194    ///  the reconstructed array. If the input image is image.fits, then
1195    ///  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
1196    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
1197
1198    if(this->fileOutputRecon==""){
1199      std::string inputName = this->imageFile;
1200      std::stringstream ss;
1201      // First we remove the ".fits" from the end of the filename.
1202      ss << inputName.substr(0,inputName.size()-5); 
1203      if(this->flagSubsection) ss<<".sub";
1204      ss << ".RECON-" << this->reconDim
1205         << "-"       << this->filterCode
1206         << "-"       << this->snrRecon
1207         << "-"       << this->scaleMin
1208         << ".fits";
1209      return ss.str();
1210    }
1211    else return this->fileOutputRecon;
1212  }
1213
1214  std::string Param::outputResidFile()
1215  {
1216    /// This function produces the required filename in which to save
1217    ///  the reconstructed array. If the input image is image.fits, then
1218    ///  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
1219    ///  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
1220
1221    if(this->fileOutputResid==""){
1222      std::string inputName = this->imageFile;
1223      std::stringstream ss;
1224      // First we remove the ".fits" from the end of the filename.
1225      ss << inputName.substr(0,inputName.size()-5);
1226      if(this->flagSubsection) ss<<".sub";
1227      ss << ".RESID-" << this->reconDim
1228         << "-"       << this->filterCode
1229         << "-"       << this->snrRecon
1230         << "-"       << this->scaleMin
1231         << ".fits";
1232      return ss.str();
1233    }
1234    else return this->fileOutputResid;
1235  }
1236
1237}
Note: See TracBrowser for help on using the repository browser.