source: trunk/src/param.cc @ 931

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

Addressing #135, and implementing the new approach, whereby all the relevant parameters are written to the VOTable. There is a new Param method that creates a vector list of VOParams. Have added the new VOParam/VOField files to the Makefile

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