source: tags/release-1.0.5/src/param.cc @ 1455

Last change on this file since 1455 was 185, checked in by Matthew Whiting, 18 years ago

Fixed a minor bug from the previous commit.

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