source: trunk/src/param.cc @ 191

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

Large commit. The addition of a new Statistics namespace & class, plus a number of changes to the code to make the cube-wide statistics calculation work. The FDR calculations are incorporated into the new class, and a number of functions have been made into templates to ease the calculations. Details follow:

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