source: trunk/src/param.cc @ 167

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

A series of changes, prompted by the need to update the subsections parsing
to make it compliant with the new multi-dimensional FITS formalism.
Specifically:

  • FitsIO/subsection.cc
    • New file. Main task the Param::verifySubsection() function. Makes sure the subsection has correct format and number of axes.

Also removes any steps in the subsection string.

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