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

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

Implemented changes to Duchamp to allow the re-plotting of object spectra. This incorporates the functionality of Selavy into Duchamp, so that you only need a single executable.

File size: 46.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.threshold;
254    this->flagUserGrowthThreshold = p.flagUserThreshold;
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
719    // Make sure the annnotationType is an acceptable option -- default is "borders"
720    if((this->annotationType != "borders") && (this->annotationType!="circles")){
721      std::stringstream errmsg;
722      errmsg << "The requested value of the parameter annotationType, \""
723             << this->annotationType << "\" is invalid.\n"
724             << "Changing to \"borders\".\n";
725      duchampWarning("Reading parameters",errmsg.str());
726      this->annotationType = "borders";
727    }
728     
729    // Make sure smoothType is an acceptable type -- default is "spectral"
730    if((this->smoothType!="spectral")&&
731       (this->smoothType!="spatial")){
732      std::stringstream errmsg;
733      errmsg << "The requested value of the parameter smoothType, \""
734             << this->smoothType << "\" is invalid.\n"
735             << "Changing to \"spectral\".\n";
736      duchampWarning("Reading parameters",errmsg.str());
737      this->smoothType = "spectral";
738    }
739    // If kernMin has not been given, or is negative, make it equal to kernMaj
740    if(this->kernMin < 0) this->kernMin = this->kernMaj;
741
742    // Make sure spectralMethod is an acceptable type -- default is "peak"
743    if((this->spectralMethod!="peak")&&
744       (this->spectralMethod!="sum")){
745      std::stringstream errmsg;
746      errmsg << "The requested value of the parameter spectralMethod, \""
747             << this->spectralMethod << "\" is invalid.\n"
748             << "Changing to \"peak\".\n";
749      duchampWarning("Reading parameters",errmsg.str());
750      this->spectralMethod = "peak";
751    }
752
753    // Make sure pixelCentre is an acceptable type -- default is "peak"
754    if((this->pixelCentre!="centroid")&&
755       (this->pixelCentre!="average") &&
756       (this->pixelCentre!="peak")       ){
757      std::stringstream errmsg;
758      errmsg << "The requested value of the parameter pixelCentre, \""
759             << this->pixelCentre << "\" is invalid.\n"
760             << "Changing to \"centroid\".\n";
761      duchampWarning("Reading parameters",errmsg.str());
762      this->pixelCentre = "centroid";
763    }
764
765    return SUCCESS;
766  }
767
768
769  std::ostream& operator<< ( std::ostream& theStream, Param& par)
770  {
771    /**
772     * Print out the parameter set in a formatted, easy to read style.
773     * Lists the parameters, a description of them, and their value.
774     */
775
776    // Only show the [beamSize] bit if we are using the parameter
777    // otherwise we have read it from the FITS header.
778    std::string beamParam = "";
779    if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
780
781    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
782    //   theStream.setf(std::ios::boolalpha);
783    theStream.setf(std::ios::left);
784    theStream  <<"\n---- Parameters ----"<<std::endl;
785    theStream  << std::setfill('.');
786    const int widthText = 38;
787    const int widthPar  = 18;
788    if(par.getFlagSubsection())
789      theStream<<std::setw(widthText)<<"Image to be analysed"                 
790               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
791               <<"  =  " <<resetiosflags(std::ios::right)
792               <<(par.getImageFile()+par.getSubsection()) <<std::endl;
793    else
794      theStream<<std::setw(widthText)<<"Image to be analysed"                 
795               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
796               <<"  =  " <<resetiosflags(std::ios::right)
797               <<par.getImageFile()      <<std::endl;
798    if(par.getFlagReconExists() && par.getFlagATrous()){
799      theStream<<std::setw(widthText)<<"Reconstructed array exists?"         
800               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
801               <<"  =  " <<resetiosflags(std::ios::right)
802               <<stringize(par.getFlagReconExists())<<std::endl;
803      theStream<<std::setw(widthText)<<"FITS file containing reconstruction" 
804               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
805               <<"  =  " <<resetiosflags(std::ios::right)
806               <<par.getReconFile()      <<std::endl;
807    }
808    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
809      theStream<<std::setw(widthText)<<"Smoothed array exists?"         
810               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
811               <<"  =  " <<resetiosflags(std::ios::right)
812               <<stringize(par.getFlagSmoothExists())<<std::endl;
813      theStream<<std::setw(widthText)<<"FITS file containing smoothed array" 
814               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
815               <<"  =  " <<resetiosflags(std::ios::right)
816               <<par.getSmoothFile()      <<std::endl;
817    }
818    theStream  <<std::setw(widthText)<<"Intermediate Logfile"
819               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
820               <<"  =  " <<resetiosflags(std::ios::right)
821               <<par.getLogFile()        <<std::endl;
822    theStream  <<std::setw(widthText)<<"Final Results file"                   
823               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
824               <<"  =  " <<resetiosflags(std::ios::right)
825               <<par.getOutFile()        <<std::endl;
826    if(par.getFlagSeparateHeader())
827      theStream <<std::setw(widthText)<<"Header for results file"
828                <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[headerFile]"
829                <<"  =  " <<resetiosflags(std::ios::right)
830                <<par.getHeaderFile()        <<std::endl;
831    theStream  <<std::setw(widthText)<<"Spectrum file"                       
832               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
833               <<"  =  " <<resetiosflags(std::ios::right)
834               <<par.getSpectraFile()    <<std::endl;
835    if(par.getFlagTextSpectra()){
836      theStream<<std::setw(widthText)<<"Text file with ascii spectral data"                         
837               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraTextFile]"
838               <<"  =  " <<resetiosflags(std::ios::right)
839               <<par.getSpectraTextFile()<<std::endl;
840    }
841    if(par.getFlagVOT()){
842      theStream<<std::setw(widthText)<<"VOTable file"                         
843               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
844               <<"  =  " <<resetiosflags(std::ios::right)
845               <<par.getVOTFile()        <<std::endl;
846    }
847    if(par.getFlagKarma()){
848      theStream<<std::setw(widthText)<<"Karma annotation file"               
849               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
850               <<"  =  " <<resetiosflags(std::ios::right)
851             
852               <<par.getKarmaFile()      <<std::endl;
853    }
854    if(par.getFlagMaps()){
855      theStream<<std::setw(widthText)<<"0th Moment Map"                       
856               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
857               <<"  =  " <<resetiosflags(std::ios::right)
858               <<par.getMomentMap()      <<std::endl;
859      theStream<<std::setw(widthText)<<"Detection Map"                       
860               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
861               <<"  =  " <<resetiosflags(std::ios::right)
862               <<par.getDetectionMap()   <<std::endl;
863    }
864    theStream  <<std::setw(widthText)<<"Display a map in a pgplot xwindow?"
865               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
866               <<"  =  " <<resetiosflags(std::ios::right)
867               <<stringize(par.getFlagXOutput())     <<std::endl;
868    if(par.getFlagATrous()){                           
869      theStream<<std::setw(widthText)<<"Saving reconstructed cube?"           
870               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputRecon]"
871               <<"  =  " <<resetiosflags(std::ios::right)
872               <<stringize(par.getFlagOutputRecon())<<std::endl;
873      theStream<<std::setw(widthText)<<"Saving residuals from reconstruction?"
874               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputResid]"
875               <<"  =  " <<resetiosflags(std::ios::right)
876               <<stringize(par.getFlagOutputResid())<<std::endl;
877    }                                                 
878    if(par.getFlagSmooth()){                           
879      theStream<<std::setw(widthText)<<"Saving smoothed cube?"           
880               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputSmooth]"
881               <<"  =  " <<resetiosflags(std::ios::right)
882               <<stringize(par.getFlagOutputSmooth())<<std::endl;
883    }                                                 
884    theStream<<std::setw(widthText)<<"Saving mask cube?"           
885             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputMask]"
886             <<"  =  " <<resetiosflags(std::ios::right)
887             <<stringize(par.getFlagOutputMask())<<std::endl;
888    theStream  <<"------"<<std::endl;
889    if(par.getFlagBlankPix()){
890      theStream<<std::setw(widthText)<<"Blank Pixel Value"                   
891               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< ""
892               <<"  =  " <<resetiosflags(std::ios::right)
893               <<par.getBlankPixVal()    <<std::endl;
894    }
895    theStream  <<std::setw(widthText)<<"Trimming Blank Pixels?"                 
896               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagTrim]"
897               <<"  =  " <<resetiosflags(std::ios::right)
898               <<stringize(par.getFlagTrim())   <<std::endl;
899    theStream  <<std::setw(widthText)<<"Searching for Negative features?"     
900               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
901               <<"  =  " <<resetiosflags(std::ios::right)
902               <<stringize(par.getFlagNegative())   <<std::endl;
903    theStream  <<std::setw(widthText)<<"Removing Milky Way channels?"         
904               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
905               <<"  =  " <<resetiosflags(std::ios::right)
906               <<stringize(par.getFlagMW())         <<std::endl;
907    if(par.getFlagMW()){
908      theStream<<std::setw(widthText)<<"Milky Way Channels"                   
909               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
910               <<"  =  " <<resetiosflags(std::ios::right)
911               <<par.getMinMW()
912               <<"-" <<par.getMaxMW()          <<std::endl;
913    }
914    theStream  <<std::setw(widthText)<<"Beam Size (pixels)"                   
915               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
916               <<"  =  " <<resetiosflags(std::ios::right)
917               <<par.getBeamSize()       <<std::endl;
918    theStream  <<std::setw(widthText)<<"Removing baselines before search?"   
919               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
920               <<"  =  " <<resetiosflags(std::ios::right)
921               <<stringize(par.getFlagBaseline())   <<std::endl;
922    theStream  <<std::setw(widthText)<<"Smoothing each spectrum first?"       
923               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
924               <<"  =  " <<resetiosflags(std::ios::right)
925               <<stringize(par.getFlagSmooth())     <<std::endl;
926    if(par.getFlagSmooth()){           
927      theStream<<std::setw(widthText)<<"Type of smoothing"     
928               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothType]"
929               <<"  =  " <<resetiosflags(std::ios::right)
930               <<par.getSmoothType()       <<std::endl;
931      if(par.getSmoothType()=="spectral")
932        theStream<<std::setw(widthText)<<"Width of hanning filter"     
933                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
934                 <<"  =  " <<resetiosflags(std::ios::right)
935                 <<par.getHanningWidth()       <<std::endl;
936      else{
937        theStream<<std::setw(widthText)<<"Gaussian kernel semi-major axis [pix]"
938                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMaj]"
939                 <<"  =  " <<resetiosflags(std::ios::right)
940                 <<par.getKernMaj() << std::endl;
941        theStream<<std::setw(widthText)<<"Gaussian kernel semi-minor axis [pix]"
942                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMin]"
943                 <<"  =  " <<resetiosflags(std::ios::right)
944                 <<par.getKernMin() << std::endl;
945        theStream<<std::setw(widthText)<<"Gaussian kernel position angle [deg]"
946                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernPA]"
947                 <<"  =  " <<resetiosflags(std::ios::right)
948                 <<par.getKernPA() << std::endl;
949      }
950    }
951    theStream  <<std::setw(widthText)<<"Using A Trous reconstruction?"       
952               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
953               <<"  =  " <<resetiosflags(std::ios::right)
954               <<stringize(par.getFlagATrous())     <<std::endl;
955    if(par.getFlagATrous()){                           
956      theStream<<std::setw(widthText)<<"Number of dimensions in reconstruction"     
957               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
958               <<"  =  " <<resetiosflags(std::ios::right)
959               <<par.getReconDim()       <<std::endl;
960      if(par.getMaxScale()>0){
961        theStream<<std::setw(widthText-1)<<"Scales used in reconstruction"     
962                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin-scaleMax]"
963                 <<"  =  " <<resetiosflags(std::ios::right)
964                 <<par.getMinScale() << "-" << par.getMaxScale()   <<std::endl;
965      }
966      else{
967        theStream<<std::setw(widthText)<<"Minimum scale in reconstruction"     
968                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
969                 <<"  =  " <<resetiosflags(std::ios::right)
970                 <<par.getMinScale()      <<std::endl;
971      }
972      theStream<<std::setw(widthText)<<"SNR Threshold within reconstruction" 
973               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
974               <<"  =  " <<resetiosflags(std::ios::right)
975               <<par.getAtrousCut()      <<std::endl;
976      theStream<<std::setw(widthText)<<"Filter being used for reconstruction"
977               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
978               <<"  =  " <<resetiosflags(std::ios::right)
979               <<par.getFilterCode()
980               << " (" << par.getFilterName()  << ")" <<std::endl;
981    }                                                 
982    theStream  <<std::setw(widthText)<<"Using Robust statistics?"                 
983               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagRobustStats]"
984               <<"  =  " <<resetiosflags(std::ios::right)
985               <<stringize(par.getFlagRobustStats()) <<std::endl;
986    if(par.getFlagStatSec()){
987      theStream<<std::setw(widthText)<<"Section used by statistics calculation"
988               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[statSec]"
989               <<"  =  " <<resetiosflags(std::ios::right)
990               <<par.statSec.getSection()          <<std::endl;
991    }
992    theStream  <<std::setw(widthText)<<"Using FDR analysis?"                 
993               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
994               <<"  =  " <<resetiosflags(std::ios::right)
995               <<stringize(par.getFlagFDR())        <<std::endl;
996    if(par.getFlagFDR()){                                     
997      theStream<<std::setw(widthText)<<"Alpha value for FDR analysis"         
998               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
999               <<"  =  " <<resetiosflags(std::ios::right)
1000               <<par.getAlpha()          <<std::endl;
1001    }                                                 
1002    else {
1003      if(par.getFlagUserThreshold()){
1004        theStream<<std::setw(widthText)<<"Detection Threshold"                       
1005                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
1006                 <<"  =  " <<resetiosflags(std::ios::right)
1007                 <<par.getThreshold()            <<std::endl;
1008      }
1009      else{
1010        theStream<<std::setw(widthText)<<"SNR Threshold (in sigma)"
1011                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
1012                 <<"  =  " <<resetiosflags(std::ios::right)
1013                 <<par.getCut()            <<std::endl;
1014      }
1015    }
1016    theStream  <<std::setw(widthText)<<"Minimum # Pixels in a detection"     
1017               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
1018               <<"  =  " <<resetiosflags(std::ios::right)
1019               <<par.getMinPix()         <<std::endl;
1020    theStream  <<std::setw(widthText)<<"Minimum # Channels in a detection"   
1021               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
1022               <<"  =  " <<resetiosflags(std::ios::right)
1023               <<par.getMinChannels()    <<std::endl;
1024    theStream  <<std::setw(widthText)<<"Growing objects after detection?"     
1025               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
1026               <<"  =  " <<resetiosflags(std::ios::right)
1027               <<stringize(par.getFlagGrowth())     <<std::endl;
1028    if(par.getFlagGrowth()) {                         
1029      theStream<<std::setw(widthText)<<"SNR Threshold for growth"             
1030               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
1031               <<"  =  " <<resetiosflags(std::ios::right)
1032               <<par.getGrowthCut()      <<std::endl;
1033    }
1034    theStream  <<std::setw(widthText)<<"Using Adjacent-pixel criterion?"     
1035               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
1036               <<"  =  " <<resetiosflags(std::ios::right)
1037               <<stringize(par.getFlagAdjacent())   <<std::endl;
1038    if(!par.getFlagAdjacent()){
1039      theStream<<std::setw(widthText)<<"Max. spatial separation for merging" 
1040               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
1041               <<"  =  " <<resetiosflags(std::ios::right)
1042               <<par.getThreshS()        <<std::endl;
1043    }
1044    theStream  <<std::setw(widthText)<<"Max. velocity separation for merging"
1045               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
1046               <<"  =  " <<resetiosflags(std::ios::right)
1047               <<par.getThreshV()        <<std::endl;
1048    theStream  <<std::setw(widthText)<<"Method of spectral plotting"         
1049               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
1050               <<"  =  " <<resetiosflags(std::ios::right)
1051               <<par.getSpectralMethod() <<std::endl;
1052    theStream  <<std::setw(widthText)<<"Type of object centre used in results"
1053               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[pixelCentre]"
1054               <<"  =  " <<resetiosflags(std::ios::right)
1055               <<par.getPixelCentre() <<std::endl;
1056    theStream  <<"--------------------\n\n";
1057    theStream  << std::setfill(' ');
1058    theStream.unsetf(std::ios::left);
1059    //  theStream.unsetf(std::ios::boolalpha);
1060    return theStream;
1061  }
1062
1063
1064  void Param::copyHeaderInfo(FitsHeader &head)
1065  {
1066    /**
1067     * A function to copy across relevant header keywords from the
1068     *  FitsHeader class to the Param class, as they are needed by
1069     *  functions in the Param class.
1070     * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
1071     */
1072
1073    this->blankKeyword  = head.getBlankKeyword();
1074    this->bscaleKeyword = head.getBscaleKeyword();
1075    this->bzeroKeyword  = head.getBzeroKeyword();
1076    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
1077      this->bzeroKeyword;
1078
1079    this->numPixBeam    = head.getBeamSize();
1080  }
1081
1082  std::string Param::outputMaskFile()
1083  {
1084    /**
1085     *  This function produces the required filename in which to save
1086     *  the mask image, indicating which pixels have been detected as
1087     *  part of an object. If the input image is image.fits, then the
1088     *  output will be image.MASK.fits.
1089     */
1090    std::string inputName = this->imageFile;
1091    std::stringstream ss;
1092    ss << inputName.substr(0,inputName.size()-5); 
1093    // remove the ".fits" on the end.
1094    ss << ".MASK.fits";
1095    return ss.str();
1096  }
1097
1098  std::string Param::outputSmoothFile()
1099  {
1100    /**
1101     * This function produces the required filename in which to save
1102     *  the smoothed array. If the input image is image.fits, then
1103     *  the output will be:
1104     *   <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
1105     *            width of the Hanning filter was 3 pixels.
1106     *       <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
1107     *            kernMaj=3, kernMin=2 and kernPA=20 degrees.
1108     *   </ul>
1109     */
1110    std::string inputName = this->imageFile;
1111    std::stringstream ss;
1112    ss << inputName.substr(0,inputName.size()-5); 
1113    // remove the ".fits" on the end.
1114    if(this->flagSubsection) ss<<".sub";
1115    if(this->smoothType=="spectral")
1116      ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
1117    else if(this->smoothType=="spatial")
1118      ss << ".SMOOTH-2D-"
1119         << this->kernMaj << "-"
1120         << this->kernMin << "-"
1121         << this->kernPA  << ".fits";
1122    return ss.str();
1123  }
1124
1125  std::string Param::outputReconFile()
1126  {
1127    /**
1128     * This function produces the required filename in which to save
1129     *  the reconstructed array. If the input image is image.fits, then
1130     *  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
1131     *  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
1132     */
1133    std::string inputName = this->imageFile;
1134    std::stringstream ss;
1135    // First we remove the ".fits" from the end of the filename.
1136    ss << inputName.substr(0,inputName.size()-5); 
1137    if(this->flagSubsection) ss<<".sub";
1138    ss << ".RECON-" << this->reconDim
1139       << "-"       << this->filterCode
1140       << "-"       << this->snrRecon
1141       << "-"       << this->scaleMin
1142       << ".fits";
1143    return ss.str();
1144  }
1145
1146  std::string Param::outputResidFile()
1147  {
1148    /**
1149     * This function produces the required filename in which to save
1150     *  the reconstructed array. If the input image is image.fits, then
1151     *  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
1152     *  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
1153     */
1154    std::string inputName = this->imageFile;
1155    std::stringstream ss;
1156    // First we remove the ".fits" from the end of the filename.
1157    ss << inputName.substr(0,inputName.size()-5);
1158    if(this->flagSubsection) ss<<".sub";
1159    ss << ".RESID-" << this->reconDim
1160       << "-"       << this->filterCode
1161       << "-"       << this->snrRecon
1162       << "-"       << this->scaleMin
1163       << ".fits";
1164    return ss.str();
1165  }
1166
1167}
Note: See TracBrowser for help on using the repository browser.