source: trunk/src/param.cc @ 1061

Last change on this file since 1061 was 1061, checked in by MatthewWhiting, 12 years ago

Ticket #162 - A large refactoring of the Column-related code. Columns have moved to Outputs, and in a new namespace Catalogues. The interface has changed, using strings to record the type rather
than the enum. Also included is a new class CatalogueSpecification?, that is designed to hold a collection of Columns. This is not yet implemented - everything still uses the full & log column
vectors, and the code still passes the verification script.

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