source: trunk/src/param.cc @ 506

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

New function makeStatMask to make a mask that accounts for the statSec region, as well as Blank pixels and MW channels. Also fixing what is in checkPars.

File size: 47.8 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::makeStatMask(float *array, long *dim)
381  {
382    /**
383     *  This returns an array of bools, saying whether each pixel in
384     *  the given array is suitable for a stats calculation. It needs
385     *  to be in the StatSec (if defined), not blank and not a MW
386     *  channel. The array is allocated by the function with a 'new' call.
387     */
388    bool *mask = new bool[dim[0]*dim[1]*dim[2]];
389    for(int x=0;x<dim[0];x++) {
390      for(int y=0;y<dim[1];y++) {
391        for(int z=0;z<dim[2];z++) {
392          int i = x+y*dim[0]+z*dim[0]*dim[1];
393          mask[i] = !this->isBlank(array[i]) && !this->isInMW(z) && this->isStatOK(x,y,z);
394        }
395      }
396    }
397    return mask;
398  }
399
400
401  bool Param::isInMW(int z)
402  {
403    /**
404     *  Tests whether we are flagging Milky Way channels, and if so
405     * whether the given channel number is in the Milky Way range. The
406     * channels are assumed to start at number 0. 
407     * \param z The channel number
408     * \return True if we are flagging Milky Way channels and z is in
409     *  the range.
410     */
411    return ( flagMW && (z>=minMW) && (z<=maxMW) );
412  }
413
414  bool Param::isStatOK(int x, int y, int z)
415  {
416    /**
417     * Test whether a given pixel position lies within the subsection
418     * given by the statSec parameter. Only tested if the flagSubsection
419     * parameter is true -- if it isn't, we just return true since all
420     * pixels are therefore available for statstical calculations.
421     * \param x X-value of pixel being tested.
422     * \param y Y-value of pixel being tested.
423     * \param z Z-value of pixel being tested.
424     * \return True if pixel is able to be used for statistical
425     * calculations. False otherwise.
426     */
427    int xval=x,yval=y,zval=z;
428    if(flagSubsection){
429      xval += pixelSec.getStart(0);
430      yval += pixelSec.getStart(1);
431      zval += pixelSec.getStart(2);
432    }
433    return !flagStatSec || statSec.isInside(xval,yval,zval);
434  }
435
436  std::vector<int> Param::getObjectRequest()
437  {
438    /**
439     *  Returns a list of the object numbers requested via the objectList parameter.
440     * \return a vector of integers, one for each number in the objectList set.
441     */
442    std::stringstream ss1;
443    std::string tmp;
444    std::vector<int> tmplist;
445    ss1.str(this->objectList);
446    while(!ss1.eof()){
447      getline(ss1,tmp,',');
448      for(int i=0;i<tmp.size();i++) if(tmp[i]=='-') tmp[i]=' ';
449      int a,b;
450      std::stringstream ss2;
451      ss2.str(tmp);
452      ss2 >>a;
453      if(!ss2.eof()) ss2 >> b;
454      else b=a;
455      for(int n=a;n<=b;n++){
456        tmplist.push_back(n);
457      }     
458    }
459    return tmplist;
460  }
461
462  std::vector<bool> Param::getObjectChoices()
463  {
464    /**
465     *  Returns a list of bool values, indicating whether a given
466     *  object was requested or not. The size of the vector is
467     *  determined by the maximum value in objectList. For instance,
468     *  if objectList="2,3,5-8", then the returned vector will be
469     *  [0,1,1,0,1,1,1,1].
470     *  \return Vector of bool values.
471     */
472    std::vector<int> objectChoices = this->getObjectRequest();
473    int maxNum = *std::max_element(objectChoices.begin(), objectChoices.end());
474    std::vector<bool> choices(maxNum,false);
475    for(int i=0;i<objectChoices.size();i++) choices[objectChoices[i]-1] = true;
476    return choices;
477  }
478
479  std::vector<bool> Param::getObjectChoices(int numObjects)
480  {
481    /**
482     *  Returns a list of bool values, indicating whether a given
483     *  object was requested or not. The size of the vector is given
484     *  by the numObjects parameter. So, if objectList="2,3,5-8", then
485     *  the returned vector from a getObjectChoices(10) call will be
486     *  [0,1,1,0,1,1,1,1,0,0].
487     *  \param numObjects How many objects there are in total.
488     *  \return Vector of bool values.
489     */
490    if(this->objectList==""){
491      std::vector<bool> choices(numObjects,true);
492      return choices;
493    }
494    else{
495      std::vector<int> objectChoices = this->getObjectRequest();
496      std::vector<bool> choices(numObjects,false);
497      for(int i=0;i<objectChoices.size();i++)
498        if(objectChoices[i]<=numObjects) choices[objectChoices[i]-1] = true;
499      return choices;
500    }
501  }
502
503  /****************************************************************/
504  ///////////////////////////////////////////////////
505  //// Other Functions using the  Parameter class:
506  ///////////////////////////////////////////////////
507
508  std::string makelower( std::string s )
509  {
510    // "borrowed" from Matt Howlett's 'fred'
511    std::string out = "";
512    for( int i=0; i<s.size(); ++i ) {
513      out += tolower(s[i]);
514    }
515    return out;
516  }
517
518  inline std::string stringize(bool b)
519  {
520    /**
521     * Convert a bool variable to the textual equivalent.
522     * \return A std::string with the english equivalent of the bool.
523     */
524    std::string output;
525    if(b) output="true";
526    else output="false";
527    return output;
528  }
529
530  inline bool boolify( std::string s )
531  {
532    /**
533     *  Convert a std::string to a bool variable:
534     *  "1" and "true" get converted to true;
535     *  "0" and "false" (and anything else) get converted to false.
536     * \return The bool equivalent of the string.
537     */
538    if((s=="1") || (makelower(s)=="true")) return true;
539    else if((s=="0") || (makelower(s)=="false")) return false;
540    else return false;
541  }
542
543  inline std::string readSval(std::stringstream& ss)
544  {
545    std::string val; ss >> val; return val;
546  }
547
548  inline bool readFlag(std::stringstream& ss)
549  {
550    std::string val; ss >> val; return boolify(val);
551  }
552
553  inline float readFval(std::stringstream& ss)
554  {
555    float val; ss >> val; return val;
556  }
557
558  inline int readIval(std::stringstream& ss)
559  {
560    int val; ss >> val; return val;
561  }
562
563  int Param::readParams(std::string paramfile)
564  {
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=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
610        if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
611        if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
612        if(arg=="flagvot")         this->flagVOT = readFlag(ss);
613        if(arg=="votfile")         this->votFile = readSval(ss);
614        if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
615        if(arg=="karmafile")       this->karmaFile = readSval(ss);
616        if(arg=="annotationtype")  this->annotationType = readSval(ss);
617        if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
618        if(arg=="detectionmap")    this->detectionMap = readSval(ss);
619        if(arg=="momentmap")       this->momentMap = readSval(ss);
620        if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
621        if(arg=="newfluxunits")    this->newFluxUnits = readSval(ss);
622        if(arg=="precflux")        this->precFlux = readIval(ss);
623        if(arg=="precvel")         this->precVel = readIval(ss);
624        if(arg=="precsnr")         this->precSNR = readIval(ss);
625
626        if(arg=="flagtrim")        this->flagTrim = readFlag(ss);
627        if(arg=="flagmw")          this->flagMW = readFlag(ss);
628        if(arg=="maxmw")           this->maxMW = readIval(ss);
629        if(arg=="minmw")           this->minMW = readIval(ss);
630        if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
631
632        if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
633        if(arg=="minpix")          this->minPix = readIval(ss);
634        if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
635        if(arg=="growthcut")       this->growthCut = readFval(ss);
636        if(arg=="growththreshold"){
637          this->growthThreshold = readFval(ss);
638          this->flagUserGrowthThreshold = true;
639        }
640
641        if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
642        if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
643
644        if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
645        if(arg=="statsec")         this->statSec.setSection(readSval(ss));
646        if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss);
647        if(arg=="snrcut")          this->snrCut = readFval(ss);
648        if(arg=="threshold"){
649          this->threshold = readFval(ss);
650          this->flagUserThreshold = true;
651        }
652     
653        if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
654        if(arg=="smoothtype")      this->smoothType = readSval(ss);
655        if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
656        if(arg=="kernmaj")         this->kernMaj = readFval(ss);
657        if(arg=="kernmin")         this->kernMin = readFval(ss);
658        if(arg=="kernpa")          this->kernPA = readFval(ss);
659
660        if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
661        if(arg=="recondim")        this->reconDim = readIval(ss);
662        if(arg=="scalemin")        this->scaleMin = readIval(ss);
663        if(arg=="scalemax")        this->scaleMax = readIval(ss);
664        if(arg=="snrrecon")        this->snrRecon = readFval(ss);
665        if(arg=="filtercode"){
666          this->filterCode = readIval(ss);
667          this->reconFilter.define(this->filterCode);
668        }
669
670        if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
671        if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
672        if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
673        if(arg=="minchannels")     this->minChannels = readIval(ss);
674
675        if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
676        if(arg=="spectralunits")   this->spectralUnits = makelower(readSval(ss));
677        if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
678        if(arg=="drawborders")     this->borders = readFlag(ss);
679        if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
680        if(arg=="verbose")         this->verbose = readFlag(ss);
681
682        // Dealing with deprecated parameters.
683        if(arg=="flagblankpix"){
684          this->flagTrim = readFlag(ss);
685          std::stringstream errmsg;
686          errmsg <<"The parameter flagBlankPix is deprecated. "
687                 <<"Please use the flagTrim parameter in future.\n"
688                 <<"Setting flagTrim = " << stringize(this->flagTrim) << ".\n";
689          duchampWarning("Reading parameters",errmsg.str());
690        }
691        if(arg=="blankpixvalue"){
692          std::stringstream errmsg;
693          errmsg <<"The parameter blankPixValue is deprecated.\n"
694                 <<"This value is only taken from the FITS header.\n";
695          duchampWarning("Reading parameters",errmsg.str());
696        }
697
698      }
699    }
700
701    this->checkPars();
702
703    return SUCCESS;
704
705  }
706 
707  void Param::checkPars()
708  {
709
710    // If we have usePrevious=false, set the objectlist to blank so that we use all of them
711    if(!this->usePrevious) this->objectList = "";
712
713    // If pgplot was not included in the compilation, need to set flagXOutput to false
714    if(!USE_PGPLOT) this->flagXOutput = false;
715
716    // Correcting bad precision values -- if negative, set to 0
717    if(this->precFlux<0) this->precFlux = 0;
718    if(this->precVel<0)  this->precVel = 0;
719    if(this->precSNR<0)  this->precSNR = 0;
720
721    // The wavelet reconstruction takes precendence over the smoothing.
722    if(this->flagATrous) this->flagSmooth = false;
723
724    if(this->flagUserThreshold){
725
726      // If we specify a manual threshold, need to also specify a manual growth threshold
727      // If we haven't done so, turn growing off
728      if(this->flagGrowth && !this->flagUserGrowthThreshold){
729        std::stringstream errmsg;
730        errmsg << "You have specified a manual search threshold, but not a manual growth threshold.\n"
731               << "You need to do so using the \"growthThreshold\" parameter.\n"
732               << "The growth function is being turned off.\n";
733        duchampWarning("Reading parameters",errmsg.str());
734        this->flagGrowth = false;
735      }
736
737      // If we specify a manual threshold, we don't need the FDR method, so turn it off if requested.
738      if(this->flagFDR){
739        std::stringstream errmsg;
740        errmsg << "You have specified a manual search threshold, so we don't need to use the FDR method.\n"
741               << "Setting \"flagFDR=false\".\n";
742        duchampWarning("Reading parameters",errmsg.str());
743        this->flagFDR = false;
744      }
745
746    }   
747
748    // Make sure the annnotationType is an acceptable option -- default is "borders"
749    if((this->annotationType != "borders") && (this->annotationType!="circles")){
750      std::stringstream errmsg;
751      errmsg << "The requested value of the parameter annotationType, \""
752             << this->annotationType << "\" is invalid.\n"
753             << "Changing to \"borders\".\n";
754      duchampWarning("Reading parameters",errmsg.str());
755      this->annotationType = "borders";
756    }
757     
758    // Make sure smoothType is an acceptable type -- default is "spectral"
759    if((this->smoothType!="spectral")&&
760       (this->smoothType!="spatial")){
761      std::stringstream errmsg;
762      errmsg << "The requested value of the parameter smoothType, \""
763             << this->smoothType << "\" is invalid.\n"
764             << "Changing to \"spectral\".\n";
765      duchampWarning("Reading parameters",errmsg.str());
766      this->smoothType = "spectral";
767    }
768    // If kernMin has not been given, or is negative, make it equal to kernMaj
769    if(this->kernMin < 0) this->kernMin = this->kernMaj;
770
771    // Make sure spectralMethod is an acceptable type -- default is "peak"
772    if((this->spectralMethod!="peak")&&
773       (this->spectralMethod!="sum")){
774      std::stringstream errmsg;
775      errmsg << "The requested value of the parameter spectralMethod, \""
776             << this->spectralMethod << "\" is invalid.\n"
777             << "Changing to \"peak\".\n";
778      duchampWarning("Reading parameters",errmsg.str());
779      this->spectralMethod = "peak";
780    }
781
782    // Make sure pixelCentre is an acceptable type -- default is "peak"
783    if((this->pixelCentre!="centroid")&&
784       (this->pixelCentre!="average") &&
785       (this->pixelCentre!="peak")       ){
786      std::stringstream errmsg;
787      errmsg << "The requested value of the parameter pixelCentre, \""
788             << this->pixelCentre << "\" is invalid.\n"
789             << "Changing to \"centroid\".\n";
790      duchampWarning("Reading parameters",errmsg.str());
791      this->pixelCentre = "centroid";
792    }
793
794  }
795
796
797  std::ostream& operator<< ( std::ostream& theStream, Param& par)
798  {
799    /**
800     * Print out the parameter set in a formatted, easy to read style.
801     * Lists the parameters, a description of them, and their value.
802     */
803
804    // Only show the [beamSize] bit if we are using the parameter
805    // otherwise we have read it from the FITS header.
806    std::string beamParam = "";
807    if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
808
809    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
810    //   theStream.setf(std::ios::boolalpha);
811    theStream.setf(std::ios::left);
812    theStream  <<"\n---- Parameters ----"<<std::endl;
813    theStream  << std::setfill('.');
814    const int widthText = 38;
815    const int widthPar  = 18;
816    if(par.getFlagSubsection())
817      theStream<<std::setw(widthText)<<"Image to be analysed"                 
818               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
819               <<"  =  " <<resetiosflags(std::ios::right)
820               <<(par.getImageFile()+par.getSubsection()) <<std::endl;
821    else
822      theStream<<std::setw(widthText)<<"Image to be analysed"                 
823               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
824               <<"  =  " <<resetiosflags(std::ios::right)
825               <<par.getImageFile()      <<std::endl;
826    if(par.getFlagReconExists() && par.getFlagATrous()){
827      theStream<<std::setw(widthText)<<"Reconstructed array exists?"         
828               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
829               <<"  =  " <<resetiosflags(std::ios::right)
830               <<stringize(par.getFlagReconExists())<<std::endl;
831      theStream<<std::setw(widthText)<<"FITS file containing reconstruction" 
832               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
833               <<"  =  " <<resetiosflags(std::ios::right)
834               <<par.getReconFile()      <<std::endl;
835    }
836    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
837      theStream<<std::setw(widthText)<<"Smoothed array exists?"         
838               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
839               <<"  =  " <<resetiosflags(std::ios::right)
840               <<stringize(par.getFlagSmoothExists())<<std::endl;
841      theStream<<std::setw(widthText)<<"FITS file containing smoothed array" 
842               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
843               <<"  =  " <<resetiosflags(std::ios::right)
844               <<par.getSmoothFile()      <<std::endl;
845    }
846    theStream  <<std::setw(widthText)<<"Intermediate Logfile"
847               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
848               <<"  =  " <<resetiosflags(std::ios::right)
849               <<par.getLogFile()        <<std::endl;
850    theStream  <<std::setw(widthText)<<"Final Results file"                   
851               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
852               <<"  =  " <<resetiosflags(std::ios::right)
853               <<par.getOutFile()        <<std::endl;
854    if(par.getFlagSeparateHeader())
855      theStream <<std::setw(widthText)<<"Header for results file"
856                <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[headerFile]"
857                <<"  =  " <<resetiosflags(std::ios::right)
858                <<par.getHeaderFile()        <<std::endl;
859    theStream  <<std::setw(widthText)<<"Spectrum file"                       
860               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
861               <<"  =  " <<resetiosflags(std::ios::right)
862               <<par.getSpectraFile()    <<std::endl;
863    if(par.getFlagTextSpectra()){
864      theStream<<std::setw(widthText)<<"Text file with ascii spectral data"                         
865               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraTextFile]"
866               <<"  =  " <<resetiosflags(std::ios::right)
867               <<par.getSpectraTextFile()<<std::endl;
868    }
869    if(par.getFlagVOT()){
870      theStream<<std::setw(widthText)<<"VOTable file"                         
871               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
872               <<"  =  " <<resetiosflags(std::ios::right)
873               <<par.getVOTFile()        <<std::endl;
874    }
875    if(par.getFlagKarma()){
876      theStream<<std::setw(widthText)<<"Karma annotation file"               
877               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
878               <<"  =  " <<resetiosflags(std::ios::right)
879             
880               <<par.getKarmaFile()      <<std::endl;
881    }
882    if(par.getFlagMaps()){
883      theStream<<std::setw(widthText)<<"0th Moment Map"                       
884               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
885               <<"  =  " <<resetiosflags(std::ios::right)
886               <<par.getMomentMap()      <<std::endl;
887      theStream<<std::setw(widthText)<<"Detection Map"                       
888               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
889               <<"  =  " <<resetiosflags(std::ios::right)
890               <<par.getDetectionMap()   <<std::endl;
891    }
892    theStream  <<std::setw(widthText)<<"Display a map in a pgplot xwindow?"
893               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
894               <<"  =  " <<resetiosflags(std::ios::right)
895               <<stringize(par.getFlagXOutput())     <<std::endl;
896    if(par.getFlagATrous()){                           
897      theStream<<std::setw(widthText)<<"Saving reconstructed cube?"           
898               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputRecon]"
899               <<"  =  " <<resetiosflags(std::ios::right)
900               <<stringize(par.getFlagOutputRecon())<<std::endl;
901      theStream<<std::setw(widthText)<<"Saving residuals from reconstruction?"
902               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputResid]"
903               <<"  =  " <<resetiosflags(std::ios::right)
904               <<stringize(par.getFlagOutputResid())<<std::endl;
905    }                                                 
906    if(par.getFlagSmooth()){                           
907      theStream<<std::setw(widthText)<<"Saving smoothed cube?"           
908               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputSmooth]"
909               <<"  =  " <<resetiosflags(std::ios::right)
910               <<stringize(par.getFlagOutputSmooth())<<std::endl;
911    }                                                 
912    theStream<<std::setw(widthText)<<"Saving mask cube?"           
913             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputMask]"
914             <<"  =  " <<resetiosflags(std::ios::right)
915             <<stringize(par.getFlagOutputMask())<<std::endl;
916    theStream  <<"------"<<std::endl;
917    if(par.getFlagBlankPix()){
918      theStream<<std::setw(widthText)<<"Blank Pixel Value"                   
919               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< ""
920               <<"  =  " <<resetiosflags(std::ios::right)
921               <<par.getBlankPixVal()    <<std::endl;
922    }
923    theStream  <<std::setw(widthText)<<"Trimming Blank Pixels?"                 
924               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagTrim]"
925               <<"  =  " <<resetiosflags(std::ios::right)
926               <<stringize(par.getFlagTrim())   <<std::endl;
927    theStream  <<std::setw(widthText)<<"Searching for Negative features?"     
928               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
929               <<"  =  " <<resetiosflags(std::ios::right)
930               <<stringize(par.getFlagNegative())   <<std::endl;
931    theStream  <<std::setw(widthText)<<"Removing Milky Way channels?"         
932               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
933               <<"  =  " <<resetiosflags(std::ios::right)
934               <<stringize(par.getFlagMW())         <<std::endl;
935    if(par.getFlagMW()){
936      theStream<<std::setw(widthText)<<"Milky Way Channels"                   
937               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
938               <<"  =  " <<resetiosflags(std::ios::right)
939               <<par.getMinMW()
940               <<"-" <<par.getMaxMW()          <<std::endl;
941    }
942    theStream  <<std::setw(widthText)<<"Beam Size (pixels)"                   
943               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
944               <<"  =  " <<resetiosflags(std::ios::right)
945               <<par.getBeamSize()       <<std::endl;
946    theStream  <<std::setw(widthText)<<"Removing baselines before search?"   
947               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
948               <<"  =  " <<resetiosflags(std::ios::right)
949               <<stringize(par.getFlagBaseline())   <<std::endl;
950    theStream  <<std::setw(widthText)<<"Smoothing each spectrum first?"       
951               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
952               <<"  =  " <<resetiosflags(std::ios::right)
953               <<stringize(par.getFlagSmooth())     <<std::endl;
954    if(par.getFlagSmooth()){           
955      theStream<<std::setw(widthText)<<"Type of smoothing"     
956               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothType]"
957               <<"  =  " <<resetiosflags(std::ios::right)
958               <<par.getSmoothType()       <<std::endl;
959      if(par.getSmoothType()=="spectral")
960        theStream<<std::setw(widthText)<<"Width of hanning filter"     
961                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
962                 <<"  =  " <<resetiosflags(std::ios::right)
963                 <<par.getHanningWidth()       <<std::endl;
964      else{
965        theStream<<std::setw(widthText)<<"Gaussian kernel semi-major axis [pix]"
966                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMaj]"
967                 <<"  =  " <<resetiosflags(std::ios::right)
968                 <<par.getKernMaj() << std::endl;
969        theStream<<std::setw(widthText)<<"Gaussian kernel semi-minor axis [pix]"
970                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMin]"
971                 <<"  =  " <<resetiosflags(std::ios::right)
972                 <<par.getKernMin() << std::endl;
973        theStream<<std::setw(widthText)<<"Gaussian kernel position angle [deg]"
974                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernPA]"
975                 <<"  =  " <<resetiosflags(std::ios::right)
976                 <<par.getKernPA() << std::endl;
977      }
978    }
979    theStream  <<std::setw(widthText)<<"Using A Trous reconstruction?"       
980               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
981               <<"  =  " <<resetiosflags(std::ios::right)
982               <<stringize(par.getFlagATrous())     <<std::endl;
983    if(par.getFlagATrous()){                           
984      theStream<<std::setw(widthText)<<"Number of dimensions in reconstruction"     
985               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
986               <<"  =  " <<resetiosflags(std::ios::right)
987               <<par.getReconDim()       <<std::endl;
988      if(par.getMaxScale()>0){
989        theStream<<std::setw(widthText-1)<<"Scales used in reconstruction"     
990                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin-scaleMax]"
991                 <<"  =  " <<resetiosflags(std::ios::right)
992                 <<par.getMinScale() << "-" << par.getMaxScale()   <<std::endl;
993      }
994      else{
995        theStream<<std::setw(widthText)<<"Minimum scale in reconstruction"     
996                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
997                 <<"  =  " <<resetiosflags(std::ios::right)
998                 <<par.getMinScale()      <<std::endl;
999      }
1000      theStream<<std::setw(widthText)<<"SNR Threshold within reconstruction" 
1001               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
1002               <<"  =  " <<resetiosflags(std::ios::right)
1003               <<par.getAtrousCut()      <<std::endl;
1004      theStream<<std::setw(widthText)<<"Filter being used for reconstruction"
1005               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
1006               <<"  =  " <<resetiosflags(std::ios::right)
1007               <<par.getFilterCode()
1008               << " (" << par.getFilterName()  << ")" <<std::endl;
1009    }                                                 
1010    theStream  <<std::setw(widthText)<<"Using Robust statistics?"                 
1011               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagRobustStats]"
1012               <<"  =  " <<resetiosflags(std::ios::right)
1013               <<stringize(par.getFlagRobustStats()) <<std::endl;
1014    if(par.getFlagStatSec()){
1015      theStream<<std::setw(widthText)<<"Section used by statistics calculation"
1016               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[statSec]"
1017               <<"  =  " <<resetiosflags(std::ios::right)
1018               <<par.statSec.getSection()          <<std::endl;
1019    }
1020    theStream  <<std::setw(widthText)<<"Using FDR analysis?"                 
1021               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
1022               <<"  =  " <<resetiosflags(std::ios::right)
1023               <<stringize(par.getFlagFDR())        <<std::endl;
1024    if(par.getFlagFDR()){                                     
1025      theStream<<std::setw(widthText)<<"Alpha value for FDR analysis"         
1026               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
1027               <<"  =  " <<resetiosflags(std::ios::right)
1028               <<par.getAlpha()          <<std::endl;
1029    }                                                 
1030    else {
1031      if(par.getFlagUserThreshold()){
1032        theStream<<std::setw(widthText)<<"Detection Threshold"                       
1033                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
1034                 <<"  =  " <<resetiosflags(std::ios::right)
1035                 <<par.getThreshold()            <<std::endl;
1036      }
1037      else{
1038        theStream<<std::setw(widthText)<<"SNR Threshold (in sigma)"
1039                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
1040                 <<"  =  " <<resetiosflags(std::ios::right)
1041                 <<par.getCut()            <<std::endl;
1042      }
1043    }
1044    theStream  <<std::setw(widthText)<<"Minimum # Pixels in a detection"     
1045               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
1046               <<"  =  " <<resetiosflags(std::ios::right)
1047               <<par.getMinPix()         <<std::endl;
1048    theStream  <<std::setw(widthText)<<"Minimum # Channels in a detection"   
1049               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
1050               <<"  =  " <<resetiosflags(std::ios::right)
1051               <<par.getMinChannels()    <<std::endl;
1052    theStream  <<std::setw(widthText)<<"Growing objects after detection?"     
1053               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
1054               <<"  =  " <<resetiosflags(std::ios::right)
1055               <<stringize(par.getFlagGrowth())     <<std::endl;
1056    if(par.getFlagGrowth()) {                         
1057      if(par.getFlagUserGrowthThreshold()){
1058        theStream<<std::setw(widthText)<<"Threshold for growth"                       
1059                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthThreshold]"
1060                 <<"  =  " <<resetiosflags(std::ios::right)
1061                 <<par.getGrowthThreshold()        <<std::endl;
1062      }
1063      else{
1064        theStream<<std::setw(widthText)<<"SNR Threshold for growth"             
1065                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
1066                 <<"  =  " <<resetiosflags(std::ios::right)
1067                 <<par.getGrowthCut()      <<std::endl;
1068      }
1069    }
1070    theStream  <<std::setw(widthText)<<"Using Adjacent-pixel criterion?"     
1071               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
1072               <<"  =  " <<resetiosflags(std::ios::right)
1073               <<stringize(par.getFlagAdjacent())   <<std::endl;
1074    if(!par.getFlagAdjacent()){
1075      theStream<<std::setw(widthText)<<"Max. spatial separation for merging" 
1076               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
1077               <<"  =  " <<resetiosflags(std::ios::right)
1078               <<par.getThreshS()        <<std::endl;
1079    }
1080    theStream  <<std::setw(widthText)<<"Max. velocity separation for merging"
1081               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
1082               <<"  =  " <<resetiosflags(std::ios::right)
1083               <<par.getThreshV()        <<std::endl;
1084    theStream  <<std::setw(widthText)<<"Method of spectral plotting"         
1085               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
1086               <<"  =  " <<resetiosflags(std::ios::right)
1087               <<par.getSpectralMethod() <<std::endl;
1088    theStream  <<std::setw(widthText)<<"Type of object centre used in results"
1089               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[pixelCentre]"
1090               <<"  =  " <<resetiosflags(std::ios::right)
1091               <<par.getPixelCentre() <<std::endl;
1092    theStream  <<"--------------------\n\n";
1093    theStream  << std::setfill(' ');
1094    theStream.unsetf(std::ios::left);
1095    //  theStream.unsetf(std::ios::boolalpha);
1096    return theStream;
1097  }
1098
1099
1100  void Param::copyHeaderInfo(FitsHeader &head)
1101  {
1102    /**
1103     * A function to copy across relevant header keywords from the
1104     *  FitsHeader class to the Param class, as they are needed by
1105     *  functions in the Param class.
1106     * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
1107     */
1108
1109    this->blankKeyword  = head.getBlankKeyword();
1110    this->bscaleKeyword = head.getBscaleKeyword();
1111    this->bzeroKeyword  = head.getBzeroKeyword();
1112    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
1113      this->bzeroKeyword;
1114
1115    this->numPixBeam    = head.getBeamSize();
1116  }
1117
1118  std::string Param::outputMaskFile()
1119  {
1120    /**
1121     *  This function produces the required filename in which to save
1122     *  the mask image, indicating which pixels have been detected as
1123     *  part of an object. If the input image is image.fits, then the
1124     *  output will be image.MASK.fits.
1125     */
1126    std::string inputName = this->imageFile;
1127    std::stringstream ss;
1128    ss << inputName.substr(0,inputName.size()-5); 
1129    // remove the ".fits" on the end.
1130    ss << ".MASK.fits";
1131    return ss.str();
1132  }
1133
1134  std::string Param::outputSmoothFile()
1135  {
1136    /**
1137     * This function produces the required filename in which to save
1138     *  the smoothed array. If the input image is image.fits, then
1139     *  the output will be:
1140     *   <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
1141     *            width of the Hanning filter was 3 pixels.
1142     *       <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
1143     *            kernMaj=3, kernMin=2 and kernPA=20 degrees.
1144     *   </ul>
1145     */
1146    std::string inputName = this->imageFile;
1147    std::stringstream ss;
1148    ss << inputName.substr(0,inputName.size()-5); 
1149    // remove the ".fits" on the end.
1150    if(this->flagSubsection) ss<<".sub";
1151    if(this->smoothType=="spectral")
1152      ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
1153    else if(this->smoothType=="spatial")
1154      ss << ".SMOOTH-2D-"
1155         << this->kernMaj << "-"
1156         << this->kernMin << "-"
1157         << this->kernPA  << ".fits";
1158    return ss.str();
1159  }
1160
1161  std::string Param::outputReconFile()
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.RECON-3-2-4-1.fits, where the numbers are
1167     *  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
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 << ".RECON-" << this->reconDim
1175       << "-"       << this->filterCode
1176       << "-"       << this->snrRecon
1177       << "-"       << this->scaleMin
1178       << ".fits";
1179    return ss.str();
1180  }
1181
1182  std::string Param::outputResidFile()
1183  {
1184    /**
1185     * This function produces the required filename in which to save
1186     *  the reconstructed array. If the input image is image.fits, then
1187     *  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
1188     *  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
1189     */
1190    std::string inputName = this->imageFile;
1191    std::stringstream ss;
1192    // First we remove the ".fits" from the end of the filename.
1193    ss << inputName.substr(0,inputName.size()-5);
1194    if(this->flagSubsection) ss<<".sub";
1195    ss << ".RESID-" << this->reconDim
1196       << "-"       << this->filterCode
1197       << "-"       << this->snrRecon
1198       << "-"       << this->scaleMin
1199       << ".fits";
1200    return ss.str();
1201  }
1202
1203}
Note: See TracBrowser for help on using the repository browser.