source: trunk/src/param.cc @ 770

Last change on this file since 770 was 733, checked in by MatthewWhiting, 14 years ago

Moving the string manipulation functions to their own file in Utils/, and fixing the filname parameter reading so that it can read filenames with spaces in them.

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