source: tags/release-1.0.6/src/param.cc @ 1391

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

Implemented a request (from ticket:1) for the ability to not display the pgplot
window showing the moment map. This is now switched on and off by the
flagXOutput parameter.
Updated code and documentation.

File size: 29.2 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
15//  recognise 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  this->flagXOutput       = true;
269  // Cube related parameters
270  this->flagBlankPix      = true;
271  this->blankPixValue     = -8.00061;
272  this->blankKeyword      = 1;
273  this->bscaleKeyword     = -8.00061;
274  this->bzeroKeyword      = 0.;
275  this->flagUsingBlank    = false;
276  this->flagMW            = false;
277  this->maxMW             = 112;
278  this->minMW             = 75;
279  this->numPixBeam        = 10.;
280  this->flagUsingBeam     = false;
281  // Trim-related         
282  this->flagTrimmed       = false;
283  this->borderLeft        = 0;
284  this->borderRight       = 0;
285  this->borderBottom      = 0;
286  this->borderTop         = 0;
287  // Subsection offsets
288  this->xSubOffset        = 0;
289  this->ySubOffset        = 0;
290  this->zSubOffset        = 0;
291  // Baseline related
292  this->flagBaseline      = false;
293  // Detection-related   
294  this->flagNegative      = false;
295  // Object growth       
296  this->flagGrowth        = false;
297  this->growthCut         = 2.;
298  // FDR analysis         
299  this->flagFDR           = false;
300  this->alphaFDR          = 0.01;
301  // Other detection     
302  this->snrCut            = 3.;
303  this->threshold         = 0.;
304  this->flagUserThreshold = false;
305  // A trous reconstruction parameters
306  this->flagATrous        = true;
307  this->reconDim          = 3;
308  this->scaleMin          = 1;
309  this->snrRecon          = 4.;
310  this->filterCode        = 1;
311  // Volume-merging parameters
312  this->flagAdjacent      = true;
313  this->threshSpatial     = 3.;
314  this->threshVelocity    = 7.;
315  this->minChannels       = 3;
316  this->minPix            = 2;
317  // Input-Output related
318  this->spectralMethod    = "peak";
319  this->borders           = true;
320  this->blankEdge         = true;
321  this->verbose           = true;
322  this->spectralUnits     = "km/s";
323};
324
325Param& Param::operator= (const Param& p)
326{
327  this->imageFile         = p.imageFile;
328  this->flagSubsection    = p.flagSubsection;
329  this->subsection        = p.subsection;     
330  this->flagReconExists   = p.flagReconExists;
331  this->reconFile         = p.reconFile;     
332  this->flagLog           = p.flagLog;       
333  this->logFile           = p.logFile;       
334  this->outFile           = p.outFile;       
335  this->spectraFile       = p.spectraFile;   
336  this->flagOutputRecon   = p.flagOutputRecon;
337  this->flagOutputResid   = p.flagOutputResid;
338  this->flagVOT           = p.flagVOT;         
339  this->votFile           = p.votFile;       
340  this->flagKarma         = p.flagKarma;     
341  this->karmaFile         = p.karmaFile;     
342  this->flagMaps          = p.flagMaps;       
343  this->detectionMap      = p.detectionMap;   
344  this->momentMap         = p.momentMap;     
345  this->flagXOutput       = p.flagXOutput;       
346  this->flagBlankPix      = p.flagBlankPix;   
347  this->blankPixValue     = p.blankPixValue; 
348  this->blankKeyword      = p.blankKeyword;   
349  this->bscaleKeyword     = p.bscaleKeyword; 
350  this->bzeroKeyword      = p.bzeroKeyword;   
351  this->flagUsingBlank    = p.flagUsingBlank;
352  this->flagMW            = p.flagMW;         
353  this->maxMW             = p.maxMW;         
354  this->minMW             = p.minMW;         
355  this->numPixBeam        = p.numPixBeam;     
356  this->flagTrimmed       = p.flagTrimmed;   
357  this->borderLeft        = p.borderLeft;     
358  this->borderRight       = p.borderRight;   
359  this->borderBottom      = p.borderBottom;   
360  this->borderTop         = p.borderTop;     
361  this->xSubOffset        = p.xSubOffset;     
362  this->ySubOffset        = p.ySubOffset;     
363  this->zSubOffset        = p.zSubOffset;
364  this->flagBaseline      = p.flagBaseline;
365  this->flagNegative      = p.flagNegative;
366  this->flagGrowth        = p.flagGrowth;
367  this->growthCut         = p.growthCut;
368  this->flagFDR           = p.flagFDR;
369  this->alphaFDR          = p.alphaFDR;
370  this->snrCut            = p.snrCut;
371  this->threshold         = p.threshold;
372  this->flagUserThreshold = p.threshold;
373  this->flagATrous        = p.flagATrous;
374  this->reconDim          = p.reconDim;
375  this->scaleMin          = p.scaleMin;
376  this->snrRecon          = p.snrRecon;
377  this->filterCode        = p.filterCode;
378  this->flagAdjacent      = p.flagAdjacent;
379  this->threshSpatial     = p.threshSpatial;
380  this->threshVelocity    = p.threshVelocity;
381  this->minChannels       = p.minChannels;
382  this->minPix            = p.minPix;
383  this->spectralMethod    = p.spectralMethod;
384  this->borders           = p.borders;
385  this->verbose           = p.verbose;
386  this->spectralUnits     = p.spectralUnits;
387}
388
389/****************************************************************/
390///////////////////////////////////////////////////
391//// Other Functions using the  Parameter class:
392///////////////////////////////////////////////////
393
394inline string makelower( string s )
395{
396  // "borrowed" from Matt Howlett's 'fred'
397  string out = "";
398  for( int i=0; i<s.size(); ++i ) {
399    out += tolower(s[i]);
400  }
401  return out;
402}
403
404inline bool boolify( string s )
405{
406  /**
407   * bool boolify(string)
408   *  Convert a string to a bool variable
409   *  "1" and "true" get converted to true
410   *  "0" and "false" (and anything else) get converted to false
411   */
412  if((s=="1") || (makelower(s)=="true")) return true;
413  else if((s=="0") || (makelower(s)=="false")) return false;
414  else return false;
415}
416
417inline string readSval(std::stringstream& ss)
418{
419  string val; ss >> val; return val;
420}
421
422inline bool readFlag(std::stringstream& ss)
423{
424  string val; ss >> val; return boolify(val);
425}
426
427inline float readFval(std::stringstream& ss)
428{
429  float val; ss >> val; return val;
430}
431
432inline int readIval(std::stringstream& ss)
433{
434  int val; ss >> val; return val;
435}
436
437int Param::readParams(string paramfile)
438{
439
440  std::ifstream fin(paramfile.c_str());
441  if(!fin.is_open()) return FAILURE;
442  string line;
443  while( !std::getline(fin,line,'\n').eof()){
444
445    if(line[0]!='#'){
446      std::stringstream ss;
447      ss.str(line);
448      string arg;
449      ss >> arg;
450      arg = makelower(arg);
451      if(arg=="imagefile")       this->imageFile = readSval(ss);
452      if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
453      if(arg=="subsection")      this->subsection = readSval(ss);
454      if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
455      if(arg=="reconfile")       this->reconFile = readSval(ss);
456
457      if(arg=="flaglog")         this->flagLog = readFlag(ss);
458      if(arg=="logfile")         this->logFile = readSval(ss);
459      if(arg=="outfile")         this->outFile = readSval(ss);
460      if(arg=="spectrafile")     this->spectraFile = readSval(ss);
461      if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
462      if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
463      if(arg=="flagvot")         this->flagVOT = readFlag(ss);
464      if(arg=="votfile")         this->votFile = readSval(ss);
465      if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
466      if(arg=="karmafile")       this->karmaFile = readSval(ss);
467      if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
468      if(arg=="detectionmap")    this->detectionMap = readSval(ss);
469      if(arg=="momentmap")       this->momentMap = readSval(ss);
470      if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
471
472      if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
473      if(arg=="flagblankpix")    this->flagBlankPix = readFlag(ss);
474      if(arg=="blankpixvalue")   this->blankPixValue = readFval(ss);
475      if(arg=="flagmw")          this->flagMW = readFlag(ss);
476      if(arg=="maxmw")           this->maxMW = readIval(ss);
477      if(arg=="minmw")           this->minMW = readIval(ss);
478      if(arg=="beamsize")        this->numPixBeam = readFval(ss);
479
480      if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
481      if(arg=="minpix")          this->minPix = readIval(ss);
482      if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
483      if(arg=="growthcut")       this->growthCut = readFval(ss);
484
485      if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
486      if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
487
488      if(arg=="snrcut")          this->snrCut = readFval(ss);
489      if(arg=="threshold"){
490                                 this->threshold = readFval(ss);
491                                 this->flagUserThreshold = true;
492      }
493
494      if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
495      if(arg=="recondim")        this->reconDim = readIval(ss);
496      if(arg=="scalemin")        this->scaleMin = readIval(ss);
497      if(arg=="snrrecon")        this->snrRecon = readFval(ss);
498      if(arg=="filtercode")      this->filterCode = readIval(ss);
499
500      if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
501      if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
502      if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
503      if(arg=="minchannels")     this->minChannels = readIval(ss);
504
505      if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
506      if(arg=="spectralunits")   this->spectralUnits=makelower(readSval(ss));
507      if(arg=="drawborders")     this->borders = readFlag(ss);
508      if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
509      if(arg=="verbose")         this->verbose = readFlag(ss);
510    }
511  }
512  return SUCCESS;
513}
514
515
516std::ostream& operator<< ( std::ostream& theStream, Param& par)
517{
518  // Only show the [blankPixValue] bit if we are using the parameter
519  // otherwise we have read it from the FITS header.
520  string blankParam = "";
521  if(par.getFlagUsingBlank()) blankParam = "[blankPixValue]";
522  string beamParam = "";
523  if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
524
525  // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
526  //   theStream.setf(std::ios::boolalpha);
527  theStream.setf(std::ios::left);
528  theStream  <<"---- Parameters ----"<<endl;
529  theStream  << std::setfill('.');
530  const int widthText = 38;
531  const int widthPar  = 18;
532  if(par.getFlagSubsection())
533    theStream<<setw(widthText)<<"Image to be analysed"                 
534             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
535             <<"  =  " <<resetiosflags(std::ios::right)
536             <<(par.getImageFile()+par.getSubsection()) <<endl;
537  else
538    theStream<<setw(widthText)<<"Image to be analysed"                 
539             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
540             <<"  =  " <<resetiosflags(std::ios::right)
541             <<par.getImageFile()      <<endl;
542  if(par.getFlagReconExists() && par.getFlagATrous()){
543    theStream<<setw(widthText)<<"Reconstructed array exists?"         
544             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
545             <<"  =  " <<resetiosflags(std::ios::right)
546             <<stringize(par.getFlagReconExists())<<endl;
547    theStream<<setw(widthText)<<"FITS file containing reconstruction" 
548             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
549             <<"  =  " <<resetiosflags(std::ios::right)
550             <<par.getReconFile()      <<endl;
551  }
552  theStream  <<setw(widthText)<<"Intermediate Logfile"
553             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
554             <<"  =  " <<resetiosflags(std::ios::right)
555             <<par.getLogFile()        <<endl;
556  theStream  <<setw(widthText)<<"Final Results file"                   
557             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
558             <<"  =  " <<resetiosflags(std::ios::right)
559             <<par.getOutFile()        <<endl;
560  theStream  <<setw(widthText)<<"Spectrum file"                       
561             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
562             <<"  =  " <<resetiosflags(std::ios::right)
563             <<par.getSpectraFile()    <<endl;
564  if(par.getFlagVOT()){
565    theStream<<setw(widthText)<<"VOTable file"                         
566             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
567             <<"  =  " <<resetiosflags(std::ios::right)
568             <<par.getVOTFile()        <<endl;
569  }
570  if(par.getFlagKarma()){
571    theStream<<setw(widthText)<<"Karma annotation file"               
572             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
573             <<"  =  " <<resetiosflags(std::ios::right)
574             
575             <<par.getKarmaFile()      <<endl;
576  }
577  if(par.getFlagMaps()){
578    theStream<<setw(widthText)<<"0th Moment Map"                       
579             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
580             <<"  =  " <<resetiosflags(std::ios::right)
581             <<par.getMomentMap()      <<endl;
582    theStream<<setw(widthText)<<"Detection Map"                       
583             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
584             <<"  =  " <<resetiosflags(std::ios::right)
585             <<par.getDetectionMap()   <<endl;
586  }
587  theStream  <<setw(widthText)<<"Display a map in a pgplot xwindow?"
588             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
589             <<"  =  " <<resetiosflags(std::ios::right)
590             <<stringize(par.getFlagXOutput())     <<endl;
591  if(par.getFlagATrous()){                             
592    theStream<<setw(widthText)<<"Saving reconstructed cube?"           
593             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputrecon]"
594             <<"  =  " <<resetiosflags(std::ios::right)
595             <<stringize(par.getFlagOutputRecon())<<endl;
596    theStream<<setw(widthText)<<"Saving residuals from reconstruction?"
597             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputresid]"
598             <<"  =  " <<resetiosflags(std::ios::right)
599             <<stringize(par.getFlagOutputResid())<<endl;
600  }                                                   
601  theStream  <<"------"<<endl;
602  theStream  <<setw(widthText)<<"Searching for Negative features?"     
603             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
604             <<"  =  " <<resetiosflags(std::ios::right)
605             <<stringize(par.getFlagNegative())   <<endl;
606  theStream  <<setw(widthText)<<"Fixing Blank Pixels?"                 
607             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBlankPix]"
608             <<"  =  " <<resetiosflags(std::ios::right)
609             <<stringize(par.getFlagBlankPix())   <<endl;
610  if(par.getFlagBlankPix()){
611    theStream<<setw(widthText)<<"Blank Pixel Value"                   
612             <<setw(widthPar)<<setiosflags(std::ios::right)<< blankParam
613             <<"  =  " <<resetiosflags(std::ios::right)
614             <<par.getBlankPixVal()    <<endl;
615  }
616  theStream  <<setw(widthText)<<"Removing Milky Way channels?"         
617             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
618             <<"  =  " <<resetiosflags(std::ios::right)
619             <<stringize(par.getFlagMW())         <<endl;
620  if(par.getFlagMW()){
621    theStream<<setw(widthText)<<"Milky Way Channels"                   
622             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
623             <<"  =  " <<resetiosflags(std::ios::right)
624             <<par.getMinMW()
625             <<"-" <<par.getMaxMW()          <<endl;
626  }
627  theStream  <<setw(widthText)<<"Beam Size (pixels)"                   
628             <<setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
629             <<"  =  " <<resetiosflags(std::ios::right)
630             <<par.getBeamSize()       <<endl;
631  theStream  <<setw(widthText)<<"Removing baselines before search?"   
632             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
633             <<"  =  " <<resetiosflags(std::ios::right)
634             <<stringize(par.getFlagBaseline())   <<endl;
635  theStream  <<setw(widthText)<<"Minimum # Pixels in a detection"     
636             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
637             <<"  =  " <<resetiosflags(std::ios::right)
638             <<par.getMinPix()         <<endl;
639  theStream  <<setw(widthText)<<"Minimum # Channels in a detection"   
640             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
641             <<"  =  " <<resetiosflags(std::ios::right)
642             <<par.getMinChannels()    <<endl;
643  theStream  <<setw(widthText)<<"Growing objects after detection?"     
644             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
645             <<"  =  " <<resetiosflags(std::ios::right)
646             <<stringize(par.getFlagGrowth())     <<endl;
647  if(par.getFlagGrowth()) {                           
648    theStream<<setw(widthText)<<"SNR Threshold for growth"             
649             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
650             <<"  =  " <<resetiosflags(std::ios::right)
651             <<par.getGrowthCut()      <<endl;
652  }
653  theStream  <<setw(widthText)<<"Using A Trous reconstruction?"       
654             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
655             <<"  =  " <<resetiosflags(std::ios::right)
656             <<stringize(par.getFlagATrous())     <<endl;
657  if(par.getFlagATrous()){                             
658    theStream<<setw(widthText)<<"Number of dimensions in reconstruction"     
659             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
660             <<"  =  " <<resetiosflags(std::ios::right)
661             <<par.getReconDim()       <<endl;
662    theStream<<setw(widthText)<<"Minimum scale in reconstruction"     
663             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
664             <<"  =  " <<resetiosflags(std::ios::right)
665             <<par.getMinScale()       <<endl;
666    theStream<<setw(widthText)<<"SNR Threshold within reconstruction" 
667             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
668             <<"  =  " <<resetiosflags(std::ios::right)
669             <<par.getAtrousCut()      <<endl;
670    theStream<<setw(widthText)<<"Filter being used for reconstruction"
671             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
672             <<"  =  " <<resetiosflags(std::ios::right)
673             <<par.getFilterCode()
674             << " (" << par.getFilterName()  << ")" <<endl;
675  }                                                   
676  theStream  <<setw(widthText)<<"Using FDR analysis?"                 
677             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
678             <<"  =  " <<resetiosflags(std::ios::right)
679             <<stringize(par.getFlagFDR())        <<endl;
680  if(par.getFlagFDR()){                               
681    theStream<<setw(widthText)<<"Alpha value for FDR analysis"         
682             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
683             <<"  =  " <<resetiosflags(std::ios::right)
684             <<par.getAlpha()          <<endl;
685  }                                                   
686  else {
687    if(par.getFlagUserThreshold()){
688      theStream<<setw(widthText)<<"Detection Threshold"                       
689               <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
690               <<"  =  " <<resetiosflags(std::ios::right)
691               <<par.getThreshold()            <<endl;
692    }
693    else{
694      theStream<<setw(widthText)<<"SNR Threshold (in sigma)"
695               <<setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
696               <<"  =  " <<resetiosflags(std::ios::right)
697               <<par.getCut()            <<endl;
698    }
699  }
700  theStream  <<setw(widthText)<<"Using Adjacent-pixel criterion?"     
701             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
702             <<"  =  " <<resetiosflags(std::ios::right)
703             <<stringize(par.getFlagAdjacent())   <<endl;
704  if(!par.getFlagAdjacent()){
705    theStream<<setw(widthText)<<"Max. spatial separation for merging" 
706             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
707             <<"  =  " <<resetiosflags(std::ios::right)
708             <<par.getThreshS()        <<endl;
709  }
710  theStream  <<setw(widthText)<<"Max. velocity separation for merging"
711             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
712             <<"  =  " <<resetiosflags(std::ios::right)
713             <<par.getThreshV()        <<endl;
714  theStream  <<setw(widthText)<<"Method of spectral plotting"         
715             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
716             <<"  =  " <<resetiosflags(std::ios::right)
717             <<par.getSpectralMethod() <<endl;
718  theStream  <<"--------------------"<<endl;
719  theStream  << std::setfill(' ');
720  theStream.unsetf(std::ios::left);
721  //  theStream.unsetf(std::ios::boolalpha);
722}
723
724
725void Param::copyHeaderInfo(FitsHeader &head)
726{
727  /**
728   *  Param::copyHeaderInfo(FitsHeader &head)
729   * A function to copy across relevant header keywords from the
730   *  FitsHeader class to the Param class, as they are needed by
731   *  functions in the Param class.
732   */
733
734  this->blankKeyword  = head.getBlankKeyword();
735  this->bscaleKeyword = head.getBscaleKeyword();
736  this->bzeroKeyword  = head.getBzeroKeyword();
737  this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
738    this->bzeroKeyword;
739
740  this->numPixBeam    = head.getBeamSize();
741}
742
743bool Param::isBlank(float &value)
744{
745  /**
746   *  Param::isBlank(float)
747   *   Tests whether the value passed as the argument is BLANK or not.
748   *   If flagBlankPix is false, return false.
749   *   Otherwise, compare to the relevant FITS keywords, using integer
750   *     comparison.
751   *   Return a bool.
752   */
753
754  return this->flagBlankPix &&
755    (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
756}
757
758string Param::outputReconFile()
759{
760  /**
761   *  outputReconFile()
762   *
763   *   This function produces the required filename in which to save
764   *    the reconstructed array. If the input image is image.fits, then
765   *    the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
766   *    3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
767   */
768  string inputName = this->imageFile;
769  std::stringstream ss;
770  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
771  if(this->flagSubsection) ss<<".sub";
772  ss << ".RECON-" << this->reconDim
773     << "-"       << this->filterCode
774     << "-"       << this->snrRecon
775     << "-"       << this->scaleMin
776     << ".fits";
777  return ss.str();
778}
779
780string Param::outputResidFile()
781{
782  /**
783   *  outputResidFile()
784   *
785   *   This function produces the required filename in which to save
786   *    the reconstructed array. If the input image is image.fits, then
787   *    the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
788   *    3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
789   */
790  string inputName = this->imageFile;
791  std::stringstream ss;
792  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
793  if(this->flagSubsection) ss<<".sub";
794  ss << ".RESID-" << this->reconDim
795     << "-"       << this->filterCode
796     << "-"       << this->snrRecon
797     << "-"       << this->scaleMin
798     << ".fits";
799  return ss.str();
800}
Note: See TracBrowser for help on using the repository browser.