source: trunk/src/param.cc @ 203

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

Clarified error message in Param::fixUnits for the case where the spectral units are not specified in the FITS header.

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