source: tags/release-1.0.5/src/param.cc @ 184

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

Some crucial edits so that things will work when the cube's WCS is not well defined.

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