source: trunk/src/param.cc @ 503

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

Fixing a couple of bugs in the Param copying function, and making the parameter checking routines in the readParams function a separate function checkPars().

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