source: tags/release-1.0.7/src/param.cc

Last change on this file was 213, checked in by Matthew Whiting, 18 years ago

Summary:

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