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
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
6#include <stdlib.h>
7#include <math.h>
8#include <wcs.h>
9#include <wcsunits.h>
10#include <param.hh>
11#include <config.h>
12#include <duchamp.hh>
13#include <Utils/utils.hh>
14
15// Define funtion to print bools as words, in case the compiler doesn't
16//  recognise the setf(ios::boolalpha) command...
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
33using std::setw;
34using std::endl;
35
36/****************************************************************/
37///////////////////////////////////////////////////
38//// Functions for FitsHeader class:
39///////////////////////////////////////////////////
40
41FitsHeader::FitsHeader()
42{
43  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
44  this->wcs->flag=-1;
45  wcsini(true, 3, this->wcs);
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
54FitsHeader::FitsHeader(const FitsHeader& h)
55{
56  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
57  this->wcs->flag=-1;
58  wcsini(true, h.wcs->naxis, this->wcs);
59  wcscopy(true, h.wcs, this->wcs);
60  wcsset(this->wcs);
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;
75}
76
77FitsHeader& FitsHeader::operator= (const FitsHeader& h)
78{
79  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
80  this->wcs->flag=-1;
81  wcsini(true, h.wcs->naxis, this->wcs);
82  wcscopy(true, h.wcs, this->wcs);
83  wcsset(this->wcs);
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;
98}
99
100void FitsHeader::setWCS(struct wcsprm *w)
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.
108   * \param w A WCSLIB wcsprm struct with the correct parameters.
109   */
110  wcscopy(true, w, this->wcs);
111  wcsset(this->wcs);
112  if( (w->lng!=-1) && (w->lat!=-1) ) this->wcsIsGood = true;
113}
114
115struct wcsprm *FitsHeader::getWCS()
116{
117  /**
118   *  A function that returns a properly initilized wcsprm object
119   *  corresponding to the WCS.
120   */
121  struct wcsprm *wNew = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
122  wNew->flag=-1;
123  wcsini(true, this->wcs->naxis, wNew);
124  wcscopy(true, this->wcs, wNew);
125  wcsset(wNew);
126  return wNew;
127}
128
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
143double FitsHeader::pixToVel(double &x, double &y, double &z)
144{
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;
156  return vel;
157}
158
159double* FitsHeader::pixToVel(double &x, double &y, double *zarray, int size)
160{
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++){
165      pix[3*i]   = x;
166      pix[3*i+1] = y;
167      pix[3*i+2] = zarray[i];
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;
174  }
175  else{
176    for(int i=0;i<size;i++) newzarray[i] = zarray[i];
177  }
178  return newzarray;
179}
180
181double  FitsHeader::specToVel(const double &coord)
182{
183  double vel;
184  if(power==1.0) vel =  coord*this->scale + this->offset;
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{
196  if(strcmp(this->wcs->lngtyp,"RA")==0)
197    return getIAUNameEQ(ra, dec, this->wcs->equinox);
198  else
199    return getIAUNameGAL(ra, dec);
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){
211    int status = wcsunits( this->wcs->cunit[this->wcs->spec],
212                         this->spectralUnits.c_str(),
213                         &sc, &of, &po);
214    if(status > 0){
215      std::stringstream errmsg;
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";
221      this->spectralUnits = this->wcs->cunit[this->wcs->spec];
222      if(this->spectralUnits==""){
223        errmsg <<
224          "Spectral units not specified. Setting them to 'SPC' for clarity.\n";
225        this->spectralUnits = "SPC";
226      }
227      duchampError("fixUnits", errmsg.str());
228     
229    }
230  }
231  this->scale = sc;
232  this->offset= of;
233  this->power = po;
234
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.
239  if(this->fluxUnits.size()>0){
240    if(this->fluxUnits.substr(this->fluxUnits.size()-5,
241                              this->fluxUnits.size()   ) == "/beam"){
242      this->intFluxUnits = this->fluxUnits.substr(0,this->fluxUnits.size()-5)
243        +" " +this->spectralUnits;
244    }
245    else this->intFluxUnits = this->fluxUnits + " " + this->spectralUnits;
246  }
247
248}
249
250/****************************************************************/
251///////////////////////////////////////////////////
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
261  this->imageFile         = "";
262  this->flagSubsection    = false;
263  this->subsection        = "[*,*,*]";
264  this->flagReconExists   = false;
265  this->reconFile         = "";
266  this->flagSmoothExists  = false;
267  this->smoothFile        = "";
268  // Output files
269  this->flagLog           = true;
270  this->logFile           = "duchamp-Logfile.txt";
271  this->outFile           = "duchamp-Results.txt";
272  this->spectraFile       = "duchamp-Spectra.ps";
273  this->flagOutputSmooth  = false;
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";
283  this->flagXOutput       = true;
284  // Cube related parameters
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;
296  // Trim-related         
297  this->flagTrimmed       = false;
298  this->borderLeft        = 0;
299  this->borderRight       = 0;
300  this->borderBottom      = 0;
301  this->borderTop         = 0;
302  // Subsection offsets
303  this->sizeOffsets       = 0;
304  this->xSubOffset        = 0;
305  this->ySubOffset        = 0;
306  this->zSubOffset        = 0;
307  // Baseline related
308  this->flagBaseline      = false;
309  // Detection-related   
310  this->flagNegative      = false;
311  // Object growth       
312  this->flagGrowth        = false;
313  this->growthCut         = 2.;
314  // FDR analysis         
315  this->flagFDR           = false;
316  this->alphaFDR          = 0.01;
317  // Other detection     
318  this->snrCut            = 3.;
319  this->threshold         = 0.;
320  this->flagUserThreshold = false;
321  // Hanning Smoothing
322  this->flagSmooth        = false;
323  this->hanningWidth      = 5;
324  // A trous reconstruction parameters
325  this->flagATrous        = true;
326  this->reconDim          = 3;
327  this->scaleMin          = 1;
328  this->snrRecon          = 4.;
329  this->filterCode        = 1;
330  // Volume-merging parameters
331  this->flagAdjacent      = true;
332  this->threshSpatial     = 3.;
333  this->threshVelocity    = 7.;
334  this->minChannels       = 3;
335  this->minPix            = 2;
336  // Input-Output related
337  this->spectralMethod    = "peak";
338  this->borders           = true;
339  this->blankEdge         = true;
340  this->verbose           = true;
341  this->spectralUnits     = "km/s";
342};
343
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;     
351  this->flagSmoothExists  = p.flagSmoothExists;
352  this->smoothFile        = p.smoothFile;     
353  this->flagLog           = p.flagLog;       
354  this->logFile           = p.logFile;       
355  this->outFile           = p.outFile;       
356  this->spectraFile       = p.spectraFile;   
357  this->flagOutputSmooth  = p.flagOutputSmooth;
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;
384  this->offsets           = new long[this->sizeOffsets];
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;
398  this->flagUserThreshold = p.flagUserThreshold;
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
417Param& Param::operator= (const Param& p)
418{
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;     
424  this->flagSmoothExists  = p.flagSmoothExists;
425  this->smoothFile        = p.smoothFile;     
426  this->flagLog           = p.flagLog;       
427  this->logFile           = p.logFile;       
428  this->outFile           = p.outFile;       
429  this->spectraFile       = p.spectraFile;   
430  this->flagOutputSmooth  = p.flagOutputSmooth;
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;     
440  this->flagXOutput       = p.flagXOutput;       
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;     
456  this->sizeOffsets       = p.sizeOffsets;
457  this->offsets           = new long[this->sizeOffsets];
458  if(this->sizeOffsets>0)
459    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
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;
471  this->flagUserThreshold = p.flagUserThreshold;
472  this->flagSmooth        = p.flagSmooth;
473  this->hanningWidth      = p.hanningWidth;
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;
488}
489
490/****************************************************************/
491///////////////////////////////////////////////////
492//// Other Functions using the  Parameter class:
493///////////////////////////////////////////////////
494
495inline string makelower( string s )
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
505inline bool boolify( string s )
506{
507  /**
508   * bool boolify(string)
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
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
538int Param::readParams(string paramfile)
539{
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   */
550  std::ifstream fin(paramfile.c_str());
551  if(!fin.is_open()) return FAILURE;
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;
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);
566      if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
567      if(arg=="smoothfile")      this->smoothFile = readSval(ss);
568
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);
573      if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
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);
583      if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
584
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);
592
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);
597
598      if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
599      if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
600
601      if(arg=="snrcut")          this->snrCut = readFval(ss);
602      if(arg=="threshold"){
603                                 this->threshold = readFval(ss);
604                                 this->flagUserThreshold = true;
605      }
606     
607      if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
608      if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
609
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);
615
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);
620
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);
626    }
627  }
628  if(this->flagATrous) this->flagSmooth = false;
629  return SUCCESS;
630}
631
632
633std::ostream& operator<< ( std::ostream& theStream, Param& par)
634{
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
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]";
644  string beamParam = "";
645  if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
646
647  // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
648  //   theStream.setf(std::ios::boolalpha);
649  theStream.setf(std::ios::left);
650  theStream  <<"\n---- Parameters ----"<<endl;
651  theStream  << std::setfill('.');
652  const int widthText = 38;
653  const int widthPar  = 18;
654  if(par.getFlagSubsection())
655    theStream<<setw(widthText)<<"Image to be analysed"                 
656             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
657             <<"  =  " <<resetiosflags(std::ios::right)
658             <<(par.getImageFile()+par.getSubsection()) <<endl;
659  else
660    theStream<<setw(widthText)<<"Image to be analysed"                 
661             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
662             <<"  =  " <<resetiosflags(std::ios::right)
663             <<par.getImageFile()      <<endl;
664  if(par.getFlagReconExists() && par.getFlagATrous()){
665    theStream<<setw(widthText)<<"Reconstructed array exists?"         
666             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
667             <<"  =  " <<resetiosflags(std::ios::right)
668             <<stringize(par.getFlagReconExists())<<endl;
669    theStream<<setw(widthText)<<"FITS file containing reconstruction" 
670             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
671             <<"  =  " <<resetiosflags(std::ios::right)
672             <<par.getReconFile()      <<endl;
673  }
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  }
684  theStream  <<setw(widthText)<<"Intermediate Logfile"
685             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
686             <<"  =  " <<resetiosflags(std::ios::right)
687             <<par.getLogFile()        <<endl;
688  theStream  <<setw(widthText)<<"Final Results file"                   
689             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
690             <<"  =  " <<resetiosflags(std::ios::right)
691             <<par.getOutFile()        <<endl;
692  theStream  <<setw(widthText)<<"Spectrum file"                       
693             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
694             <<"  =  " <<resetiosflags(std::ios::right)
695             <<par.getSpectraFile()    <<endl;
696  if(par.getFlagVOT()){
697    theStream<<setw(widthText)<<"VOTable file"                         
698             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
699             <<"  =  " <<resetiosflags(std::ios::right)
700             <<par.getVOTFile()        <<endl;
701  }
702  if(par.getFlagKarma()){
703    theStream<<setw(widthText)<<"Karma annotation file"               
704             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
705             <<"  =  " <<resetiosflags(std::ios::right)
706             
707             <<par.getKarmaFile()      <<endl;
708  }
709  if(par.getFlagMaps()){
710    theStream<<setw(widthText)<<"0th Moment Map"                       
711             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
712             <<"  =  " <<resetiosflags(std::ios::right)
713             <<par.getMomentMap()      <<endl;
714    theStream<<setw(widthText)<<"Detection Map"                       
715             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
716             <<"  =  " <<resetiosflags(std::ios::right)
717             <<par.getDetectionMap()   <<endl;
718  }
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;
723  if(par.getFlagATrous()){                             
724    theStream<<setw(widthText)<<"Saving reconstructed cube?"           
725             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputrecon]"
726             <<"  =  " <<resetiosflags(std::ios::right)
727             <<stringize(par.getFlagOutputRecon())<<endl;
728    theStream<<setw(widthText)<<"Saving residuals from reconstruction?"
729             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputresid]"
730             <<"  =  " <<resetiosflags(std::ios::right)
731             <<stringize(par.getFlagOutputResid())<<endl;
732  }                                                   
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  }                                                   
739  theStream  <<"------"<<endl;
740  theStream  <<setw(widthText)<<"Searching for Negative features?"     
741             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
742             <<"  =  " <<resetiosflags(std::ios::right)
743             <<stringize(par.getFlagNegative())   <<endl;
744  theStream  <<setw(widthText)<<"Fixing Blank Pixels?"                 
745             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBlankPix]"
746             <<"  =  " <<resetiosflags(std::ios::right)
747             <<stringize(par.getFlagBlankPix())   <<endl;
748  if(par.getFlagBlankPix()){
749    theStream<<setw(widthText)<<"Blank Pixel Value"                   
750             <<setw(widthPar)<<setiosflags(std::ios::right)<< blankParam
751             <<"  =  " <<resetiosflags(std::ios::right)
752             <<par.getBlankPixVal()    <<endl;
753  }
754  theStream  <<setw(widthText)<<"Removing Milky Way channels?"         
755             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
756             <<"  =  " <<resetiosflags(std::ios::right)
757             <<stringize(par.getFlagMW())         <<endl;
758  if(par.getFlagMW()){
759    theStream<<setw(widthText)<<"Milky Way Channels"                   
760             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
761             <<"  =  " <<resetiosflags(std::ios::right)
762             <<par.getMinMW()
763             <<"-" <<par.getMaxMW()          <<endl;
764  }
765  theStream  <<setw(widthText)<<"Beam Size (pixels)"                   
766             <<setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
767             <<"  =  " <<resetiosflags(std::ios::right)
768             <<par.getBeamSize()       <<endl;
769  theStream  <<setw(widthText)<<"Removing baselines before search?"   
770             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
771             <<"  =  " <<resetiosflags(std::ios::right)
772             <<stringize(par.getFlagBaseline())   <<endl;
773  theStream  <<setw(widthText)<<"Minimum # Pixels in a detection"     
774             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
775             <<"  =  " <<resetiosflags(std::ios::right)
776             <<par.getMinPix()         <<endl;
777  theStream  <<setw(widthText)<<"Minimum # Channels in a detection"   
778             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
779             <<"  =  " <<resetiosflags(std::ios::right)
780             <<par.getMinChannels()    <<endl;
781  theStream  <<setw(widthText)<<"Growing objects after detection?"     
782             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
783             <<"  =  " <<resetiosflags(std::ios::right)
784             <<stringize(par.getFlagGrowth())     <<endl;
785  if(par.getFlagGrowth()) {                           
786    theStream<<setw(widthText)<<"SNR Threshold for growth"             
787             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
788             <<"  =  " <<resetiosflags(std::ios::right)
789             <<par.getGrowthCut()      <<endl;
790  }
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;
800  theStream  <<setw(widthText)<<"Using A Trous reconstruction?"       
801             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
802             <<"  =  " <<resetiosflags(std::ios::right)
803             <<stringize(par.getFlagATrous())     <<endl;
804  if(par.getFlagATrous()){                             
805    theStream<<setw(widthText)<<"Number of dimensions in reconstruction"     
806             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
807             <<"  =  " <<resetiosflags(std::ios::right)
808             <<par.getReconDim()       <<endl;
809    theStream<<setw(widthText)<<"Minimum scale in reconstruction"     
810             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
811             <<"  =  " <<resetiosflags(std::ios::right)
812             <<par.getMinScale()       <<endl;
813    theStream<<setw(widthText)<<"SNR Threshold within reconstruction" 
814             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
815             <<"  =  " <<resetiosflags(std::ios::right)
816             <<par.getAtrousCut()      <<endl;
817    theStream<<setw(widthText)<<"Filter being used for reconstruction"
818             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
819             <<"  =  " <<resetiosflags(std::ios::right)
820             <<par.getFilterCode()
821             << " (" << par.getFilterName()  << ")" <<endl;
822  }                                                   
823  theStream  <<setw(widthText)<<"Using FDR analysis?"                 
824             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
825             <<"  =  " <<resetiosflags(std::ios::right)
826             <<stringize(par.getFlagFDR())        <<endl;
827  if(par.getFlagFDR()){                               
828    theStream<<setw(widthText)<<"Alpha value for FDR analysis"         
829             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
830             <<"  =  " <<resetiosflags(std::ios::right)
831             <<par.getAlpha()          <<endl;
832  }                                                   
833  else {
834    if(par.getFlagUserThreshold()){
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    }
846  }
847  theStream  <<setw(widthText)<<"Using Adjacent-pixel criterion?"     
848             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
849             <<"  =  " <<resetiosflags(std::ios::right)
850             <<stringize(par.getFlagAdjacent())   <<endl;
851  if(!par.getFlagAdjacent()){
852    theStream<<setw(widthText)<<"Max. spatial separation for merging" 
853             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
854             <<"  =  " <<resetiosflags(std::ios::right)
855             <<par.getThreshS()        <<endl;
856  }
857  theStream  <<setw(widthText)<<"Max. velocity separation for merging"
858             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
859             <<"  =  " <<resetiosflags(std::ios::right)
860             <<par.getThreshV()        <<endl;
861  theStream  <<setw(widthText)<<"Method of spectral plotting"         
862             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
863             <<"  =  " <<resetiosflags(std::ios::right)
864             <<par.getSpectralMethod() <<endl;
865  theStream  <<"--------------------\n\n";
866  theStream  << std::setfill(' ');
867  theStream.unsetf(std::ios::left);
868  //  theStream.unsetf(std::ios::boolalpha);
869}
870
871
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.
878   * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
879   */
880
881  this->blankKeyword  = head.getBlankKeyword();
882  this->bscaleKeyword = head.getBscaleKeyword();
883  this->bzeroKeyword  = head.getBzeroKeyword();
884  this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
885    this->bzeroKeyword;
886
887  this->numPixBeam    = head.getBeamSize();
888}
889
890string Param::outputSmoothFile()
891{
892  /**
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.
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
908string Param::outputReconFile()
909{
910  /**
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
915   */
916  string inputName = this->imageFile;
917  std::stringstream ss;
918  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
919  if(this->flagSubsection) ss<<".sub";
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  /**
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
935   */
936  string inputName = this->imageFile;
937  std::stringstream ss;
938  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
939  if(this->flagSubsection) ss<<".sub";
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.