source: trunk/src/param.cc @ 222

Last change on this file since 222 was 222, checked in by Matthew Whiting, 17 years ago

Large commit, but mostly documentation-oriented.

Only non-doc-related changes are:

  • To remove two deprecated files and any declarations of the functions in them
  • To move drawBlankEdges to the Cubes/ directory
  • Some small changes to the implementation of the StatsContainer? functions.
  • Creation of Utils/devel.hh to hide functions not used in Duchamp
  • To move the trimmedHist stats functions to their own file, again to hide them.
File size: 35.7 KB
RevLine 
[3]1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
[205]6#include <stdlib.h>
[3]7#include <math.h>
[103]8#include <wcs.h>
9#include <wcsunits.h>
[3]10#include <param.hh>
[134]11#include <config.h>
[142]12#include <duchamp.hh>
[103]13#include <Utils/utils.hh>
[3]14
[194]15// Define funtion to print bools as words, in case the compiler doesn't
16//  recognise the setf(ios::boolalpha) command...
[110]17#ifdef HAVE_STDBOOL_H
18string stringize(bool b){
19  std::stringstream ss;
20  ss.setf(std::ios::boolalpha);
21  ss << b;
22  return ss.str();
23}
24#else
25string stringize(bool b){
26  std::string output;
27  if(b) output="true";
28  else output="false";
29  return output;
30}
31#endif
32
[3]33using std::setw;
34using std::endl;
35
36/****************************************************************/
37///////////////////////////////////////////////////
[103]38//// Functions for FitsHeader class:
39///////////////////////////////////////////////////
40
[204]41FitsHeader::FitsHeader()
42{
[205]43  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]44  this->wcs->flag=-1;
[204]45  wcsini(true, 3, this->wcs);
[103]46  this->wcsIsGood = false;
47  this->nwcs = 0;
48  this->scale=1.;
49  this->offset=0.;
50  this->power=1.;
51  this->fluxUnits="counts";
52}
53
[204]54FitsHeader::FitsHeader(const FitsHeader& h)
55{
[205]56  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]57  this->wcs->flag=-1;
[204]58  wcsini(true, h.wcs->naxis, this->wcs);
59  wcscopy(true, h.wcs, this->wcs);
[103]60  wcsset(this->wcs);
[137]61  this->nwcs = h.nwcs;
62  this->wcsIsGood = h.wcsIsGood;
63  this->spectralUnits = h.spectralUnits;
64  this->fluxUnits = h.fluxUnits;
65  this->intFluxUnits = h.intFluxUnits;
66  this->beamSize = h.beamSize;
67  this->bmajKeyword = h.bmajKeyword;
68  this->bminKeyword = h.bminKeyword;
69  this->blankKeyword = h.blankKeyword;
70  this->bzeroKeyword = h.bzeroKeyword;
71  this->bscaleKeyword = h.bscaleKeyword;
72  this->scale = h.scale;
73  this->offset = h.offset;
74  this->power = h.power;
[103]75}
76
[204]77FitsHeader& FitsHeader::operator= (const FitsHeader& h)
78{
[205]79  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]80  this->wcs->flag=-1;
[204]81  wcsini(true, h.wcs->naxis, this->wcs);
82  wcscopy(true, h.wcs, this->wcs);
[103]83  wcsset(this->wcs);
[137]84  this->nwcs = h.nwcs;
85  this->wcsIsGood = h.wcsIsGood;
86  this->spectralUnits = h.spectralUnits;
87  this->fluxUnits = h.fluxUnits;
88  this->intFluxUnits = h.intFluxUnits;
89  this->beamSize = h.beamSize;
90  this->bmajKeyword = h.bmajKeyword;
91  this->bminKeyword = h.bminKeyword;
92  this->blankKeyword = h.blankKeyword;
93  this->bzeroKeyword = h.bzeroKeyword;
94  this->bscaleKeyword = h.bscaleKeyword;
95  this->scale = h.scale;
96  this->offset = h.offset;
97  this->power = h.power;
[103]98}
99
[204]100void FitsHeader::setWCS(struct wcsprm *w)
[103]101{
102  /**
103   *  A function that assigns the wcs parameters, and runs
104   *   wcsset to set it up correctly.
105   *  Performs a check to see if the WCS is good (by looking at
106   *   the lng and lat wcsprm parameters), and sets the wcsIsGood
107   *   flag accordingly.
[221]108   * \param w A WCSLIB wcsprm struct with the correct parameters.
[103]109   */
[204]110  wcscopy(true, w, this->wcs);
[103]111  wcsset(this->wcs);
112  if( (w->lng!=-1) && (w->lat!=-1) ) this->wcsIsGood = true;
113}
114
[204]115struct wcsprm *FitsHeader::getWCS()
[103]116{
117  /**
[221]118   *  A function that returns a properly initilized wcsprm object
119   *  corresponding to the WCS.
[103]120   */
[205]121  struct wcsprm *wNew = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]122  wNew->flag=-1;
[204]123  wcsini(true, this->wcs->naxis, wNew);
124  wcscopy(true, this->wcs, wNew);
[103]125  wcsset(wNew);
126  return wNew;
127}
128
[222]129int FitsHeader::wcsToPix(const double *world, double *pix){     
130  return wcsToPixSingle(this->wcs, world, pix); 
131};
132int FitsHeader::wcsToPix(const double *world, double *pix, const int npts){
133  return wcsToPixMulti(this->wcs, world, pix, npts); 
134};
135int FitsHeader::pixToWCS(const double *pix, double *world){   
136  return pixToWCSSingle(this->wcs, pix, world); 
137};
138int FitsHeader::pixToWCS(const double *pix, double *world, const int npts){
139  return pixToWCSMulti(this->wcs, pix,world, npts); 
140};
141
142
[204]143double FitsHeader::pixToVel(double &x, double &y, double &z)
[103]144{
[186]145  double vel;
146  if(this->wcsIsGood){
147    double *pix   = new double[3];
148    double *world = new double[3];
149    pix[0] = x; pix[1] = y; pix[2] = z;
150    pixToWCSSingle(this->wcs,pix,world);
151    vel = this->specToVel(world[2]);
152    delete [] pix;
153    delete [] world;
154  }
155  else vel = z;
[103]156  return vel;
157}
158
159double* FitsHeader::pixToVel(double &x, double &y, double *zarray, int size)
160{
[186]161  double *newzarray = new double[size];
162  if(this->wcsIsGood){
163    double *pix   = new double[size*3];
164    for(int i=0;i<size;i++){
[187]165      pix[3*i]   = x;
166      pix[3*i+1] = y;
167      pix[3*i+2] = zarray[i];
[186]168    }
169    double *world = new double[size*3];
170    pixToWCSMulti(this->wcs,pix,world,size);
171    delete [] pix;
172    for(int i=0;i<size;i++) newzarray[i] = this->specToVel(world[3*i+2]);
173    delete [] world;
[103]174  }
[186]175  else{
176    for(int i=0;i<size;i++) newzarray[i] = zarray[i];
177  }
[103]178  return newzarray;
179}
180
181double  FitsHeader::specToVel(const double &coord)
182{
183  double vel;
[139]184  if(power==1.0) vel =  coord*this->scale + this->offset;
[103]185  else vel = pow( (coord*this->scale + this->offset), this->power);
186  return vel;
187}
188
189double  FitsHeader::velToSpec(const float &velocity)
190{
191//   return velToCoord(this->wcs,velocity,this->spectralUnits);};
192  return (pow(velocity, 1./this->power) - this->offset) / this->scale;}
193
194string  FitsHeader::getIAUName(double ra, double dec)
195{
[201]196  if(strcmp(this->wcs->lngtyp,"RA")==0)
197    return getIAUNameEQ(ra, dec, this->wcs->equinox);
198  else
199    return getIAUNameGAL(ra, dec);
[103]200}
201
202void FitsHeader::fixUnits(Param &par)
203{
204  // define spectral units from the param set
205  this->spectralUnits = par.getSpectralUnits();
206
207  double sc=1.;
208  double of=0.;
209  double po=1.;;
210  if(this->wcsIsGood){
[205]211    int status = wcsunits( this->wcs->cunit[this->wcs->spec],
[160]212                         this->spectralUnits.c_str(),
[142]213                         &sc, &of, &po);
[205]214    if(status > 0){
[120]215      std::stringstream errmsg;
[205]216      errmsg << "WCSUNITS Error, Code = " << status
217             << ": " << wcsunits_errmsg[status];
218      if(status == 10) errmsg << "\nTried to get conversion from '"
219                              << this->wcs->cunit[this->wcs->spec] << "' to '"
220                              << this->spectralUnits.c_str() << "'\n";
[204]221      this->spectralUnits = this->wcs->cunit[this->wcs->spec];
[103]222      if(this->spectralUnits==""){
[202]223        errmsg <<
[219]224          "Spectral units not specified. Setting them to 'SPC' for clarity.\n";
225        this->spectralUnits = "SPC";
[103]226      }
[120]227      duchampError("fixUnits", errmsg.str());
228     
[103]229    }
230  }
231  this->scale = sc;
232  this->offset= of;
233  this->power = po;
234
[142]235  // Work out the integrated flux units, based on the spectral units.
236  // If flux is per beam, trim the /beam from the flux units and multiply
237  //  by the spectral units.
238  // Otherwise, just muliply by the spectral units.
[103]239  if(this->fluxUnits.size()>0){
[142]240    if(this->fluxUnits.substr(this->fluxUnits.size()-5,
241                              this->fluxUnits.size()   ) == "/beam"){
[103]242      this->intFluxUnits = this->fluxUnits.substr(0,this->fluxUnits.size()-5)
243        +" " +this->spectralUnits;
244    }
[159]245    else this->intFluxUnits = this->fluxUnits + " " + this->spectralUnits;
[103]246  }
247
248}
249
250/****************************************************************/
251///////////////////////////////////////////////////
[3]252//// Accessor Functions for Parameter class:
253///////////////////////////////////////////////////
254Param::Param(){
255  /**
256   * Param()
257   *  Default intial values for the parameters.
258   * imageFile has no default value!
259   */
260  // Input files
[190]261  this->imageFile         = "";
262  this->flagSubsection    = false;
263  this->subsection        = "[*,*,*]";
264  this->flagReconExists   = false;
265  this->reconFile         = "";
[208]266  this->flagSmoothExists  = false;
267  this->smoothFile        = "";
[3]268  // Output files
[190]269  this->flagLog           = true;
270  this->logFile           = "duchamp-Logfile.txt";
271  this->outFile           = "duchamp-Results.txt";
272  this->spectraFile       = "duchamp-Spectra.ps";
[208]273  this->flagOutputSmooth  = false;
[190]274  this->flagOutputRecon   = false;
275  this->flagOutputResid   = false;
276  this->flagVOT           = false;
277  this->votFile           = "duchamp-Results.xml";
278  this->flagKarma         = false;
279  this->karmaFile         = "duchamp-Results.ann";
280  this->flagMaps          = true;
281  this->detectionMap      = "duchamp-DetectionMap.ps";
282  this->momentMap         = "duchamp-MomentMap.ps";
[195]283  this->flagXOutput       = true;
[3]284  // Cube related parameters
[190]285  this->flagBlankPix      = true;
286  this->blankPixValue     = -8.00061;
287  this->blankKeyword      = 1;
288  this->bscaleKeyword     = -8.00061;
289  this->bzeroKeyword      = 0.;
290  this->flagUsingBlank    = false;
291  this->flagMW            = false;
292  this->maxMW             = 112;
293  this->minMW             = 75;
294  this->numPixBeam        = 10.;
295  this->flagUsingBeam     = false;
[3]296  // Trim-related         
[190]297  this->flagTrimmed       = false;
298  this->borderLeft        = 0;
299  this->borderRight       = 0;
300  this->borderBottom      = 0;
301  this->borderTop         = 0;
[3]302  // Subsection offsets
[204]303  this->sizeOffsets       = 0;
[190]304  this->xSubOffset        = 0;
305  this->ySubOffset        = 0;
306  this->zSubOffset        = 0;
[3]307  // Baseline related
[190]308  this->flagBaseline      = false;
[3]309  // Detection-related   
[190]310  this->flagNegative      = false;
[3]311  // Object growth       
[190]312  this->flagGrowth        = false;
313  this->growthCut         = 2.;
[3]314  // FDR analysis         
[190]315  this->flagFDR           = false;
316  this->alphaFDR          = 0.01;
[3]317  // Other detection     
[190]318  this->snrCut            = 3.;
319  this->threshold         = 0.;
320  this->flagUserThreshold = false;
[201]321  // Hanning Smoothing
322  this->flagSmooth        = false;
323  this->hanningWidth      = 5;
[3]324  // A trous reconstruction parameters
[190]325  this->flagATrous        = true;
326  this->reconDim          = 3;
327  this->scaleMin          = 1;
328  this->snrRecon          = 4.;
329  this->filterCode        = 1;
[3]330  // Volume-merging parameters
[190]331  this->flagAdjacent      = true;
332  this->threshSpatial     = 3.;
333  this->threshVelocity    = 7.;
334  this->minChannels       = 3;
335  this->minPix            = 2;
[3]336  // Input-Output related
[190]337  this->spectralMethod    = "peak";
338  this->borders           = true;
339  this->blankEdge         = true;
340  this->verbose           = true;
341  this->spectralUnits     = "km/s";
[3]342};
343
[204]344Param::Param (const Param& p)
345{
346  this->imageFile         = p.imageFile;
347  this->flagSubsection    = p.flagSubsection;
348  this->subsection        = p.subsection;     
349  this->flagReconExists   = p.flagReconExists;
350  this->reconFile         = p.reconFile;     
[208]351  this->flagSmoothExists  = p.flagSmoothExists;
352  this->smoothFile        = p.smoothFile;     
[204]353  this->flagLog           = p.flagLog;       
354  this->logFile           = p.logFile;       
355  this->outFile           = p.outFile;       
356  this->spectraFile       = p.spectraFile;   
[208]357  this->flagOutputSmooth  = p.flagOutputSmooth;
[204]358  this->flagOutputRecon   = p.flagOutputRecon;
359  this->flagOutputResid   = p.flagOutputResid;
360  this->flagVOT           = p.flagVOT;         
361  this->votFile           = p.votFile;       
362  this->flagKarma         = p.flagKarma;     
363  this->karmaFile         = p.karmaFile;     
364  this->flagMaps          = p.flagMaps;       
365  this->detectionMap      = p.detectionMap;   
366  this->momentMap         = p.momentMap;     
367  this->flagXOutput       = p.flagXOutput;       
368  this->flagBlankPix      = p.flagBlankPix;   
369  this->blankPixValue     = p.blankPixValue; 
370  this->blankKeyword      = p.blankKeyword;   
371  this->bscaleKeyword     = p.bscaleKeyword; 
372  this->bzeroKeyword      = p.bzeroKeyword;   
373  this->flagUsingBlank    = p.flagUsingBlank;
374  this->flagMW            = p.flagMW;         
375  this->maxMW             = p.maxMW;         
376  this->minMW             = p.minMW;         
377  this->numPixBeam        = p.numPixBeam;     
378  this->flagTrimmed       = p.flagTrimmed;   
379  this->borderLeft        = p.borderLeft;     
380  this->borderRight       = p.borderRight;   
381  this->borderBottom      = p.borderBottom;   
382  this->borderTop         = p.borderTop;     
383  this->sizeOffsets       = p.sizeOffsets;
[213]384  this->offsets           = new long[this->sizeOffsets];
[204]385  if(this->sizeOffsets>0)
386    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
387  this->xSubOffset        = p.xSubOffset;     
388  this->ySubOffset        = p.ySubOffset;     
389  this->zSubOffset        = p.zSubOffset;
390  this->flagBaseline      = p.flagBaseline;
391  this->flagNegative      = p.flagNegative;
392  this->flagGrowth        = p.flagGrowth;
393  this->growthCut         = p.growthCut;
394  this->flagFDR           = p.flagFDR;
395  this->alphaFDR          = p.alphaFDR;
396  this->snrCut            = p.snrCut;
397  this->threshold         = p.threshold;
[205]398  this->flagUserThreshold = p.flagUserThreshold;
[204]399  this->flagSmooth        = p.flagSmooth;
400  this->hanningWidth      = p.hanningWidth;
401  this->flagATrous        = p.flagATrous;
402  this->reconDim          = p.reconDim;
403  this->scaleMin          = p.scaleMin;
404  this->snrRecon          = p.snrRecon;
405  this->filterCode        = p.filterCode;
406  this->flagAdjacent      = p.flagAdjacent;
407  this->threshSpatial     = p.threshSpatial;
408  this->threshVelocity    = p.threshVelocity;
409  this->minChannels       = p.minChannels;
410  this->minPix            = p.minPix;
411  this->spectralMethod    = p.spectralMethod;
412  this->borders           = p.borders;
413  this->verbose           = p.verbose;
414  this->spectralUnits     = p.spectralUnits;
415}
416
[137]417Param& Param::operator= (const Param& p)
418{
[190]419  this->imageFile         = p.imageFile;
420  this->flagSubsection    = p.flagSubsection;
421  this->subsection        = p.subsection;     
422  this->flagReconExists   = p.flagReconExists;
423  this->reconFile         = p.reconFile;     
[208]424  this->flagSmoothExists  = p.flagSmoothExists;
425  this->smoothFile        = p.smoothFile;     
[190]426  this->flagLog           = p.flagLog;       
427  this->logFile           = p.logFile;       
428  this->outFile           = p.outFile;       
429  this->spectraFile       = p.spectraFile;   
[208]430  this->flagOutputSmooth  = p.flagOutputSmooth;
[190]431  this->flagOutputRecon   = p.flagOutputRecon;
432  this->flagOutputResid   = p.flagOutputResid;
433  this->flagVOT           = p.flagVOT;         
434  this->votFile           = p.votFile;       
435  this->flagKarma         = p.flagKarma;     
436  this->karmaFile         = p.karmaFile;     
437  this->flagMaps          = p.flagMaps;       
438  this->detectionMap      = p.detectionMap;   
439  this->momentMap         = p.momentMap;     
[195]440  this->flagXOutput       = p.flagXOutput;       
[190]441  this->flagBlankPix      = p.flagBlankPix;   
442  this->blankPixValue     = p.blankPixValue; 
443  this->blankKeyword      = p.blankKeyword;   
444  this->bscaleKeyword     = p.bscaleKeyword; 
445  this->bzeroKeyword      = p.bzeroKeyword;   
446  this->flagUsingBlank    = p.flagUsingBlank;
447  this->flagMW            = p.flagMW;         
448  this->maxMW             = p.maxMW;         
449  this->minMW             = p.minMW;         
450  this->numPixBeam        = p.numPixBeam;     
451  this->flagTrimmed       = p.flagTrimmed;   
452  this->borderLeft        = p.borderLeft;     
453  this->borderRight       = p.borderRight;   
454  this->borderBottom      = p.borderBottom;   
455  this->borderTop         = p.borderTop;     
[204]456  this->sizeOffsets       = p.sizeOffsets;
[213]457  this->offsets           = new long[this->sizeOffsets];
[204]458  if(this->sizeOffsets>0)
459    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
[190]460  this->xSubOffset        = p.xSubOffset;     
461  this->ySubOffset        = p.ySubOffset;     
462  this->zSubOffset        = p.zSubOffset;
463  this->flagBaseline      = p.flagBaseline;
464  this->flagNegative      = p.flagNegative;
465  this->flagGrowth        = p.flagGrowth;
466  this->growthCut         = p.growthCut;
467  this->flagFDR           = p.flagFDR;
468  this->alphaFDR          = p.alphaFDR;
469  this->snrCut            = p.snrCut;
470  this->threshold         = p.threshold;
[205]471  this->flagUserThreshold = p.flagUserThreshold;
[201]472  this->flagSmooth        = p.flagSmooth;
473  this->hanningWidth      = p.hanningWidth;
[190]474  this->flagATrous        = p.flagATrous;
475  this->reconDim          = p.reconDim;
476  this->scaleMin          = p.scaleMin;
477  this->snrRecon          = p.snrRecon;
478  this->filterCode        = p.filterCode;
479  this->flagAdjacent      = p.flagAdjacent;
480  this->threshSpatial     = p.threshSpatial;
481  this->threshVelocity    = p.threshVelocity;
482  this->minChannels       = p.minChannels;
483  this->minPix            = p.minPix;
484  this->spectralMethod    = p.spectralMethod;
485  this->borders           = p.borders;
486  this->verbose           = p.verbose;
487  this->spectralUnits     = p.spectralUnits;
[137]488}
489
[3]490/****************************************************************/
491///////////////////////////////////////////////////
492//// Other Functions using the  Parameter class:
493///////////////////////////////////////////////////
494
[163]495inline string makelower( string s )
[3]496{
497  // "borrowed" from Matt Howlett's 'fred'
498  string out = "";
499  for( int i=0; i<s.size(); ++i ) {
500    out += tolower(s[i]);
501  }
502  return out;
503}
504
[163]505inline bool boolify( string s )
[132]506{
507  /**
[133]508   * bool boolify(string)
[132]509   *  Convert a string to a bool variable
510   *  "1" and "true" get converted to true
511   *  "0" and "false" (and anything else) get converted to false
512   */
513  if((s=="1") || (makelower(s)=="true")) return true;
514  else if((s=="0") || (makelower(s)=="false")) return false;
515  else return false;
516}
517
[163]518inline string readSval(std::stringstream& ss)
519{
520  string val; ss >> val; return val;
521}
522
523inline bool readFlag(std::stringstream& ss)
524{
525  string val; ss >> val; return boolify(val);
526}
527
528inline float readFval(std::stringstream& ss)
529{
530  float val; ss >> val; return val;
531}
532
533inline int readIval(std::stringstream& ss)
534{
535  int val; ss >> val; return val;
536}
537
[160]538int Param::readParams(string paramfile)
[3]539{
[221]540  /**
541   * The parameters are read in from a disk file, on the assumption that each
542   *  line of the file has the format "parameter value" (eg. alphafdr 0.1)
543   *
544   * The case of the parameter name does not matter, nor does the
545   * formatting of the spaces (it can be any amount of whitespace or
546   * tabs).
547   *
548   * \param paramfile A std::string containing the parameter filename.
549   */
[3]550  std::ifstream fin(paramfile.c_str());
[160]551  if(!fin.is_open()) return FAILURE;
[3]552  string line;
553  while( !std::getline(fin,line,'\n').eof()){
554
555    if(line[0]!='#'){
556      std::stringstream ss;
557      ss.str(line);
558      string arg;
[163]559      ss >> arg;
560      arg = makelower(arg);
561      if(arg=="imagefile")       this->imageFile = readSval(ss);
562      if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
563      if(arg=="subsection")      this->subsection = readSval(ss);
564      if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
565      if(arg=="reconfile")       this->reconFile = readSval(ss);
[208]566      if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
567      if(arg=="smoothfile")      this->smoothFile = readSval(ss);
[71]568
[163]569      if(arg=="flaglog")         this->flagLog = readFlag(ss);
570      if(arg=="logfile")         this->logFile = readSval(ss);
571      if(arg=="outfile")         this->outFile = readSval(ss);
572      if(arg=="spectrafile")     this->spectraFile = readSval(ss);
[208]573      if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
[163]574      if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
575      if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
576      if(arg=="flagvot")         this->flagVOT = readFlag(ss);
577      if(arg=="votfile")         this->votFile = readSval(ss);
578      if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
579      if(arg=="karmafile")       this->karmaFile = readSval(ss);
580      if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
581      if(arg=="detectionmap")    this->detectionMap = readSval(ss);
582      if(arg=="momentmap")       this->momentMap = readSval(ss);
[195]583      if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
[3]584
[163]585      if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
586      if(arg=="flagblankpix")    this->flagBlankPix = readFlag(ss);
587      if(arg=="blankpixvalue")   this->blankPixValue = readFval(ss);
588      if(arg=="flagmw")          this->flagMW = readFlag(ss);
589      if(arg=="maxmw")           this->maxMW = readIval(ss);
590      if(arg=="minmw")           this->minMW = readIval(ss);
591      if(arg=="beamsize")        this->numPixBeam = readFval(ss);
[71]592
[163]593      if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
594      if(arg=="minpix")          this->minPix = readIval(ss);
595      if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
596      if(arg=="growthcut")       this->growthCut = readFval(ss);
[71]597
[163]598      if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
599      if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
[103]600
[163]601      if(arg=="snrcut")          this->snrCut = readFval(ss);
[190]602      if(arg=="threshold"){
603                                 this->threshold = readFval(ss);
604                                 this->flagUserThreshold = true;
605      }
[201]606     
607      if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
608      if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
[103]609
[163]610      if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
611      if(arg=="recondim")        this->reconDim = readIval(ss);
612      if(arg=="scalemin")        this->scaleMin = readIval(ss);
613      if(arg=="snrrecon")        this->snrRecon = readFval(ss);
614      if(arg=="filtercode")      this->filterCode = readIval(ss);
[71]615
[163]616      if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
617      if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
618      if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
619      if(arg=="minchannels")     this->minChannels = readIval(ss);
[71]620
[163]621      if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
622      if(arg=="spectralunits")   this->spectralUnits=makelower(readSval(ss));
623      if(arg=="drawborders")     this->borders = readFlag(ss);
624      if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
625      if(arg=="verbose")         this->verbose = readFlag(ss);
[3]626    }
627  }
[208]628  if(this->flagATrous) this->flagSmooth = false;
[160]629  return SUCCESS;
[3]630}
631
632
633std::ostream& operator<< ( std::ostream& theStream, Param& par)
634{
[221]635  /**
636   * Print out the parameter set in a formatted, easy to read style.
637   * Lists the parameters, a description of them, and their value.
638   */
639
[103]640  // Only show the [blankPixValue] bit if we are using the parameter
641  // otherwise we have read it from the FITS header.
642  string blankParam = "";
643  if(par.getFlagUsingBlank()) blankParam = "[blankPixValue]";
[172]644  string beamParam = "";
645  if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
[103]646
[107]647  // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
[172]648  //   theStream.setf(std::ios::boolalpha);
[3]649  theStream.setf(std::ios::left);
[219]650  theStream  <<"\n---- Parameters ----"<<endl;
[103]651  theStream  << std::setfill('.');
[187]652  const int widthText = 38;
653  const int widthPar  = 18;
[3]654  if(par.getFlagSubsection())
[187]655    theStream<<setw(widthText)<<"Image to be analysed"                 
656             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
[103]657             <<"  =  " <<resetiosflags(std::ios::right)
[172]658             <<(par.getImageFile()+par.getSubsection()) <<endl;
[3]659  else
[187]660    theStream<<setw(widthText)<<"Image to be analysed"                 
661             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
[172]662             <<"  =  " <<resetiosflags(std::ios::right)
663             <<par.getImageFile()      <<endl;
[81]664  if(par.getFlagReconExists() && par.getFlagATrous()){
[187]665    theStream<<setw(widthText)<<"Reconstructed array exists?"         
666             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
[172]667             <<"  =  " <<resetiosflags(std::ios::right)
668             <<stringize(par.getFlagReconExists())<<endl;
[187]669    theStream<<setw(widthText)<<"FITS file containing reconstruction" 
670             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
[172]671             <<"  =  " <<resetiosflags(std::ios::right)
672             <<par.getReconFile()      <<endl;
[71]673  }
[208]674  if(par.getFlagSmoothExists() && par.getFlagSmooth()){
675    theStream<<setw(widthText)<<"Hanning-smoothed array exists?"         
676             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
677             <<"  =  " <<resetiosflags(std::ios::right)
678             <<stringize(par.getFlagSmoothExists())<<endl;
679    theStream<<setw(widthText)<<"FITS file containing smoothed array" 
680             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
681             <<"  =  " <<resetiosflags(std::ios::right)
682             <<par.getSmoothFile()      <<endl;
683  }
[187]684  theStream  <<setw(widthText)<<"Intermediate Logfile"
685             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
[172]686             <<"  =  " <<resetiosflags(std::ios::right)
687             <<par.getLogFile()        <<endl;
[187]688  theStream  <<setw(widthText)<<"Final Results file"                   
689             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
[172]690             <<"  =  " <<resetiosflags(std::ios::right)
691             <<par.getOutFile()        <<endl;
[187]692  theStream  <<setw(widthText)<<"Spectrum file"                       
693             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
[172]694             <<"  =  " <<resetiosflags(std::ios::right)
695             <<par.getSpectraFile()    <<endl;
[3]696  if(par.getFlagVOT()){
[187]697    theStream<<setw(widthText)<<"VOTable file"                         
698             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
[172]699             <<"  =  " <<resetiosflags(std::ios::right)
700             <<par.getVOTFile()        <<endl;
[3]701  }
[20]702  if(par.getFlagKarma()){
[187]703    theStream<<setw(widthText)<<"Karma annotation file"               
704             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
[172]705             <<"  =  " <<resetiosflags(std::ios::right)
706             
707             <<par.getKarmaFile()      <<endl;
[20]708  }
[3]709  if(par.getFlagMaps()){
[187]710    theStream<<setw(widthText)<<"0th Moment Map"                       
711             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
[172]712             <<"  =  " <<resetiosflags(std::ios::right)
713             <<par.getMomentMap()      <<endl;
[187]714    theStream<<setw(widthText)<<"Detection Map"                       
715             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
[172]716             <<"  =  " <<resetiosflags(std::ios::right)
717             <<par.getDetectionMap()   <<endl;
[3]718  }
[195]719  theStream  <<setw(widthText)<<"Display a map in a pgplot xwindow?"
720             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
721             <<"  =  " <<resetiosflags(std::ios::right)
722             <<stringize(par.getFlagXOutput())     <<endl;
[3]723  if(par.getFlagATrous()){                             
[187]724    theStream<<setw(widthText)<<"Saving reconstructed cube?"           
725             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputrecon]"
[172]726             <<"  =  " <<resetiosflags(std::ios::right)
727             <<stringize(par.getFlagOutputRecon())<<endl;
[187]728    theStream<<setw(widthText)<<"Saving residuals from reconstruction?"
729             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputresid]"
[172]730             <<"  =  " <<resetiosflags(std::ios::right)
731             <<stringize(par.getFlagOutputResid())<<endl;
[3]732  }                                                   
[208]733  if(par.getFlagSmooth()){                             
734    theStream<<setw(widthText)<<"Saving Hanning-smoothed cube?"           
735             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputsmooth]"
736             <<"  =  " <<resetiosflags(std::ios::right)
737             <<stringize(par.getFlagOutputSmooth())<<endl;
738  }                                                   
[60]739  theStream  <<"------"<<endl;
[187]740  theStream  <<setw(widthText)<<"Searching for Negative features?"     
741             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
[172]742             <<"  =  " <<resetiosflags(std::ios::right)
743             <<stringize(par.getFlagNegative())   <<endl;
[187]744  theStream  <<setw(widthText)<<"Fixing Blank Pixels?"                 
745             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBlankPix]"
[172]746             <<"  =  " <<resetiosflags(std::ios::right)
747             <<stringize(par.getFlagBlankPix())   <<endl;
[3]748  if(par.getFlagBlankPix()){
[187]749    theStream<<setw(widthText)<<"Blank Pixel Value"                   
750             <<setw(widthPar)<<setiosflags(std::ios::right)<< blankParam
[172]751             <<"  =  " <<resetiosflags(std::ios::right)
752             <<par.getBlankPixVal()    <<endl;
[3]753  }
[187]754  theStream  <<setw(widthText)<<"Removing Milky Way channels?"         
755             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
[172]756             <<"  =  " <<resetiosflags(std::ios::right)
757             <<stringize(par.getFlagMW())         <<endl;
[3]758  if(par.getFlagMW()){
[187]759    theStream<<setw(widthText)<<"Milky Way Channels"                   
760             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
[172]761             <<"  =  " <<resetiosflags(std::ios::right)
762             <<par.getMinMW()
[103]763             <<"-" <<par.getMaxMW()          <<endl;
[3]764  }
[187]765  theStream  <<setw(widthText)<<"Beam Size (pixels)"                   
766             <<setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
[172]767             <<"  =  " <<resetiosflags(std::ios::right)
768             <<par.getBeamSize()       <<endl;
[187]769  theStream  <<setw(widthText)<<"Removing baselines before search?"   
770             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
[172]771             <<"  =  " <<resetiosflags(std::ios::right)
772             <<stringize(par.getFlagBaseline())   <<endl;
[187]773  theStream  <<setw(widthText)<<"Minimum # Pixels in a detection"     
774             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
[172]775             <<"  =  " <<resetiosflags(std::ios::right)
776             <<par.getMinPix()         <<endl;
[187]777  theStream  <<setw(widthText)<<"Minimum # Channels in a detection"   
778             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
[172]779             <<"  =  " <<resetiosflags(std::ios::right)
780             <<par.getMinChannels()    <<endl;
[187]781  theStream  <<setw(widthText)<<"Growing objects after detection?"     
782             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
[172]783             <<"  =  " <<resetiosflags(std::ios::right)
784             <<stringize(par.getFlagGrowth())     <<endl;
[3]785  if(par.getFlagGrowth()) {                           
[187]786    theStream<<setw(widthText)<<"SNR Threshold for growth"             
787             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
[172]788             <<"  =  " <<resetiosflags(std::ios::right)
789             <<par.getGrowthCut()      <<endl;
[3]790  }
[201]791  theStream  <<setw(widthText)<<"Hanning-smoothing each spectrum first?"       
792             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
793             <<"  =  " <<resetiosflags(std::ios::right)
794             <<stringize(par.getFlagSmooth())     <<endl;
795  if(par.getFlagSmooth())                             
796    theStream<<setw(widthText)<<"Width of hanning filter"     
797             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
798             <<"  =  " <<resetiosflags(std::ios::right)
799             <<par.getHanningWidth()       <<endl;
[187]800  theStream  <<setw(widthText)<<"Using A Trous reconstruction?"       
801             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
[172]802             <<"  =  " <<resetiosflags(std::ios::right)
803             <<stringize(par.getFlagATrous())     <<endl;
[3]804  if(par.getFlagATrous()){                             
[187]805    theStream<<setw(widthText)<<"Number of dimensions in reconstruction"     
806             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
[172]807             <<"  =  " <<resetiosflags(std::ios::right)
808             <<par.getReconDim()       <<endl;
[187]809    theStream<<setw(widthText)<<"Minimum scale in reconstruction"     
810             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
[172]811             <<"  =  " <<resetiosflags(std::ios::right)
812             <<par.getMinScale()       <<endl;
[187]813    theStream<<setw(widthText)<<"SNR Threshold within reconstruction" 
814             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
[172]815             <<"  =  " <<resetiosflags(std::ios::right)
816             <<par.getAtrousCut()      <<endl;
[187]817    theStream<<setw(widthText)<<"Filter being used for reconstruction"
818             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
[172]819             <<"  =  " <<resetiosflags(std::ios::right)
820             <<par.getFilterCode()
[103]821             << " (" << par.getFilterName()  << ")" <<endl;
[3]822  }                                                   
[187]823  theStream  <<setw(widthText)<<"Using FDR analysis?"                 
824             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
[172]825             <<"  =  " <<resetiosflags(std::ios::right)
826             <<stringize(par.getFlagFDR())        <<endl;
[3]827  if(par.getFlagFDR()){                               
[187]828    theStream<<setw(widthText)<<"Alpha value for FDR analysis"         
829             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
[172]830             <<"  =  " <<resetiosflags(std::ios::right)
831             <<par.getAlpha()          <<endl;
[3]832  }                                                   
833  else {
[190]834    if(par.getFlagUserThreshold()){
[189]835      theStream<<setw(widthText)<<"Detection Threshold"                       
836               <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
837               <<"  =  " <<resetiosflags(std::ios::right)
838               <<par.getThreshold()            <<endl;
839    }
840    else{
841      theStream<<setw(widthText)<<"SNR Threshold (in sigma)"
842               <<setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
843               <<"  =  " <<resetiosflags(std::ios::right)
844               <<par.getCut()            <<endl;
845    }
[3]846  }
[187]847  theStream  <<setw(widthText)<<"Using Adjacent-pixel criterion?"     
848             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
[172]849             <<"  =  " <<resetiosflags(std::ios::right)
850             <<stringize(par.getFlagAdjacent())   <<endl;
[3]851  if(!par.getFlagAdjacent()){
[187]852    theStream<<setw(widthText)<<"Max. spatial separation for merging" 
853             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
[172]854             <<"  =  " <<resetiosflags(std::ios::right)
855             <<par.getThreshS()        <<endl;
[3]856  }
[187]857  theStream  <<setw(widthText)<<"Max. velocity separation for merging"
858             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
[172]859             <<"  =  " <<resetiosflags(std::ios::right)
860             <<par.getThreshV()        <<endl;
[187]861  theStream  <<setw(widthText)<<"Method of spectral plotting"         
862             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
[172]863             <<"  =  " <<resetiosflags(std::ios::right)
864             <<par.getSpectralMethod() <<endl;
[219]865  theStream  <<"--------------------\n\n";
[103]866  theStream  << std::setfill(' ');
[3]867  theStream.unsetf(std::ios::left);
[110]868  //  theStream.unsetf(std::ios::boolalpha);
[3]869}
870
[120]871
[112]872void Param::copyHeaderInfo(FitsHeader &head)
873{
874  /**
875   * A function to copy across relevant header keywords from the
876   *  FitsHeader class to the Param class, as they are needed by
877   *  functions in the Param class.
[221]878   * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
[112]879   */
880
881  this->blankKeyword  = head.getBlankKeyword();
882  this->bscaleKeyword = head.getBscaleKeyword();
883  this->bzeroKeyword  = head.getBzeroKeyword();
[159]884  this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
885    this->bzeroKeyword;
[112]886
887  this->numPixBeam    = head.getBeamSize();
888}
889
[208]890string Param::outputSmoothFile()
891{
892  /**
[221]893   * This function produces the required filename in which to save
894   *  the Hanning-smoothed array. If the input image is image.fits, then
895   *  the output will be eg. image.SMOOTH-3.fits, where the width of the
896   *  Hanning filter was 3 pixels.
[208]897   */
898  string inputName = this->imageFile;
899  std::stringstream ss;
900  ss << inputName.substr(0,inputName.size()-5); 
901                          // remove the ".fits" on the end.
902  if(this->flagSubsection) ss<<".sub";
903  ss << ".SMOOTH-" << this->hanningWidth
904     << ".fits";
905  return ss.str();
906}
907
[103]908string Param::outputReconFile()
909{
910  /**
[221]911   * This function produces the required filename in which to save
912   *  the reconstructed array. If the input image is image.fits, then
913   *  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
914   *  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
[103]915   */
916  string inputName = this->imageFile;
917  std::stringstream ss;
918  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
[106]919  if(this->flagSubsection) ss<<".sub";
[103]920  ss << ".RECON-" << this->reconDim
921     << "-"       << this->filterCode
922     << "-"       << this->snrRecon
923     << "-"       << this->scaleMin
924     << ".fits";
925  return ss.str();
926}
927
928string Param::outputResidFile()
929{
930  /**
[221]931   * This function produces the required filename in which to save
932   *  the reconstructed array. If the input image is image.fits, then
933   *  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
934   *  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
[103]935   */
936  string inputName = this->imageFile;
937  std::stringstream ss;
938  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
[106]939  if(this->flagSubsection) ss<<".sub";
[103]940  ss << ".RESID-" << this->reconDim
941     << "-"       << this->filterCode
942     << "-"       << this->snrRecon
943     << "-"       << this->scaleMin
944     << ".fits";
945  return ss.str();
946}
Note: See TracBrowser for help on using the repository browser.