source: trunk/src/param.cc @ 201

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