source: trunk/src/param.cc @ 882

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

Getting the Cube::slice command working right. Still some issues with the WCS positions of the final objects.

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