source: trunk/src/param.cc @ 188

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

Large suite of edits, mostly due to testing with valgrind, which clear up bad memory allocations and so on.
Improved the printing of progress bars in some routines by introducing a new ProgressBar? class, with associated functions to do the printing (now much cleaner).

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