source: trunk/src/param.cc @ 1066

Last change on this file since 1066 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
RevLine 
[299]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// -----------------------------------------------------------------------
[3]28#include <iostream>
29#include <iomanip>
30#include <fstream>
31#include <sstream>
32#include <string>
[534]33#include <algorithm>
[205]34#include <stdlib.h>
[269]35#include <ctype.h>
[3]36#include <math.h>
[410]37#include <unistd.h>
[393]38#include <duchamp/param.hh>
39#include <duchamp/fitsHeader.hh>
40#include <duchamp/duchamp.hh>
[420]41#include <duchamp/pgheader.hh>
[393]42#include <duchamp/ATrous/filter.hh>
43#include <duchamp/Utils/utils.hh>
44#include <duchamp/Utils/Section.hh>
[916]45#include <duchamp/Utils/VOParam.hh>
[1061]46#include <duchamp/Outputs/columns.hh>
[3]47
[378]48namespace duchamp
[309]49{
[882]50  const std::string defaultSection = "[*,*,*]";
[309]51
[378]52  /****************************************************************/
53  ///////////////////////////////////////////////////
54  //// Accessor Functions for Parameter class:
55  ///////////////////////////////////////////////////
56  Param::~Param()
57  {
[528]58    /// Deletes the offsets array if the sizeOffsets parameter is
59    /// positive.
[378]60    if(this->sizeOffsets>0) delete [] this->offsets;
61  }
[309]62
[378]63  Param::Param()
64  {
65    this->defaultValues();
66  }
[3]67
[378]68  void Param::defaultValues()
69  {
[528]70    /// Provides default intial values for the parameters. Note that
71    /// imageFile has no default value!
72
[378]73    // Input files
74    this->imageFile         = "";
75    this->flagSubsection    = false;
[882]76    this->pixelSec.setSection(defaultSection);
[378]77    this->flagReconExists   = false;
78    this->reconFile         = "";
79    this->flagSmoothExists  = false;
80    this->smoothFile        = "";
[475]81    this->usePrevious       = false;
82    this->objectList        = "";
[378]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";
[831]89    this->flagPlotSpectra   = true;
[378]90    this->spectraFile       = "duchamp-Spectra.ps";
[424]91    this->flagTextSpectra   = false;
92    this->spectraTextFile   = "duchamp-Spectra.txt";
[670]93    this->flagOutputMomentMap    = false;
94    this->fileOutputMomentMap    = "";
[379]95    this->flagOutputMask    = false;
[525]96    this->fileOutputMask    = "";
[521]97    this->flagMaskWithObjectNum = false;
[378]98    this->flagOutputSmooth  = false;
[525]99    this->fileOutputSmooth  = "";
[378]100    this->flagOutputRecon   = false;
[525]101    this->fileOutputRecon   = "";
[378]102    this->flagOutputResid   = false;
[525]103    this->fileOutputResid   = "";
[378]104    this->flagVOT           = false;
105    this->votFile           = "duchamp-Results.xml";
106    this->flagKarma         = false;
107    this->karmaFile         = "duchamp-Results.ann";
[446]108    this->annotationType    = "borders";
[378]109    this->flagMaps          = true;
110    this->detectionMap      = "duchamp-DetectionMap.ps";
111    this->momentMap         = "duchamp-MomentMap.ps";
112    this->flagXOutput       = true;
[1061]113    this->precFlux          = Catalogues::prFLUX;
114    this->precVel           = Catalogues::prVEL;
115    this->precSNR           = Catalogues::prSNR;
[378]116    // Cube related parameters
[845]117    this->flagBlankPix      = false;
[378]118    this->blankPixValue     = -8.00061;
119    this->blankKeyword      = 1;
120    this->bscaleKeyword     = -8.00061;
121    this->bzeroKeyword      = 0.;
[434]122    this->newFluxUnits      = "";
[378]123    // Milky-Way parameters
124    this->flagMW            = false;
125    this->maxMW             = 112;
126    this->minMW             = 75;
[788]127    this->areaBeam          = 0.;
128    this->fwhmBeam          = 0.;
[791]129    this->beamAsUsed.empty();
[686]130    this->searchType        = "spatial";
[378]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;
[458]149    this->growthCut         = 3.;
[461]150    this->flagUserGrowthThreshold = false;
151    this->growthThreshold   = 0.;
[378]152    // FDR analysis         
153    this->flagFDR           = false;
154    this->alphaFDR          = 0.01;
[543]155    this->FDRnumCorChan     = 2;
[378]156    // Other detection     
157    this->flagStatSec       = false;
[882]158    this->statSec.setSection(defaultSection);
[385]159    this->flagRobustStats   = true;
[1025]160    this->snrCut            = 5.;
[378]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.;
[1026]176    this->reconConvergence  = 0.005;
[378]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;
[720]185    this->minVoxels         = 4;
[672]186    this->flagRejectBeforeMerge = false;
[691]187    this->flagTwoStageMerging = true;
[378]188    // Input-Output related
189    this->spectralMethod    = "peak";
[948]190    this->spectralType      = "";
191    this->restFrequency     = -1.;
192    this->restFrequencyUsed = false;
[949]193    this->spectralUnits     = "";
[378]194    this->pixelCentre       = "centroid";
[571]195    this->sortingParam      = "vel";
[378]196    this->borders           = true;
197    this->blankEdge         = true;
198    this->verbose           = true;
[419]199  }
[204]200
[378]201  Param::Param (const Param& p)
202  {
203    operator=(p);
[309]204  }
[137]205
[378]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;
[475]215    this->smoothFile        = p.smoothFile;     
216    this->usePrevious       = p.usePrevious;
217    this->objectList        = p.objectList;
[378]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;
[882]223    this->flagPlotSpectra   = p.flagPlotSpectra;
[378]224    this->spectraFile       = p.spectraFile;   
[424]225    this->flagTextSpectra   = p.flagTextSpectra;   
226    this->spectraTextFile   = p.spectraTextFile;   
[670]227    this->flagOutputMomentMap    = p.flagOutputMomentMap;
228    this->fileOutputMomentMap    = p.fileOutputMomentMap;
[379]229    this->flagOutputMask    = p.flagOutputMask;
[525]230    this->fileOutputMask    = p.fileOutputMask;
[521]231    this->flagMaskWithObjectNum = p.flagMaskWithObjectNum;
[378]232    this->flagOutputSmooth  = p.flagOutputSmooth;
[525]233    this->fileOutputSmooth  = p.fileOutputSmooth;
[378]234    this->flagOutputRecon   = p.flagOutputRecon;
[525]235    this->fileOutputRecon   = p.fileOutputRecon;
[378]236    this->flagOutputResid   = p.flagOutputResid;
[525]237    this->fileOutputResid   = p.fileOutputResid;
[378]238    this->flagVOT           = p.flagVOT;         
239    this->votFile           = p.votFile;       
240    this->flagKarma         = p.flagKarma;     
241    this->karmaFile         = p.karmaFile;     
[446]242    this->annotationType    = p.annotationType;
[378]243    this->flagMaps          = p.flagMaps;       
244    this->detectionMap      = p.detectionMap;   
245    this->momentMap         = p.momentMap;     
246    this->flagXOutput       = p.flagXOutput;       
[438]247    this->precFlux          = p.precFlux;
248    this->precVel           = p.precVel;
249    this->precSNR           = p.precSNR;
[882]250    this->flagNegative      = p.flagNegative;
[378]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;   
[434]256    this->newFluxUnits      = p.newFluxUnits;
[378]257    this->flagMW            = p.flagMW;         
258    this->maxMW             = p.maxMW;         
259    this->minMW             = p.minMW;         
[662]260    this->areaBeam          = p.areaBeam;     
261    this->fwhmBeam          = p.fwhmBeam;     
[791]262    this->beamAsUsed        = p.beamAsUsed;
[686]263    this->searchType        = p.searchType;
[378]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;
[503]282    this->growthThreshold   = p.growthThreshold;
283    this->flagUserGrowthThreshold = p.flagUserGrowthThreshold;
[378]284    this->flagFDR           = p.flagFDR;
285    this->alphaFDR          = p.alphaFDR;
[543]286    this->FDRnumCorChan     = p.FDRnumCorChan;
[378]287    this->flagStatSec       = p.flagStatSec;
[385]288    this->statSec           = p.statSec;
289    this->flagRobustStats   = p.flagRobustStats;
[378]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;
[1026]304    this->reconConvergence  = p.reconConvergence;
[378]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;
[720]312    this->minVoxels         = p.minVoxels;
[691]313    this->flagRejectBeforeMerge = p.flagRejectBeforeMerge;
314    this->flagTwoStageMerging = p.flagTwoStageMerging;
[378]315    this->spectralMethod    = p.spectralMethod;
[948]316    this->spectralType      = p.spectralType;
317    this->restFrequency     = p.restFrequency;
318    this->restFrequencyUsed = p.restFrequencyUsed;
[378]319    this->spectralUnits     = p.spectralUnits;
320    this->pixelCentre       = p.pixelCentre;
[571]321    this->sortingParam      = p.sortingParam;
[378]322    this->borders           = p.borders;
[571]323    this->blankEdge         = p.blankEdge;
[378]324    this->verbose           = p.verbose;
325    return *this;
326  }
327  //--------------------------------------------------------------------
[266]328
[698]329  OUTCOME Param::getopts(int argc, char ** argv, std::string progname)
[378]330  {
[528]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.
[378]336
[698]337    OUTCOME returnValue = FAILURE;
[378]338    if(argc==1){
[474]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;
[378]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){
[913]354            DUCHAMPERROR(progname,"Could not open parameter file " << file);
[378]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 :
[474]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;
[378]374          break;
[266]375        }
376      }
[378]377      if(changeX){
378        if(returnValue == SUCCESS) this->setFlagXOutput(false);
379        else {
[913]380          DUCHAMPERROR(progname, "You need to specify either a parameter file or FITS image.\n");
[378]381          std::cout << "\n" << ERR_USAGE_MSG;
382        }
[294]383      }
384    }
[378]385    return returnValue;
[266]386  }
[378]387  //--------------------------------------------------------------------
[266]388
[378]389  bool Param::isBlank(float &value)
390  {
[528]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
[378]396    return this->flagBlankPix &&
397      (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
[419]398  }
[266]399
[1000]400  bool *Param::makeBlankMask(float *array, size_t size)
[378]401  {
[528]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
[378]406    bool *mask = new bool[size];
[1000]407    for(size_t i=0;i<size;i++) mask[i] = !this->isBlank(array[i]);
[378]408    return mask;
409  }
[275]410
411
[1000]412  bool *Param::makeStatMask(float *array, size_t *dim)
[506]413  {
[528]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
[506]419    bool *mask = new bool[dim[0]*dim[1]*dim[2]];
[1000]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];
[506]424          mask[i] = !this->isBlank(array[i]) && !this->isInMW(z) && this->isStatOK(x,y,z);
425        }
426      }
427    }
428    return mask;
429  }
430
431
[378]432  bool Param::isInMW(int z)
433  {
[528]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
[673]441    return ( this->flagMW && (z>=this->getMinMW()) && (z<=this->getMaxMW()) );
[378]442  }
[266]443
[378]444  bool Param::isStatOK(int x, int y, int z)
445  {
[913]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.
[528]455
[272]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);
[419]463  }
[266]464
[475]465  std::vector<int> Param::getObjectRequest()
466  {
[528]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
[475]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,',');
[623]476      for(size_t i=0;i<tmp.size();i++) if(tmp[i]=='-') tmp[i]=' ';
[475]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  {
[528]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
[475]499    std::vector<int> objectChoices = this->getObjectRequest();
500    int maxNum = *std::max_element(objectChoices.begin(), objectChoices.end());
501    std::vector<bool> choices(maxNum,false);
[623]502    for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++)
503      choices[*obj-1] = true;
[475]504    return choices;
505  }
506
507  std::vector<bool> Param::getObjectChoices(int numObjects)
508  {
[528]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
[475]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);
[623]524      for(std::vector<int>::iterator obj = objectChoices.begin();obj!=objectChoices.end();obj++)
525        if(*obj<=numObjects) choices[*obj-1] = true;
[475]526      return choices;
527    }
528  }
529
[378]530  /****************************************************************/
[528]531  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
532  /// / Other Functions using the  Parameter class:
533  /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
[3]534
[698]535  OUTCOME Param::readParams(std::string paramfile)
[378]536  {
[528]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
[839]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
[378]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()){
[3]560
[378]561      if(line[0]!='#'){
562        std::stringstream ss;
563        ss.str(line);
564        std::string arg;
565        ss >> arg;
566        arg = makelower(arg);
[733]567        if(arg=="imagefile")       this->imageFile = readFilename(ss);
[378]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);
[839]574        if(arg=="beamarea")        this->areaBeam = readFval(ss);
575        if(arg=="beamfwhm")        this->fwhmBeam = readFval(ss);
[475]576        if(arg=="useprevious")     this->usePrevious = readFlag(ss);
577        if(arg=="objectlist")      this->objectList = readSval(ss);
[71]578
[378]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);
[733]583        if(arg=="headerfile")      this->headerFile = readFilename(ss);
[831]584        if(arg=="flagplotspectra") this->flagPlotSpectra = readFlag(ss);
[733]585        if(arg=="spectrafile")     this->spectraFile = readFilename(ss);
[424]586        if(arg=="flagtextspectra") this->flagTextSpectra = readFlag(ss);
[733]587        if(arg=="spectratextfile") this->spectraTextFile = readFilename(ss);
[670]588        if(arg=="flagoutputmomentmap")  this->flagOutputMomentMap = readFlag(ss);
[733]589        if(arg=="fileoutputmomentmap")  this->fileOutputMomentMap = readFilename(ss);
[379]590        if(arg=="flagoutputmask")  this->flagOutputMask = readFlag(ss);
[733]591        if(arg=="fileoutputmask")  this->fileOutputMask = readFilename(ss);
[521]592        if(arg=="flagmaskwithobjectnum") this->flagMaskWithObjectNum = readFlag(ss);
[378]593        if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
[733]594        if(arg=="fileoutputsmooth")this->fileOutputSmooth = readFilename(ss);
[378]595        if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
[733]596        if(arg=="fileoutputrecon") this->fileOutputRecon = readFilename(ss);
[378]597        if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
[733]598        if(arg=="fileoutputresid") this->fileOutputResid = readFilename(ss);
[378]599        if(arg=="flagvot")         this->flagVOT = readFlag(ss);
[733]600        if(arg=="votfile")         this->votFile = readFilename(ss);
[378]601        if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
[733]602        if(arg=="karmafile")       this->karmaFile = readFilename(ss);
[446]603        if(arg=="annotationtype")  this->annotationType = readSval(ss);
[378]604        if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
[733]605        if(arg=="detectionmap")    this->detectionMap = readFilename(ss);
606        if(arg=="momentmap")       this->momentMap = readFilename(ss);
[378]607        if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
[434]608        if(arg=="newfluxunits")    this->newFluxUnits = readSval(ss);
[438]609        if(arg=="precflux")        this->precFlux = readIval(ss);
610        if(arg=="precvel")         this->precVel = readIval(ss);
611        if(arg=="precsnr")         this->precSNR = readIval(ss);
[3]612
[378]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);
[442]617        if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
[691]618        if(arg=="searchtype")      this->searchType = readSval(ss);
[71]619
[442]620        if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
[378]621        if(arg=="minpix")          this->minPix = readIval(ss);
622        if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
623        if(arg=="growthcut")       this->growthCut = readFval(ss);
[461]624        if(arg=="growththreshold"){
625          this->growthThreshold = readFval(ss);
626          this->flagUserGrowthThreshold = true;
627        }
[71]628
[378]629        if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
630        if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
[543]631        if(arg=="fdrnumcorchan")   this->FDRnumCorChan = readIval(ss);
[378]632        if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
633        if(arg=="statsec")         this->statSec.setSection(readSval(ss));
[385]634        if(arg=="flagrobuststats") this->flagRobustStats = readFlag(ss);
[378]635        if(arg=="snrcut")          this->snrCut = readFval(ss);
636        if(arg=="threshold"){
637          this->threshold = readFval(ss);
638          this->flagUserThreshold = true;
639        }
[201]640     
[378]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);
[103]647
[378]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);
[1026]653        if(arg=="reconconvergence") this->reconConvergence = readFval(ss);
654        if(arg=="filtercode")      this->filterCode = readIval(ss);
[71]655
[378]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);
[720]660        if(arg=="minvoxels")       this->minVoxels = readIval(ss);
[691]661        if(arg=="flagrejectbeforemerge") this->flagRejectBeforeMerge = readFlag(ss);
662        if(arg=="flagtwostagemerging") this->flagTwoStageMerging = readFlag(ss);
[71]663
[378]664        if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
[948]665        if(arg=="spectraltype")    this->spectralType = readSval(ss);
666        if(arg=="restfrequency")   this->restFrequency = readFval(ss);
[949]667        if(arg=="spectralunits")   this->spectralUnits = readSval(ss);
[378]668        if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
[571]669        if(arg=="sortingparam")    this->sortingParam = makelower(readSval(ss));
[378]670        if(arg=="drawborders")     this->borders = readFlag(ss);
671        if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
672        if(arg=="verbose")         this->verbose = readFlag(ss);
[295]673
[378]674        // Dealing with deprecated parameters.
675        if(arg=="flagblankpix"){
676          this->flagTrim = readFlag(ss);
[913]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));
[378]679        }
680        if(arg=="blankpixvalue"){
[913]681          DUCHAMPWARN("Reading parameters","The parameter blankPixValue is deprecated. This value is only taken from the FITS header.");
[378]682        }
[662]683        if(arg=="beamsize"){
[675]684          this->areaBeam = readFval(ss);
[913]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);
[662]687        }
[378]688
[295]689      }
[378]690    }
[295]691
[506]692    this->checkPars();
693
694    return SUCCESS;
695
696  }
697 
698  void Param::checkPars()
699  {
700
[882]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
[475]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
[420]712    // If pgplot was not included in the compilation, need to set flagXOutput to false
[831]713    if(!USE_PGPLOT){
714      if(this->flagXOutput || this->flagMaps || this->flagPlotSpectra)
[913]715        DUCHAMPWARN("Reading parameters","PGPlot has not been enabled, so setting flagXOutput, flagMaps and flagPlotSpectra to false.");
[831]716      this->flagXOutput = false;
717      this->flagMaps = false;
718      this->flagPlotSpectra = false;
719    }
[420]720
[438]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
[686]726    // Can only have "spatial" or "spectral" as search types
727    if(this->searchType != "spatial" && this->searchType != "spectral"){
[913]728      DUCHAMPWARN("Reading parameters","You have requested a search type of \""<<this->searchType<<"\" -- Only \"spectral\" and \"spatial\" are accepted, so setting to \"spatial\".");
[686]729      this->searchType = "spatial";
730    }
731
[378]732    // The wavelet reconstruction takes precendence over the smoothing.
733    if(this->flagATrous) this->flagSmooth = false;
734
[1026]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
[461]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){
[913]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.");
[461]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){
[913]773        DUCHAMPWARN("Reading parameters","You have specified a manual search threshold, so we don't need to use the FDR method. Setting \"flagFDR=false\".");
[461]774        this->flagFDR = false;
775      }
776
777    }   
778
[537]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) ) ){
[913]786        errmsg << "Your \"growthThreshold\" parameter" << this->growthThreshold <<" is larger than your \"threshold\"" << this->threshold;
[537]787        doWarn = true;
788      }
789     
790      if(!this->flagUserThreshold &&
791         (this->snrCut < this->growthCut)) {
[913]792        errmsg << "Your \"growthCut\" parameter " << this->growthCut << " is larger than your \"snrCut\"" << this->snrCut;
[537]793        doWarn = true;
794      }
795
[913]796      if(doWarn){
797        DUCHAMPWARN("Reading parameters",errmsg);
798        DUCHAMPWARN("Reading parameters","The growth function is being turned off.");
[537]799
[913]800      }
[537]801    }
802
[446]803    // Make sure the annnotationType is an acceptable option -- default is "borders"
804    if((this->annotationType != "borders") && (this->annotationType!="circles")){
[913]805      DUCHAMPWARN("Reading parameters","The requested value of the parameter annotationType, \"" << this->annotationType << "\", is invalid -- changing to \"borders\".");
[446]806      this->annotationType = "borders";
807    }
808     
[378]809    // Make sure smoothType is an acceptable type -- default is "spectral"
810    if((this->smoothType!="spectral")&&
811       (this->smoothType!="spatial")){
[913]812      DUCHAMPWARN("Reading parameters","The requested value of the parameter smoothType, \"" << this->smoothType << "\", is invalid -- changing to \"spectral\".");
[378]813      this->smoothType = "spectral";
[3]814    }
[378]815    // If kernMin has not been given, or is negative, make it equal to kernMaj
816    if(this->kernMin < 0) this->kernMin = this->kernMaj;
[272]817
[378]818    // Make sure spectralMethod is an acceptable type -- default is "peak"
819    if((this->spectralMethod!="peak")&&
820       (this->spectralMethod!="sum")){
[913]821      DUCHAMPWARN("Reading parameters","The requested value of the parameter spectralMethod, \"" << this->spectralMethod << "\", is invalid -- changing to \"peak\".");
[378]822      this->spectralMethod = "peak";
823    }
[232]824
[913]825    // make sure pixelCentre is an acceptable type -- default is "peak"
[378]826    if((this->pixelCentre!="centroid")&&
827       (this->pixelCentre!="average") &&
828       (this->pixelCentre!="peak")       ){
[913]829      DUCHAMPWARN("Reading parameters","The requested value of the parameter pixelCentre, \"" << this->pixelCentre << "\", is invalid -- changing to \"centroid\".");
[378]830      this->pixelCentre = "centroid";
831    }
[275]832
[571]833    // Make sure sortingParam is an acceptable type -- default is "vel"
834    bool OK = false;
[955]835    int loc=(this->sortingParam[0]=='-') ? 1 : 0;
[571]836    for(int i=0;i<numSortingParamOptions;i++)
[955]837      OK = OK || this->sortingParam.substr(loc)==sortingParamOptions[i];
[571]838    if(!OK){
[913]839      DUCHAMPWARN("Reading parameters","The requested value of the parameter sortingParam, \"" << this->sortingParam << "\", is invalid. -- changing to \"vel\".");
[571]840      this->sortingParam = "vel";
841    }
[942]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    }
[571]848     
[265]849  }
850
[910]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
[664]867  void recordParameters(std::ostream& theStream, std::string paramName, std::string paramDesc, std::string paramValue)
868  {
869   
[716]870    const int width = 56;
871    int widthText = width - paramName.size();
[265]872
[664]873    theStream << std::setw(widthText) << paramDesc
[716]874              << setiosflags(std::ios::right) << paramName
[664]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
[378]888  std::ostream& operator<< ( std::ostream& theStream, Param& par)
889  {
[528]890    /// Print out the parameter set in a formatted, easy to read style.
891    /// Lists the parameters, a description of them, and their value.
[3]892
[378]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())
[664]899      recordParam(theStream, "[imageFile]", "Image to be analysed", par.getImageFile()<<par.getSubsection());
[378]900    else
[664]901      recordParam(theStream, "[imageFile]", "Image to be analysed", par.getImageFile());
[948]902    if(par.getFlagRestFrequencyUsed()){
903      recordParam(theStream, "[restFrequency]","Rest frequency as used", par.getRestFrequency());
904    }
[378]905    if(par.getFlagReconExists() && par.getFlagATrous()){
[664]906      recordParam(theStream, "[reconExists]", "Reconstructed array exists?", stringize(par.getFlagReconExists()));
907      recordParam(theStream, "[reconFile]", "FITS file containing reconstruction", par.getReconFile());
[378]908    }
909    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
[664]910      recordParam(theStream, "[smoothExists]", "Smoothed array exists?", stringize(par.getFlagSmoothExists()));
911      recordParam(theStream, "[smoothFile]", "FITS file containing smoothed array", par.getSmoothFile());
[378]912    }
[788]913    recordParam(theStream, "[logFile]", "Intermediate Logfile", par.logFile);
[664]914    recordParam(theStream, "[outFile]", "Final Results file", par.getOutFile());
915    if(par.getFlagSeparateHeader()){
916      recordParam(theStream, "[headerFile]", "Header for results file", par.getHeaderFile());
917    }
[831]918    if(USE_PGPLOT && par.getFlagPlotSpectra()){
919      recordParam(theStream, "[spectraFile]", "Spectrum file", par.getSpectraFile());
920    }
[424]921    if(par.getFlagTextSpectra()){
[664]922      recordParam(theStream, "[spectraTextFile]", "Text file with ascii spectral data", par.getSpectraTextFile());
[424]923    }
[378]924    if(par.getFlagVOT()){
[664]925      recordParam(theStream, "[votFile]", "VOTable file", par.getVOTFile());
[378]926    }
927    if(par.getFlagKarma()){
[664]928      recordParam(theStream, "[karmaFile]", "Karma annotation file" , par.getKarmaFile());
[378]929    }
[831]930    if(USE_PGPLOT && par.getFlagMaps()){
[664]931      recordParam(theStream, "[momentMap]", "0th Moment Map", par.getMomentMap());
932      recordParam(theStream, "[detectionMap]", "Detection Map", par.getDetectionMap());
[378]933    }
[831]934    if(USE_PGPLOT){
935      recordParam(theStream, "[flagXOutput]", "Display a map in a pgplot xwindow?", stringize(par.getFlagXOutput()));
936    }
[664]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()));
[378]940    }                                                 
[664]941    if(par.getFlagSmooth()){   
942      recordParam(theStream, "[flagOutputSmooth]", "Saving smoothed cube?", fileOption(par.getFlagOutputSmooth(),par.outputSmoothFile()));
[378]943    }                                                 
[664]944    recordParam(theStream, "[flagOutputMask]", "Saving mask cube?", fileOption(par.getFlagOutputMask(),par.outputMaskFile()));
[670]945    recordParam(theStream, "[flagOutputMask]", "Saving 0th moment to FITS file?", fileOption(par.getFlagOutputMomentMap(),par.outputMomentMapFile()));
[664]946
[378]947    theStream  <<"------"<<std::endl;
[664]948
[686]949    recordParam(theStream, "[searchType]", "Type of searching performed", par.getSearchType());
[378]950    if(par.getFlagBlankPix()){
[664]951      recordParam(theStream, "", "Blank Pixel Value", par.getBlankPixVal());
[275]952    }
[664]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()));
[378]956    if(par.getFlagMW()){
[673]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());
[348]959    }
[791]960    if(par.beamAsUsed.origin()==EMPTY){  // No beam in FITS file and no information provided
[788]961      recordParam(theStream, "", "Area of Beam", "No beam");
[675]962    }
[791]963    else if(par.beamAsUsed.origin()==HEADER){ // Report beam size from FITS file
[795]964      recordParam(theStream, "", "Area of Beam (pixels)", par.beamAsUsed.area() << "   (beam: " << par.beamAsUsed.maj() << " x " << par.beamAsUsed.min() <<" pixels)");
[675]965    }
[791]966    else if(par.beamAsUsed.origin()==PARAM){ // Report beam size requested in parameter set input
[788]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{
[913]971      recordParam(theStream, "[beam info]", "Size & shape of beam", "No information available!");
[788]972    }
[664]973    recordParam(theStream, "[flagBaseline]", "Removing baselines before search?", stringize(par.getFlagBaseline()));
974    recordParam(theStream, "[flagSmooth]", "Smoothing data prior to searching?", stringize(par.getFlagSmooth()));
[378]975    if(par.getFlagSmooth()){           
[664]976      recordParam(theStream, "[smoothType]", "Type of smoothing", par.getSmoothType());
[378]977      if(par.getSmoothType()=="spectral")
[664]978        recordParam(theStream, "[hanningWidth]", "Width of hanning filter", par.getHanningWidth());
[378]979      else{
[664]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());
[378]983      }
[348]984    }
[664]985    recordParam(theStream, "[flagATrous]", "Using A Trous reconstruction?", stringize(par.getFlagATrous()));
[378]986    if(par.getFlagATrous()){                           
[664]987      recordParam(theStream, "[reconDim]", "Number of dimensions in reconstruction", par.getReconDim());
[378]988      if(par.getMaxScale()>0){
[664]989        recordParam(theStream, "[scaleMin-scaleMax]", "Scales used in reconstruction", par.getMinScale()<<"-"<<par.getMaxScale());
[378]990      }
991      else{
[664]992        recordParam(theStream, "[scaleMin]", "Minimum scale in reconstruction", par.getMinScale());
[378]993      }
[664]994      recordParam(theStream, "[snrRecon]", "SNR Threshold within reconstruction", par.getAtrousCut());
[1026]995      recordParam(theStream, "[reconConvergence]", "Residual convergence criterion", par.getReconConvergence());
[664]996      recordParam(theStream, "[filterCode]", "Filter being used for reconstruction", par.getFilterCode()<<" ("<<par.getFilterName()<<")");
[378]997    }                                                 
[664]998    recordParam(theStream, "[flagRobustStats]", "Using Robust statistics?", stringize(par.getFlagRobustStats()));
[378]999    if(par.getFlagStatSec()){
[664]1000      recordParam(theStream, "[statSec]", "Section used by statistics calculation", par.statSec.getSection());
[189]1001    }
[664]1002    recordParam(theStream, "[flagFDR]", "Using FDR analysis?", stringize(par.getFlagFDR()));
[378]1003    if(par.getFlagFDR()){                                     
[664]1004      recordParam(theStream, "[alphaFDR]", "Alpha value for FDR analysis", par.getAlpha());
1005      recordParam(theStream, "[FDRnumCorChan]", "Number of correlated channels for FDR", par.getFDRnumCorChan());
[378]1006    }                                                 
1007    else {
1008      if(par.getFlagUserThreshold()){
[664]1009        recordParam(theStream, "[threshold]", "Detection Threshold", par.getThreshold());
[378]1010      }
1011      else{
[664]1012        recordParam(theStream, "[snrCut]", "SNR Threshold (in sigma)", par.getCut());
[378]1013      }
[189]1014    }
[664]1015    recordParam(theStream, "[minPix]", "Minimum # Pixels in a detection", par.getMinPix());
1016    recordParam(theStream, "[minChannels]", "Minimum # Channels in a detection", par.getMinChannels());
[720]1017    recordParam(theStream, "[minVoxels]", "Minimum # Voxels in a detection", par.getMinVoxels());
[664]1018    recordParam(theStream, "[flagGrowth]", "Growing objects after detection?", stringize(par.getFlagGrowth()));
[378]1019    if(par.getFlagGrowth()) {                         
[503]1020      if(par.getFlagUserGrowthThreshold()){
[664]1021        recordParam(theStream, "[growthThreshold]", "Threshold for growth", par.getGrowthThreshold());
[503]1022      }
1023      else{
[664]1024        recordParam(theStream, "[growthCut]", "SNR Threshold for growth", par.getGrowthCut());
[503]1025      }
[378]1026    }
[664]1027    recordParam(theStream, "[flagAdjacent]", "Using Adjacent-pixel criterion?", stringize(par.getFlagAdjacent()));
[378]1028    if(!par.getFlagAdjacent()){
[664]1029      recordParam(theStream, "[threshSpatial]", "Max. spatial separation for merging", par.getThreshS());
[378]1030    }
[664]1031    recordParam(theStream, "[threshVelocity]", "Max. velocity separation for merging", par.getThreshV());
[672]1032    recordParam(theStream, "[flagRejectBeforeMerge]", "Reject objects before merging?", stringize(par.getFlagRejectBeforeMerge()));
[691]1033    recordParam(theStream, "[flagTwoStageMerging]", "Merge objects in two stages?", stringize(par.getFlagTwoStageMerging()));
[664]1034    recordParam(theStream, "[spectralMethod]", "Method of spectral plotting", par.getSpectralMethod());
1035    recordParam(theStream, "[pixelCentre]", "Type of object centre used in results", par.getPixelCentre());
1036
[1049]1037    theStream  <<"--------------------\n";
[378]1038    theStream  << std::setfill(' ');
1039    theStream.unsetf(std::ios::left);
1040    //  theStream.unsetf(std::ios::boolalpha);
1041    return theStream;
[3]1042  }
1043
[916]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(),""));
[958]1048    vopars.push_back(VOParam("flagSubsection","meta.code","boolean",this->flagSubsection,0,""));
[916]1049    if(this->flagSubsection)
1050      vopars.push_back(VOParam("subsection","","char",this->pixelSec.getSection(),this->pixelSec.getSection().size(),""));
[958]1051    vopars.push_back(VOParam("flagStatSec","meta.code","boolean",this->flagStatSec,0,""));
[916]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(),""));
[120]1060
[916]1061    vopars.push_back(VOParam("searchType","meta.note","char",this->searchType,this->searchType.size(),""));
[958]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,""));
[916]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    }
[958]1076    vopars.push_back(VOParam("flagGrowth","meta.code","boolean",this->flagGrowth,0,""));
[916]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,""));
[958]1086    vopars.push_back(VOParam("flagAdjacent","meta.code","boolean",this->flagAdjacent,0,""));
[916]1087    if(!this->flagAdjacent)
1088      vopars.push_back(VOParam("threshSpatial","","float",this->threshSpatial,0,""));
1089    vopars.push_back(VOParam("threshVelocity","","float",this->threshSpatial,0,""));
[958]1090    vopars.push_back(VOParam("flagRejectBeforeMerge","","boolean",this->flagRejectBeforeMerge,0,""));
1091    vopars.push_back(VOParam("flagTwoStageMerging","","boolean",this->flagTwoStageMerging,0,""));
[916]1092    vopars.push_back(VOParam("pixelCentre","","char",this->pixelCentre,this->pixelCentre.size(),""));
[958]1093    vopars.push_back(VOParam("flagSmooth","meta.code","boolean",this->flagSmooth,0,""));
[916]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    }
[958]1104    vopars.push_back(VOParam("flagATrous","meta.code","boolean",this->flagATrous,0,""));
[916]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,""));
[1026]1111      vopars.push_back(VOParam("reconConvergence","","float",this->reconConvergence,0,""));
[916]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    }
[948]1120    if(this->restFrequencyUsed){
1121      vopars.push_back(VOParam("restFrequency","em.freq","float",this->restFrequency,0,"Hz"));
1122    }
[916]1123
1124    return vopars;
1125
1126  }
1127
1128
1129
[378]1130  void Param::copyHeaderInfo(FitsHeader &head)
1131  {
[528]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.
[112]1136
[378]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  }
[112]1143
[379]1144  std::string Param::outputMaskFile()
1145  {
[528]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
[525]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;
[379]1160  }
1161
[670]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
[378]1179  std::string Param::outputSmoothFile()
1180  {
[528]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
[525]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;
[378]1206  }
[208]1207
[378]1208  std::string Param::outputReconFile()
1209  {
[528]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
[525]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
[1027]1225         << "-"       << this->scaleMax
[1026]1226         << "-"       << this->reconConvergence
[525]1227         << ".fits";
1228      return ss.str();
1229    }
1230    else return this->fileOutputRecon;
[378]1231  }
[103]1232
[378]1233  std::string Param::outputResidFile()
1234  {
[528]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
[525]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
[1027]1250         << "-"       << this->scaleMax
[1026]1251         << "-"       << this->reconConvergence
[525]1252         << ".fits";
1253      return ss.str();
1254    }
1255    else return this->fileOutputResid;
[378]1256  }
1257
[103]1258}
Note: See TracBrowser for help on using the repository browser.