source: trunk/src/param.cc @ 379

Last change on this file since 379 was 379, checked in by MatthewWhiting, 17 years ago

Added in functionality to output a mask cube FITS file. Cube has values 1 where there is a detected object, and 0 elsewhere. Works in similar way to the reconCube or smoothCube.

File size: 40.0 KB
Line 
1// -----------------------------------------------------------------------
2// param.cc: Dealing with the set of parameters for Duchamp.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <iostream>
29#include <iomanip>
30#include <fstream>
31#include <sstream>
32#include <string>
33#include <stdlib.h>
34#include <ctype.h>
35#include <math.h>
36#include <param.hh>
37#include <fitsHeader.hh>
38#include <duchamp.hh>
39#include <ATrous/filter.hh>
40#include <Utils/utils.hh>
41#include <Utils/Section.hh>
42
43namespace duchamp
44{
45
46  /****************************************************************/
47  ///////////////////////////////////////////////////
48  //// Accessor Functions for Parameter class:
49  ///////////////////////////////////////////////////
50  Param::~Param()
51  {
52    /**
53     * Deletes the offsets array if the sizeOffsets parameter is
54     * positive.
55     */
56    if(this->sizeOffsets>0) delete [] this->offsets;
57  }
58
59  Param::Param()
60  {
61    this->defaultValues();
62  }
63
64  void Param::defaultValues()
65  {
66    /**
67     * Provides default intial values for the parameters. Note that
68     * imageFile has no default value!
69     */
70    std::string baseSection = "[*,*,*]";
71    // Input files
72    this->imageFile         = "";
73    this->flagSubsection    = false;
74    this->pixelSec.setSection(baseSection);
75    this->flagReconExists   = false;
76    this->reconFile         = "";
77    this->flagSmoothExists  = false;
78    this->smoothFile        = "";
79    // Output files
80    this->flagLog           = false;
81    this->logFile           = "duchamp-Logfile.txt";
82    this->outFile           = "duchamp-Results.txt";
83    this->flagSeparateHeader= false;
84    this->headerFile        = "duchamp-Results.hdr";
85    this->spectraFile       = "duchamp-Spectra.ps";
86    this->flagOutputMask    = false;
87    this->flagOutputSmooth  = false;
88    this->flagOutputRecon   = false;
89    this->flagOutputResid   = false;
90    this->flagVOT           = false;
91    this->votFile           = "duchamp-Results.xml";
92    this->flagKarma         = false;
93    this->karmaFile         = "duchamp-Results.ann";
94    this->flagMaps          = true;
95    this->detectionMap      = "duchamp-DetectionMap.ps";
96    this->momentMap         = "duchamp-MomentMap.ps";
97    this->flagXOutput       = true;
98    // Cube related parameters
99    this->flagBlankPix      = true;
100    this->blankPixValue     = -8.00061;
101    this->blankKeyword      = 1;
102    this->bscaleKeyword     = -8.00061;
103    this->bzeroKeyword      = 0.;
104    // Milky-Way parameters
105    this->flagMW            = false;
106    this->maxMW             = 112;
107    this->minMW             = 75;
108    this->numPixBeam        = 10.;
109    this->flagUsingBeam     = false;
110    // Trim-related         
111    this->flagTrim          = false;
112    this->hasBeenTrimmed    = false;
113    this->borderLeft        = 0;
114    this->borderRight       = 0;
115    this->borderBottom      = 0;
116    this->borderTop         = 0;
117    // Subsection offsets
118    this->sizeOffsets       = 0;
119    this->xSubOffset        = 0;
120    this->ySubOffset        = 0;
121    this->zSubOffset        = 0;
122    // Baseline related
123    this->flagBaseline      = false;
124    // Detection-related   
125    this->flagNegative      = false;
126    // Object growth       
127    this->flagGrowth        = false;
128    this->growthCut         = 2.;
129    // FDR analysis         
130    this->flagFDR           = false;
131    this->alphaFDR          = 0.01;
132    // Other detection     
133    this->flagStatSec       = false;
134    this->statSec.setSection(baseSection);
135    this->snrCut            = 3.;
136    this->threshold         = 0.;
137    this->flagUserThreshold = false;
138    // Smoothing
139    this->flagSmooth        = false;
140    this->smoothType        = "spectral";
141    this->hanningWidth      = 5;
142    this->kernMaj           = 3.;
143    this->kernMin           = -1.;
144    this->kernPA            = 0.;
145    // A trous reconstruction parameters
146    this->flagATrous        = false;
147    this->reconDim          = 1;
148    this->scaleMin          = 1;
149    this->scaleMax          = 0;
150    this->snrRecon          = 4.;
151    this->filterCode        = 1;
152    this->reconFilter.define(this->filterCode);
153    // Volume-merging parameters
154    this->flagAdjacent      = true;
155    this->threshSpatial     = 3.;
156    this->threshVelocity    = 7.;
157    this->minChannels       = 3;
158    this->minPix            = 2;
159    // Input-Output related
160    this->spectralMethod    = "peak";
161    this->spectralUnits     = "km/s";
162    this->pixelCentre       = "centroid";
163    this->borders           = true;
164    this->blankEdge         = true;
165    this->verbose           = true;
166  };
167
168  Param::Param (const Param& p)
169  {
170    operator=(p);
171  }
172
173  Param& Param::operator= (const Param& p)
174  {
175    if(this == &p) return *this;
176    this->imageFile         = p.imageFile;
177    this->flagSubsection    = p.flagSubsection;
178    this->pixelSec          = p.pixelSec;
179    this->flagReconExists   = p.flagReconExists;
180    this->reconFile         = p.reconFile;     
181    this->flagSmoothExists  = p.flagSmoothExists;
182    this->smoothFile        = p.smoothFile;     
183    this->flagLog           = p.flagLog;       
184    this->logFile           = p.logFile;       
185    this->outFile           = p.outFile;       
186    this->flagSeparateHeader= p.flagSeparateHeader;
187    this->headerFile        = p.headerFile;
188    this->spectraFile       = p.spectraFile;   
189    this->flagOutputMask    = p.flagOutputMask;
190    this->flagOutputSmooth  = p.flagOutputSmooth;
191    this->flagOutputRecon   = p.flagOutputRecon;
192    this->flagOutputResid   = p.flagOutputResid;
193    this->flagVOT           = p.flagVOT;         
194    this->votFile           = p.votFile;       
195    this->flagKarma         = p.flagKarma;     
196    this->karmaFile         = p.karmaFile;     
197    this->flagMaps          = p.flagMaps;       
198    this->detectionMap      = p.detectionMap;   
199    this->momentMap         = p.momentMap;     
200    this->flagXOutput       = p.flagXOutput;       
201    this->flagBlankPix      = p.flagBlankPix;   
202    this->blankPixValue     = p.blankPixValue; 
203    this->blankKeyword      = p.blankKeyword;   
204    this->bscaleKeyword     = p.bscaleKeyword; 
205    this->bzeroKeyword      = p.bzeroKeyword;   
206    this->flagMW            = p.flagMW;         
207    this->maxMW             = p.maxMW;         
208    this->minMW             = p.minMW;         
209    this->numPixBeam        = p.numPixBeam;     
210    this->flagTrim          = p.flagTrim;   
211    this->hasBeenTrimmed    = p.hasBeenTrimmed;   
212    this->borderLeft        = p.borderLeft;     
213    this->borderRight       = p.borderRight;   
214    this->borderBottom      = p.borderBottom;   
215    this->borderTop         = p.borderTop;     
216    if(this->sizeOffsets>0) delete [] this->offsets;
217    this->sizeOffsets       = p.sizeOffsets;
218    if(this->sizeOffsets>0){
219      this->offsets           = new long[this->sizeOffsets];
220      for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
221    }
222    this->xSubOffset        = p.xSubOffset;     
223    this->ySubOffset        = p.ySubOffset;     
224    this->zSubOffset        = p.zSubOffset;
225    this->flagBaseline      = p.flagBaseline;
226    this->flagNegative      = p.flagNegative;
227    this->flagGrowth        = p.flagGrowth;
228    this->growthCut         = p.growthCut;
229    this->flagFDR           = p.flagFDR;
230    this->alphaFDR          = p.alphaFDR;
231    this->flagStatSec       = p.flagStatSec;
232    this->statSec           = p.statSec;
233    this->snrCut            = p.snrCut;
234    this->threshold         = p.threshold;
235    this->flagUserThreshold = p.flagUserThreshold;
236    this->flagSmooth        = p.flagSmooth;
237    this->smoothType        = p.smoothType;
238    this->hanningWidth      = p.hanningWidth;
239    this->kernMaj           = p.kernMaj;
240    this->kernMin           = p.kernMin;
241    this->kernPA            = p.kernPA;
242    this->flagATrous        = p.flagATrous;
243    this->reconDim          = p.reconDim;
244    this->scaleMin          = p.scaleMin;
245    this->scaleMax          = p.scaleMax;
246    this->snrRecon          = p.snrRecon;
247    this->filterCode        = p.filterCode;
248    this->reconFilter       = p.reconFilter;
249    this->flagAdjacent      = p.flagAdjacent;
250    this->threshSpatial     = p.threshSpatial;
251    this->threshVelocity    = p.threshVelocity;
252    this->minChannels       = p.minChannels;
253    this->minPix            = p.minPix;
254    this->spectralMethod    = p.spectralMethod;
255    this->spectralUnits     = p.spectralUnits;
256    this->pixelCentre       = p.pixelCentre;
257    this->borders           = p.borders;
258    this->verbose           = p.verbose;
259    return *this;
260  }
261  //--------------------------------------------------------------------
262
263  int Param::getopts(int argc, char ** argv)
264  {
265    /** 
266     *   A function that reads in the command-line options, in a manner
267     *    tailored for use with the main Duchamp program.
268     *
269     *   \param argc The number of command line arguments.
270     *   \param argv The array of command line arguments.
271     */
272
273    int returnValue = FAILURE;
274    if(argc==1){
275      std::cout << ERR_USAGE_MSG;
276      returnValue = FAILURE;
277    }
278    else {
279      std::string file;
280      bool changeX = false;
281      this->defaultValues();
282      char c;
283      while( ( c = getopt(argc,argv,"p:f:hvx") )!=-1){
284        switch(c) {
285        case 'p':
286          file = optarg;
287          if(this->readParams(file)==FAILURE){
288            std::stringstream errmsg;
289            errmsg << "Could not open parameter file " << file << ".\n";
290            duchampError("Duchamp",errmsg.str());
291          }
292          else returnValue = SUCCESS;
293          break;
294        case 'f':
295          file = optarg;
296          this->imageFile = file;
297          returnValue = SUCCESS;
298          break;
299        case 'v':
300          std::cout << PROGNAME << " version " << VERSION << std::endl;
301          break;
302        case 'x':
303          changeX = true;
304          break;
305        case 'h':
306        default :
307          std::cout << ERR_USAGE_MSG;
308          break;
309        }
310      }
311      if(changeX){
312        if(returnValue == SUCCESS) this->setFlagXOutput(false);
313        else {
314          duchampError("Duchamp",
315                       "You need to specify either a parameter file or FITS image.\n");
316          std::cout << "\n" << ERR_USAGE_MSG;
317        }
318      }
319    }
320    return returnValue;
321  }
322  //--------------------------------------------------------------------
323
324  bool Param::isBlank(float &value)
325  {
326    /**
327     *  Tests whether the value passed as the argument is BLANK or not.
328     *  \param value Pixel value to be tested.
329     *  \return False if flagBlankPix is false. Else, compare to the
330     *  relevant FITS keywords, using integer comparison.
331     */
332    return this->flagBlankPix &&
333      (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
334  };
335
336  bool *Param::makeBlankMask(float *array, int size)
337  {
338    /**
339     *  This returns an array of bools, saying whether each pixel in the
340     *  given array is BLANK or not. If the pixel is BLANK, set mask to
341     *  false, else set to true. The array is allocated by the function.
342     */
343    bool *mask = new bool[size];
344    for(int i=0;i<size;i++) mask[i] = !this->isBlank(array[i]);
345    return mask;
346  }
347
348
349  bool Param::isInMW(int z)
350  {
351    /**
352     *  Tests whether we are flagging Milky Way channels, and if so
353     * whether the given channel number is in the Milky Way range. The
354     * channels are assumed to start at number 0. 
355     * \param z The channel number
356     * \return True if we are flagging Milky Way channels and z is in
357     *  the range.
358     */
359    return ( flagMW && (z>=minMW) && (z<=maxMW) );
360  }
361
362  bool Param::isStatOK(int x, int y, int z)
363  {
364    /**
365     * Test whether a given pixel position lies within the subsection
366     * given by the statSec parameter. Only tested if the flagSubsection
367     * parameter is true -- if it isn't, we just return true since all
368     * pixels are therefore available for statstical calculations.
369     * \param x X-value of pixel being tested.
370     * \param y Y-value of pixel being tested.
371     * \param z Z-value of pixel being tested.
372     * \return True if pixel is able to be used for statistical
373     * calculations. False otherwise.
374     */
375    int xval=x,yval=y,zval=z;
376    if(flagSubsection){
377      xval += pixelSec.getStart(0);
378      yval += pixelSec.getStart(1);
379      zval += pixelSec.getStart(2);
380    }
381    return !flagStatSec || statSec.isInside(xval,yval,zval);
382  };
383
384  /****************************************************************/
385  ///////////////////////////////////////////////////
386  //// Other Functions using the  Parameter class:
387  ///////////////////////////////////////////////////
388
389  std::string makelower( std::string s )
390  {
391    // "borrowed" from Matt Howlett's 'fred'
392    std::string out = "";
393    for( int i=0; i<s.size(); ++i ) {
394      out += tolower(s[i]);
395    }
396    return out;
397  }
398
399  inline std::string stringize(bool b)
400  {
401    /**
402     * Convert a bool variable to the textual equivalent.
403     * \return A std::string with the english equivalent of the bool.
404     */
405    std::string output;
406    if(b) output="true";
407    else output="false";
408    return output;
409  }
410
411  inline bool boolify( std::string s )
412  {
413    /**
414     *  Convert a std::string to a bool variable:
415     *  "1" and "true" get converted to true;
416     *  "0" and "false" (and anything else) get converted to false.
417     * \return The bool equivalent of the string.
418     */
419    if((s=="1") || (makelower(s)=="true")) return true;
420    else if((s=="0") || (makelower(s)=="false")) return false;
421    else return false;
422  }
423
424  inline std::string readSval(std::stringstream& ss)
425  {
426    std::string val; ss >> val; return val;
427  }
428
429  inline bool readFlag(std::stringstream& ss)
430  {
431    std::string val; ss >> val; return boolify(val);
432  }
433
434  inline float readFval(std::stringstream& ss)
435  {
436    float val; ss >> val; return val;
437  }
438
439  inline int readIval(std::stringstream& ss)
440  {
441    int val; ss >> val; return val;
442  }
443
444  int Param::readParams(std::string paramfile)
445  {
446    /**
447     * The parameters are read in from a disk file, on the assumption that each
448     *  line of the file has the format "parameter value" (eg. alphafdr 0.1)
449     *
450     * The case of the parameter name does not matter, nor does the
451     * formatting of the spaces (it can be any amount of whitespace or
452     * tabs).
453     *
454     * \param paramfile A std::string containing the parameter filename.
455     *
456     * \return FAILURE if the parameter file does not exist. SUCCESS if
457     * it is able to read it.
458     */
459    std::ifstream fin(paramfile.c_str());
460    if(!fin.is_open()) return FAILURE;
461    std::string line;
462    while( !std::getline(fin,line,'\n').eof()){
463
464      if(line[0]!='#'){
465        std::stringstream ss;
466        ss.str(line);
467        std::string arg;
468        ss >> arg;
469        arg = makelower(arg);
470        if(arg=="imagefile")       this->imageFile = readSval(ss);
471        if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
472        if(arg=="subsection")      this->pixelSec.setSection(readSval(ss));
473        if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
474        if(arg=="reconfile")       this->reconFile = readSval(ss);
475        if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
476        if(arg=="smoothfile")      this->smoothFile = readSval(ss);
477
478        if(arg=="flaglog")         this->flagLog = readFlag(ss);
479        if(arg=="logfile")         this->logFile = readSval(ss);
480        if(arg=="outfile")         this->outFile = readSval(ss);
481        if(arg=="flagseparateheader") this->flagSeparateHeader = readFlag(ss);
482        if(arg=="headerfile")      this->headerFile = readSval(ss);
483        if(arg=="spectrafile")     this->spectraFile = readSval(ss);
484        if(arg=="flagoutputmask")  this->flagOutputMask = readFlag(ss);
485        if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
486        if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
487        if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
488        if(arg=="flagvot")         this->flagVOT = readFlag(ss);
489        if(arg=="votfile")         this->votFile = readSval(ss);
490        if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
491        if(arg=="karmafile")       this->karmaFile = readSval(ss);
492        if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
493        if(arg=="detectionmap")    this->detectionMap = readSval(ss);
494        if(arg=="momentmap")       this->momentMap = readSval(ss);
495        if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
496
497        if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
498        if(arg=="flagtrim")        this->flagTrim = readFlag(ss);
499        if(arg=="flagmw")          this->flagMW = readFlag(ss);
500        if(arg=="maxmw")           this->maxMW = readIval(ss);
501        if(arg=="minmw")           this->minMW = readIval(ss);
502        if(arg=="beamsize")        this->numPixBeam = readFval(ss);
503
504        if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
505        if(arg=="minpix")          this->minPix = readIval(ss);
506        if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
507        if(arg=="growthcut")       this->growthCut = readFval(ss);
508
509        if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
510        if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
511
512        if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
513        if(arg=="statsec")         this->statSec.setSection(readSval(ss));
514        if(arg=="snrcut")          this->snrCut = readFval(ss);
515        if(arg=="threshold"){
516          this->threshold = readFval(ss);
517          this->flagUserThreshold = true;
518        }
519     
520        if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
521        if(arg=="smoothtype")      this->smoothType = readSval(ss);
522        if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
523        if(arg=="kernmaj")         this->kernMaj = readFval(ss);
524        if(arg=="kernmin")         this->kernMin = readFval(ss);
525        if(arg=="kernpa")          this->kernPA = readFval(ss);
526
527        if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
528        if(arg=="recondim")        this->reconDim = readIval(ss);
529        if(arg=="scalemin")        this->scaleMin = readIval(ss);
530        if(arg=="scalemax")        this->scaleMax = readIval(ss);
531        if(arg=="snrrecon")        this->snrRecon = readFval(ss);
532        if(arg=="filtercode"){
533          this->filterCode = readIval(ss);
534          this->reconFilter.define(this->filterCode);
535        }
536
537        if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
538        if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
539        if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
540        if(arg=="minchannels")     this->minChannels = readIval(ss);
541
542        if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
543        if(arg=="spectralunits")   this->spectralUnits = makelower(readSval(ss));
544        if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
545        if(arg=="drawborders")     this->borders = readFlag(ss);
546        if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
547        if(arg=="verbose")         this->verbose = readFlag(ss);
548
549        // Dealing with deprecated parameters.
550        if(arg=="flagblankpix"){
551          this->flagTrim = readFlag(ss);
552          std::stringstream errmsg;
553          errmsg <<"The parameter flagBlankPix is deprecated. "
554                 <<"Please use the flagTrim parameter in future.\n"
555                 <<"Setting flagTrim = " << stringize(this->flagTrim) << ".\n";
556          duchampWarning("Reading parameters",errmsg.str());
557        }
558        if(arg=="blankpixvalue"){
559          std::stringstream errmsg;
560          errmsg <<"The parameter blankPixValue is deprecated.\n"
561                 <<"This value is only taken from the FITS header.\n";
562          duchampWarning("Reading parameters",errmsg.str());
563        }
564
565      }
566    }
567
568    // The wavelet reconstruction takes precendence over the smoothing.
569    if(this->flagATrous) this->flagSmooth = false;
570
571    // Make sure smoothType is an acceptable type -- default is "spectral"
572    if((this->smoothType!="spectral")&&
573       (this->smoothType!="spatial")){
574      std::stringstream errmsg;
575      errmsg << "The requested value of the parameter smoothType, \""
576             << this->smoothType << "\" is invalid.\n"
577             << "Changing to \"spectral\".\n";
578      duchampWarning("Reading parameters",errmsg.str());
579      this->smoothType = "spectral";
580    }
581    // If kernMin has not been given, or is negative, make it equal to kernMaj
582    if(this->kernMin < 0) this->kernMin = this->kernMaj;
583
584    // Make sure spectralMethod is an acceptable type -- default is "peak"
585    if((this->spectralMethod!="peak")&&
586       (this->spectralMethod!="sum")){
587      std::stringstream errmsg;
588      errmsg << "The requested value of the parameter spectralMethod, \""
589             << this->spectralMethod << "\" is invalid.\n"
590             << "Changing to \"peak\".\n";
591      duchampWarning("Reading parameters",errmsg.str());
592      this->spectralMethod = "peak";
593    }
594
595    // Make sure pixelCentre is an acceptable type -- default is "peak"
596    if((this->pixelCentre!="centroid")&&
597       (this->pixelCentre!="average") &&
598       (this->pixelCentre!="peak")       ){
599      std::stringstream errmsg;
600      errmsg << "The requested value of the parameter pixelCentre, \""
601             << this->pixelCentre << "\" is invalid.\n"
602             << "Changing to \"centroid\".\n";
603      duchampWarning("Reading parameters",errmsg.str());
604      this->pixelCentre = "centroid";
605    }
606
607    return SUCCESS;
608  }
609
610
611  std::ostream& operator<< ( std::ostream& theStream, Param& par)
612  {
613    /**
614     * Print out the parameter set in a formatted, easy to read style.
615     * Lists the parameters, a description of them, and their value.
616     */
617
618    // Only show the [beamSize] bit if we are using the parameter
619    // otherwise we have read it from the FITS header.
620    std::string beamParam = "";
621    if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
622
623    // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
624    //   theStream.setf(std::ios::boolalpha);
625    theStream.setf(std::ios::left);
626    theStream  <<"\n---- Parameters ----"<<std::endl;
627    theStream  << std::setfill('.');
628    const int widthText = 38;
629    const int widthPar  = 18;
630    if(par.getFlagSubsection())
631      theStream<<std::setw(widthText)<<"Image to be analysed"                 
632               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
633               <<"  =  " <<resetiosflags(std::ios::right)
634               <<(par.getImageFile()+par.getSubsection()) <<std::endl;
635    else
636      theStream<<std::setw(widthText)<<"Image to be analysed"                 
637               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
638               <<"  =  " <<resetiosflags(std::ios::right)
639               <<par.getImageFile()      <<std::endl;
640    if(par.getFlagReconExists() && par.getFlagATrous()){
641      theStream<<std::setw(widthText)<<"Reconstructed array exists?"         
642               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
643               <<"  =  " <<resetiosflags(std::ios::right)
644               <<stringize(par.getFlagReconExists())<<std::endl;
645      theStream<<std::setw(widthText)<<"FITS file containing reconstruction" 
646               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
647               <<"  =  " <<resetiosflags(std::ios::right)
648               <<par.getReconFile()      <<std::endl;
649    }
650    if(par.getFlagSmoothExists() && par.getFlagSmooth()){
651      theStream<<std::setw(widthText)<<"Smoothed array exists?"         
652               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
653               <<"  =  " <<resetiosflags(std::ios::right)
654               <<stringize(par.getFlagSmoothExists())<<std::endl;
655      theStream<<std::setw(widthText)<<"FITS file containing smoothed array" 
656               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
657               <<"  =  " <<resetiosflags(std::ios::right)
658               <<par.getSmoothFile()      <<std::endl;
659    }
660    theStream  <<std::setw(widthText)<<"Intermediate Logfile"
661               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
662               <<"  =  " <<resetiosflags(std::ios::right)
663               <<par.getLogFile()        <<std::endl;
664    theStream  <<std::setw(widthText)<<"Final Results file"                   
665               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
666               <<"  =  " <<resetiosflags(std::ios::right)
667               <<par.getOutFile()        <<std::endl;
668    if(par.getFlagSeparateHeader())
669      theStream <<std::setw(widthText)<<"Header for results file"
670                <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[headerFile]"
671                <<"  =  " <<resetiosflags(std::ios::right)
672                <<par.getHeaderFile()        <<std::endl;
673    theStream  <<std::setw(widthText)<<"Spectrum file"                       
674               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
675               <<"  =  " <<resetiosflags(std::ios::right)
676               <<par.getSpectraFile()    <<std::endl;
677    if(par.getFlagVOT()){
678      theStream<<std::setw(widthText)<<"VOTable file"                         
679               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
680               <<"  =  " <<resetiosflags(std::ios::right)
681               <<par.getVOTFile()        <<std::endl;
682    }
683    if(par.getFlagKarma()){
684      theStream<<std::setw(widthText)<<"Karma annotation file"               
685               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
686               <<"  =  " <<resetiosflags(std::ios::right)
687             
688               <<par.getKarmaFile()      <<std::endl;
689    }
690    if(par.getFlagMaps()){
691      theStream<<std::setw(widthText)<<"0th Moment Map"                       
692               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
693               <<"  =  " <<resetiosflags(std::ios::right)
694               <<par.getMomentMap()      <<std::endl;
695      theStream<<std::setw(widthText)<<"Detection Map"                       
696               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
697               <<"  =  " <<resetiosflags(std::ios::right)
698               <<par.getDetectionMap()   <<std::endl;
699    }
700    theStream  <<std::setw(widthText)<<"Display a map in a pgplot xwindow?"
701               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
702               <<"  =  " <<resetiosflags(std::ios::right)
703               <<stringize(par.getFlagXOutput())     <<std::endl;
704    if(par.getFlagATrous()){                           
705      theStream<<std::setw(widthText)<<"Saving reconstructed cube?"           
706               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputRecon]"
707               <<"  =  " <<resetiosflags(std::ios::right)
708               <<stringize(par.getFlagOutputRecon())<<std::endl;
709      theStream<<std::setw(widthText)<<"Saving residuals from reconstruction?"
710               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputResid]"
711               <<"  =  " <<resetiosflags(std::ios::right)
712               <<stringize(par.getFlagOutputResid())<<std::endl;
713    }                                                 
714    if(par.getFlagSmooth()){                           
715      theStream<<std::setw(widthText)<<"Saving smoothed cube?"           
716               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputSmooth]"
717               <<"  =  " <<resetiosflags(std::ios::right)
718               <<stringize(par.getFlagOutputSmooth())<<std::endl;
719    }                                                 
720    theStream<<std::setw(widthText)<<"Saving mask cube?"           
721             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagOutputMask]"
722             <<"  =  " <<resetiosflags(std::ios::right)
723             <<stringize(par.getFlagOutputMask())<<std::endl;
724    theStream  <<"------"<<std::endl;
725    if(par.getFlagBlankPix()){
726      theStream<<std::setw(widthText)<<"Blank Pixel Value"                   
727               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< ""
728               <<"  =  " <<resetiosflags(std::ios::right)
729               <<par.getBlankPixVal()    <<std::endl;
730    }
731    theStream  <<std::setw(widthText)<<"Trimming Blank Pixels?"                 
732               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagTrim]"
733               <<"  =  " <<resetiosflags(std::ios::right)
734               <<stringize(par.getFlagTrim())   <<std::endl;
735    theStream  <<std::setw(widthText)<<"Searching for Negative features?"     
736               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
737               <<"  =  " <<resetiosflags(std::ios::right)
738               <<stringize(par.getFlagNegative())   <<std::endl;
739    theStream  <<std::setw(widthText)<<"Removing Milky Way channels?"         
740               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
741               <<"  =  " <<resetiosflags(std::ios::right)
742               <<stringize(par.getFlagMW())         <<std::endl;
743    if(par.getFlagMW()){
744      theStream<<std::setw(widthText)<<"Milky Way Channels"                   
745               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
746               <<"  =  " <<resetiosflags(std::ios::right)
747               <<par.getMinMW()
748               <<"-" <<par.getMaxMW()          <<std::endl;
749    }
750    theStream  <<std::setw(widthText)<<"Beam Size (pixels)"                   
751               <<std::setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
752               <<"  =  " <<resetiosflags(std::ios::right)
753               <<par.getBeamSize()       <<std::endl;
754    theStream  <<std::setw(widthText)<<"Removing baselines before search?"   
755               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
756               <<"  =  " <<resetiosflags(std::ios::right)
757               <<stringize(par.getFlagBaseline())   <<std::endl;
758    theStream  <<std::setw(widthText)<<"Smoothing each spectrum first?"       
759               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
760               <<"  =  " <<resetiosflags(std::ios::right)
761               <<stringize(par.getFlagSmooth())     <<std::endl;
762    if(par.getFlagSmooth()){           
763      theStream<<std::setw(widthText)<<"Type of smoothing"     
764               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothType]"
765               <<"  =  " <<resetiosflags(std::ios::right)
766               <<par.getSmoothType()       <<std::endl;
767      if(par.getSmoothType()=="spectral")
768        theStream<<std::setw(widthText)<<"Width of hanning filter"     
769                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
770                 <<"  =  " <<resetiosflags(std::ios::right)
771                 <<par.getHanningWidth()       <<std::endl;
772      else{
773        theStream<<std::setw(widthText)<<"Gaussian kernel semi-major axis [pix]"
774                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMaj]"
775                 <<"  =  " <<resetiosflags(std::ios::right)
776                 <<par.getKernMaj() << std::endl;
777        theStream<<std::setw(widthText)<<"Gaussian kernel semi-minor axis [pix]"
778                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernMin]"
779                 <<"  =  " <<resetiosflags(std::ios::right)
780                 <<par.getKernMin() << std::endl;
781        theStream<<std::setw(widthText)<<"Gaussian kernel position angle [deg]"
782                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[kernPA]"
783                 <<"  =  " <<resetiosflags(std::ios::right)
784                 <<par.getKernPA() << std::endl;
785      }
786    }
787    theStream  <<std::setw(widthText)<<"Using A Trous reconstruction?"       
788               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
789               <<"  =  " <<resetiosflags(std::ios::right)
790               <<stringize(par.getFlagATrous())     <<std::endl;
791    if(par.getFlagATrous()){                           
792      theStream<<std::setw(widthText)<<"Number of dimensions in reconstruction"     
793               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
794               <<"  =  " <<resetiosflags(std::ios::right)
795               <<par.getReconDim()       <<std::endl;
796      if(par.getMaxScale()>0){
797        theStream<<std::setw(widthText-1)<<"Scales used in reconstruction"     
798                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin-scaleMax]"
799                 <<"  =  " <<resetiosflags(std::ios::right)
800                 <<par.getMinScale() << "-" << par.getMaxScale()   <<std::endl;
801      }
802      else{
803        theStream<<std::setw(widthText)<<"Minimum scale in reconstruction"     
804                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
805                 <<"  =  " <<resetiosflags(std::ios::right)
806                 <<par.getMinScale()      <<std::endl;
807      }
808      theStream<<std::setw(widthText)<<"SNR Threshold within reconstruction" 
809               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
810               <<"  =  " <<resetiosflags(std::ios::right)
811               <<par.getAtrousCut()      <<std::endl;
812      theStream<<std::setw(widthText)<<"Filter being used for reconstruction"
813               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
814               <<"  =  " <<resetiosflags(std::ios::right)
815               <<par.getFilterCode()
816               << " (" << par.getFilterName()  << ")" <<std::endl;
817    }                                                 
818    if(par.getFlagStatSec()){
819      theStream<<std::setw(widthText)<<"Section used by statistics calculation"
820               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[statSec]"
821               <<"  =  " <<resetiosflags(std::ios::right)
822               <<par.statSec.getSection()          <<std::endl;
823    }
824    theStream  <<std::setw(widthText)<<"Using FDR analysis?"                 
825               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
826               <<"  =  " <<resetiosflags(std::ios::right)
827               <<stringize(par.getFlagFDR())        <<std::endl;
828    if(par.getFlagFDR()){                                     
829      theStream<<std::setw(widthText)<<"Alpha value for FDR analysis"         
830               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
831               <<"  =  " <<resetiosflags(std::ios::right)
832               <<par.getAlpha()          <<std::endl;
833    }                                                 
834    else {
835      if(par.getFlagUserThreshold()){
836        theStream<<std::setw(widthText)<<"Detection Threshold"                       
837                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
838                 <<"  =  " <<resetiosflags(std::ios::right)
839                 <<par.getThreshold()            <<std::endl;
840      }
841      else{
842        theStream<<std::setw(widthText)<<"SNR Threshold (in sigma)"
843                 <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
844                 <<"  =  " <<resetiosflags(std::ios::right)
845                 <<par.getCut()            <<std::endl;
846      }
847    }
848    theStream  <<std::setw(widthText)<<"Minimum # Pixels in a detection"     
849               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
850               <<"  =  " <<resetiosflags(std::ios::right)
851               <<par.getMinPix()         <<std::endl;
852    theStream  <<std::setw(widthText)<<"Minimum # Channels in a detection"   
853               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
854               <<"  =  " <<resetiosflags(std::ios::right)
855               <<par.getMinChannels()    <<std::endl;
856    theStream  <<std::setw(widthText)<<"Growing objects after detection?"     
857               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
858               <<"  =  " <<resetiosflags(std::ios::right)
859               <<stringize(par.getFlagGrowth())     <<std::endl;
860    if(par.getFlagGrowth()) {                         
861      theStream<<std::setw(widthText)<<"SNR Threshold for growth"             
862               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
863               <<"  =  " <<resetiosflags(std::ios::right)
864               <<par.getGrowthCut()      <<std::endl;
865    }
866    theStream  <<std::setw(widthText)<<"Using Adjacent-pixel criterion?"     
867               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
868               <<"  =  " <<resetiosflags(std::ios::right)
869               <<stringize(par.getFlagAdjacent())   <<std::endl;
870    if(!par.getFlagAdjacent()){
871      theStream<<std::setw(widthText)<<"Max. spatial separation for merging" 
872               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
873               <<"  =  " <<resetiosflags(std::ios::right)
874               <<par.getThreshS()        <<std::endl;
875    }
876    theStream  <<std::setw(widthText)<<"Max. velocity separation for merging"
877               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
878               <<"  =  " <<resetiosflags(std::ios::right)
879               <<par.getThreshV()        <<std::endl;
880    theStream  <<std::setw(widthText)<<"Method of spectral plotting"         
881               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
882               <<"  =  " <<resetiosflags(std::ios::right)
883               <<par.getSpectralMethod() <<std::endl;
884    theStream  <<std::setw(widthText)<<"Type of object centre used in results"
885               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[pixelCentre]"
886               <<"  =  " <<resetiosflags(std::ios::right)
887               <<par.getPixelCentre() <<std::endl;
888    theStream  <<"--------------------\n\n";
889    theStream  << std::setfill(' ');
890    theStream.unsetf(std::ios::left);
891    //  theStream.unsetf(std::ios::boolalpha);
892    return theStream;
893  }
894
895
896  void Param::copyHeaderInfo(FitsHeader &head)
897  {
898    /**
899     * A function to copy across relevant header keywords from the
900     *  FitsHeader class to the Param class, as they are needed by
901     *  functions in the Param class.
902     * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
903     */
904
905    this->blankKeyword  = head.getBlankKeyword();
906    this->bscaleKeyword = head.getBscaleKeyword();
907    this->bzeroKeyword  = head.getBzeroKeyword();
908    this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
909      this->bzeroKeyword;
910
911    this->numPixBeam    = head.getBeamSize();
912  }
913
914  std::string Param::outputMaskFile()
915  {
916    /**
917     *  This function produces the required filename in which to save
918     *  the mask image, indicating which pixels have been detected as
919     *  part of an object. If the input image is image.fits, then the
920     *  output will be image.MASK.fits.
921     */
922    std::string inputName = this->imageFile;
923    std::stringstream ss;
924    ss << inputName.substr(0,inputName.size()-5); 
925    // remove the ".fits" on the end.
926    ss << ".MASK.fits";
927    return ss.str();
928  }
929
930  std::string Param::outputSmoothFile()
931  {
932    /**
933     * This function produces the required filename in which to save
934     *  the smoothed array. If the input image is image.fits, then
935     *  the output will be:
936     *   <ul><li> Spectral smoothing: image.SMOOTH-1D-3.fits, where the
937     *            width of the Hanning filter was 3 pixels.
938     *       <li> Spatial smoothing : image.SMOOTH-2D-3-2-20.fits, where
939     *            kernMaj=3, kernMin=2 and kernPA=20 degrees.
940     *   </ul>
941     */
942    std::string inputName = this->imageFile;
943    std::stringstream ss;
944    ss << inputName.substr(0,inputName.size()-5); 
945    // remove the ".fits" on the end.
946    if(this->flagSubsection) ss<<".sub";
947    if(this->smoothType=="spectral")
948      ss << ".SMOOTH-1D-" << this->hanningWidth << ".fits";
949    else if(this->smoothType=="spatial")
950      ss << ".SMOOTH-2D-"
951         << this->kernMaj << "-"
952         << this->kernMin << "-"
953         << this->kernPA  << ".fits";
954    return ss.str();
955  }
956
957  std::string Param::outputReconFile()
958  {
959    /**
960     * This function produces the required filename in which to save
961     *  the reconstructed array. If the input image is image.fits, then
962     *  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
963     *  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
964     */
965    std::string inputName = this->imageFile;
966    std::stringstream ss;
967    // First we remove the ".fits" from the end of the filename.
968    ss << inputName.substr(0,inputName.size()-5); 
969    if(this->flagSubsection) ss<<".sub";
970    ss << ".RECON-" << this->reconDim
971       << "-"       << this->filterCode
972       << "-"       << this->snrRecon
973       << "-"       << this->scaleMin
974       << ".fits";
975    return ss.str();
976  }
977
978  std::string Param::outputResidFile()
979  {
980    /**
981     * This function produces the required filename in which to save
982     *  the reconstructed array. If the input image is image.fits, then
983     *  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
984     *  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
985     */
986    std::string inputName = this->imageFile;
987    std::stringstream ss;
988    // First we remove the ".fits" from the end of the filename.
989    ss << inputName.substr(0,inputName.size()-5);
990    if(this->flagSubsection) ss<<".sub";
991    ss << ".RESID-" << this->reconDim
992       << "-"       << this->filterCode
993       << "-"       << this->snrRecon
994       << "-"       << this->scaleMin
995       << ".fits";
996    return ss.str();
997  }
998
999}
Note: See TracBrowser for help on using the repository browser.