source: trunk/src/param.cc @ 221

Last change on this file since 221 was 221, checked in by Matthew Whiting, 17 years ago

More documentation being added to source code, with a new file (src/Utils/Hanning.cc) added as well.

File size: 35.2 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
6#include <stdlib.h>
7#include <math.h>
8#include <wcs.h>
9#include <wcsunits.h>
10#include <param.hh>
11#include <config.h>
12#include <duchamp.hh>
13#include <Utils/utils.hh>
14
15// Define funtion to print bools as words, in case the compiler doesn't
16//  recognise the setf(ios::boolalpha) command...
17#ifdef HAVE_STDBOOL_H
18string stringize(bool b){
19  std::stringstream ss;
20  ss.setf(std::ios::boolalpha);
21  ss << b;
22  return ss.str();
23}
24#else
25string stringize(bool b){
26  std::string output;
27  if(b) output="true";
28  else output="false";
29  return output;
30}
31#endif
32
33using std::setw;
34using std::endl;
35
36/****************************************************************/
37///////////////////////////////////////////////////
38//// Functions for FitsHeader class:
39///////////////////////////////////////////////////
40
41FitsHeader::FitsHeader()
42{
43  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
44  this->wcs->flag=-1;
45  wcsini(true, 3, this->wcs);
46  this->wcsIsGood = false;
47  this->nwcs = 0;
48  this->scale=1.;
49  this->offset=0.;
50  this->power=1.;
51  this->fluxUnits="counts";
52}
53
54FitsHeader::FitsHeader(const FitsHeader& h)
55{
56  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
57  this->wcs->flag=-1;
58  wcsini(true, h.wcs->naxis, this->wcs);
59  wcscopy(true, h.wcs, this->wcs);
60  wcsset(this->wcs);
61  this->nwcs = h.nwcs;
62  this->wcsIsGood = h.wcsIsGood;
63  this->spectralUnits = h.spectralUnits;
64  this->fluxUnits = h.fluxUnits;
65  this->intFluxUnits = h.intFluxUnits;
66  this->beamSize = h.beamSize;
67  this->bmajKeyword = h.bmajKeyword;
68  this->bminKeyword = h.bminKeyword;
69  this->blankKeyword = h.blankKeyword;
70  this->bzeroKeyword = h.bzeroKeyword;
71  this->bscaleKeyword = h.bscaleKeyword;
72  this->scale = h.scale;
73  this->offset = h.offset;
74  this->power = h.power;
75}
76
77FitsHeader& FitsHeader::operator= (const FitsHeader& h)
78{
79  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
80  this->wcs->flag=-1;
81  wcsini(true, h.wcs->naxis, this->wcs);
82  wcscopy(true, h.wcs, this->wcs);
83  wcsset(this->wcs);
84  this->nwcs = h.nwcs;
85  this->wcsIsGood = h.wcsIsGood;
86  this->spectralUnits = h.spectralUnits;
87  this->fluxUnits = h.fluxUnits;
88  this->intFluxUnits = h.intFluxUnits;
89  this->beamSize = h.beamSize;
90  this->bmajKeyword = h.bmajKeyword;
91  this->bminKeyword = h.bminKeyword;
92  this->blankKeyword = h.blankKeyword;
93  this->bzeroKeyword = h.bzeroKeyword;
94  this->bscaleKeyword = h.bscaleKeyword;
95  this->scale = h.scale;
96  this->offset = h.offset;
97  this->power = h.power;
98}
99
100void FitsHeader::setWCS(struct wcsprm *w)
101{
102  /**
103   *  A function that assigns the wcs parameters, and runs
104   *   wcsset to set it up correctly.
105   *  Performs a check to see if the WCS is good (by looking at
106   *   the lng and lat wcsprm parameters), and sets the wcsIsGood
107   *   flag accordingly.
108   * \param w A WCSLIB wcsprm struct with the correct parameters.
109   */
110  wcscopy(true, w, this->wcs);
111  wcsset(this->wcs);
112  if( (w->lng!=-1) && (w->lat!=-1) ) this->wcsIsGood = true;
113}
114
115struct wcsprm *FitsHeader::getWCS()
116{
117  /**
118   *  A function that returns a properly initilized wcsprm object
119   *  corresponding to the WCS.
120   */
121  struct wcsprm *wNew = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
122  wNew->flag=-1;
123  wcsini(true, this->wcs->naxis, wNew);
124  wcscopy(true, this->wcs, wNew);
125  wcsset(wNew);
126  return wNew;
127}
128
129double FitsHeader::pixToVel(double &x, double &y, double &z)
130{
131  double vel;
132  if(this->wcsIsGood){
133    double *pix   = new double[3];
134    double *world = new double[3];
135    pix[0] = x; pix[1] = y; pix[2] = z;
136    pixToWCSSingle(this->wcs,pix,world);
137    vel = this->specToVel(world[2]);
138    delete [] pix;
139    delete [] world;
140  }
141  else vel = z;
142  return vel;
143}
144
145double* FitsHeader::pixToVel(double &x, double &y, double *zarray, int size)
146{
147  double *newzarray = new double[size];
148  if(this->wcsIsGood){
149    double *pix   = new double[size*3];
150    for(int i=0;i<size;i++){
151      pix[3*i]   = x;
152      pix[3*i+1] = y;
153      pix[3*i+2] = zarray[i];
154    }
155    double *world = new double[size*3];
156    pixToWCSMulti(this->wcs,pix,world,size);
157    delete [] pix;
158    for(int i=0;i<size;i++) newzarray[i] = this->specToVel(world[3*i+2]);
159    delete [] world;
160  }
161  else{
162    for(int i=0;i<size;i++) newzarray[i] = zarray[i];
163  }
164  return newzarray;
165}
166
167double  FitsHeader::specToVel(const double &coord)
168{
169  double vel;
170  if(power==1.0) vel =  coord*this->scale + this->offset;
171  else vel = pow( (coord*this->scale + this->offset), this->power);
172  return vel;
173}
174
175double  FitsHeader::velToSpec(const float &velocity)
176{
177//   return velToCoord(this->wcs,velocity,this->spectralUnits);};
178  return (pow(velocity, 1./this->power) - this->offset) / this->scale;}
179
180string  FitsHeader::getIAUName(double ra, double dec)
181{
182  if(strcmp(this->wcs->lngtyp,"RA")==0)
183    return getIAUNameEQ(ra, dec, this->wcs->equinox);
184  else
185    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 status = wcsunits( this->wcs->cunit[this->wcs->spec],
198                         this->spectralUnits.c_str(),
199                         &sc, &of, &po);
200    if(status > 0){
201      std::stringstream errmsg;
202      errmsg << "WCSUNITS Error, Code = " << status
203             << ": " << wcsunits_errmsg[status];
204      if(status == 10) errmsg << "\nTried to get conversion from '"
205                              << this->wcs->cunit[this->wcs->spec] << "' to '"
206                              << this->spectralUnits.c_str() << "'\n";
207      this->spectralUnits = this->wcs->cunit[this->wcs->spec];
208      if(this->spectralUnits==""){
209        errmsg <<
210          "Spectral units not specified. Setting them to 'SPC' for clarity.\n";
211        this->spectralUnits = "SPC";
212      }
213      duchampError("fixUnits", errmsg.str());
214     
215    }
216  }
217  this->scale = sc;
218  this->offset= of;
219  this->power = po;
220
221  // Work out the integrated flux units, based on the spectral units.
222  // If flux is per beam, trim the /beam from the flux units and multiply
223  //  by the spectral units.
224  // Otherwise, just muliply by the spectral units.
225  if(this->fluxUnits.size()>0){
226    if(this->fluxUnits.substr(this->fluxUnits.size()-5,
227                              this->fluxUnits.size()   ) == "/beam"){
228      this->intFluxUnits = this->fluxUnits.substr(0,this->fluxUnits.size()-5)
229        +" " +this->spectralUnits;
230    }
231    else this->intFluxUnits = this->fluxUnits + " " + this->spectralUnits;
232  }
233
234}
235
236/****************************************************************/
237///////////////////////////////////////////////////
238//// Accessor Functions for Parameter class:
239///////////////////////////////////////////////////
240Param::Param(){
241  /**
242   * Param()
243   *  Default intial values for the parameters.
244   * imageFile has no default value!
245   */
246  // Input files
247  this->imageFile         = "";
248  this->flagSubsection    = false;
249  this->subsection        = "[*,*,*]";
250  this->flagReconExists   = false;
251  this->reconFile         = "";
252  this->flagSmoothExists  = false;
253  this->smoothFile        = "";
254  // Output files
255  this->flagLog           = true;
256  this->logFile           = "duchamp-Logfile.txt";
257  this->outFile           = "duchamp-Results.txt";
258  this->spectraFile       = "duchamp-Spectra.ps";
259  this->flagOutputSmooth  = false;
260  this->flagOutputRecon   = false;
261  this->flagOutputResid   = false;
262  this->flagVOT           = false;
263  this->votFile           = "duchamp-Results.xml";
264  this->flagKarma         = false;
265  this->karmaFile         = "duchamp-Results.ann";
266  this->flagMaps          = true;
267  this->detectionMap      = "duchamp-DetectionMap.ps";
268  this->momentMap         = "duchamp-MomentMap.ps";
269  this->flagXOutput       = true;
270  // Cube related parameters
271  this->flagBlankPix      = true;
272  this->blankPixValue     = -8.00061;
273  this->blankKeyword      = 1;
274  this->bscaleKeyword     = -8.00061;
275  this->bzeroKeyword      = 0.;
276  this->flagUsingBlank    = false;
277  this->flagMW            = false;
278  this->maxMW             = 112;
279  this->minMW             = 75;
280  this->numPixBeam        = 10.;
281  this->flagUsingBeam     = false;
282  // Trim-related         
283  this->flagTrimmed       = false;
284  this->borderLeft        = 0;
285  this->borderRight       = 0;
286  this->borderBottom      = 0;
287  this->borderTop         = 0;
288  // Subsection offsets
289  this->sizeOffsets       = 0;
290  this->xSubOffset        = 0;
291  this->ySubOffset        = 0;
292  this->zSubOffset        = 0;
293  // Baseline related
294  this->flagBaseline      = false;
295  // Detection-related   
296  this->flagNegative      = false;
297  // Object growth       
298  this->flagGrowth        = false;
299  this->growthCut         = 2.;
300  // FDR analysis         
301  this->flagFDR           = false;
302  this->alphaFDR          = 0.01;
303  // Other detection     
304  this->snrCut            = 3.;
305  this->threshold         = 0.;
306  this->flagUserThreshold = false;
307  // Hanning Smoothing
308  this->flagSmooth        = false;
309  this->hanningWidth      = 5;
310  // A trous reconstruction parameters
311  this->flagATrous        = true;
312  this->reconDim          = 3;
313  this->scaleMin          = 1;
314  this->snrRecon          = 4.;
315  this->filterCode        = 1;
316  // Volume-merging parameters
317  this->flagAdjacent      = true;
318  this->threshSpatial     = 3.;
319  this->threshVelocity    = 7.;
320  this->minChannels       = 3;
321  this->minPix            = 2;
322  // Input-Output related
323  this->spectralMethod    = "peak";
324  this->borders           = true;
325  this->blankEdge         = true;
326  this->verbose           = true;
327  this->spectralUnits     = "km/s";
328};
329
330Param::Param (const Param& p)
331{
332  this->imageFile         = p.imageFile;
333  this->flagSubsection    = p.flagSubsection;
334  this->subsection        = p.subsection;     
335  this->flagReconExists   = p.flagReconExists;
336  this->reconFile         = p.reconFile;     
337  this->flagSmoothExists  = p.flagSmoothExists;
338  this->smoothFile        = p.smoothFile;     
339  this->flagLog           = p.flagLog;       
340  this->logFile           = p.logFile;       
341  this->outFile           = p.outFile;       
342  this->spectraFile       = p.spectraFile;   
343  this->flagOutputSmooth  = p.flagOutputSmooth;
344  this->flagOutputRecon   = p.flagOutputRecon;
345  this->flagOutputResid   = p.flagOutputResid;
346  this->flagVOT           = p.flagVOT;         
347  this->votFile           = p.votFile;       
348  this->flagKarma         = p.flagKarma;     
349  this->karmaFile         = p.karmaFile;     
350  this->flagMaps          = p.flagMaps;       
351  this->detectionMap      = p.detectionMap;   
352  this->momentMap         = p.momentMap;     
353  this->flagXOutput       = p.flagXOutput;       
354  this->flagBlankPix      = p.flagBlankPix;   
355  this->blankPixValue     = p.blankPixValue; 
356  this->blankKeyword      = p.blankKeyword;   
357  this->bscaleKeyword     = p.bscaleKeyword; 
358  this->bzeroKeyword      = p.bzeroKeyword;   
359  this->flagUsingBlank    = p.flagUsingBlank;
360  this->flagMW            = p.flagMW;         
361  this->maxMW             = p.maxMW;         
362  this->minMW             = p.minMW;         
363  this->numPixBeam        = p.numPixBeam;     
364  this->flagTrimmed       = p.flagTrimmed;   
365  this->borderLeft        = p.borderLeft;     
366  this->borderRight       = p.borderRight;   
367  this->borderBottom      = p.borderBottom;   
368  this->borderTop         = p.borderTop;     
369  this->sizeOffsets       = p.sizeOffsets;
370  this->offsets           = new long[this->sizeOffsets];
371  if(this->sizeOffsets>0)
372    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
373  this->xSubOffset        = p.xSubOffset;     
374  this->ySubOffset        = p.ySubOffset;     
375  this->zSubOffset        = p.zSubOffset;
376  this->flagBaseline      = p.flagBaseline;
377  this->flagNegative      = p.flagNegative;
378  this->flagGrowth        = p.flagGrowth;
379  this->growthCut         = p.growthCut;
380  this->flagFDR           = p.flagFDR;
381  this->alphaFDR          = p.alphaFDR;
382  this->snrCut            = p.snrCut;
383  this->threshold         = p.threshold;
384  this->flagUserThreshold = p.flagUserThreshold;
385  this->flagSmooth        = p.flagSmooth;
386  this->hanningWidth      = p.hanningWidth;
387  this->flagATrous        = p.flagATrous;
388  this->reconDim          = p.reconDim;
389  this->scaleMin          = p.scaleMin;
390  this->snrRecon          = p.snrRecon;
391  this->filterCode        = p.filterCode;
392  this->flagAdjacent      = p.flagAdjacent;
393  this->threshSpatial     = p.threshSpatial;
394  this->threshVelocity    = p.threshVelocity;
395  this->minChannels       = p.minChannels;
396  this->minPix            = p.minPix;
397  this->spectralMethod    = p.spectralMethod;
398  this->borders           = p.borders;
399  this->verbose           = p.verbose;
400  this->spectralUnits     = p.spectralUnits;
401}
402
403Param& Param::operator= (const Param& p)
404{
405  this->imageFile         = p.imageFile;
406  this->flagSubsection    = p.flagSubsection;
407  this->subsection        = p.subsection;     
408  this->flagReconExists   = p.flagReconExists;
409  this->reconFile         = p.reconFile;     
410  this->flagSmoothExists  = p.flagSmoothExists;
411  this->smoothFile        = p.smoothFile;     
412  this->flagLog           = p.flagLog;       
413  this->logFile           = p.logFile;       
414  this->outFile           = p.outFile;       
415  this->spectraFile       = p.spectraFile;   
416  this->flagOutputSmooth  = p.flagOutputSmooth;
417  this->flagOutputRecon   = p.flagOutputRecon;
418  this->flagOutputResid   = p.flagOutputResid;
419  this->flagVOT           = p.flagVOT;         
420  this->votFile           = p.votFile;       
421  this->flagKarma         = p.flagKarma;     
422  this->karmaFile         = p.karmaFile;     
423  this->flagMaps          = p.flagMaps;       
424  this->detectionMap      = p.detectionMap;   
425  this->momentMap         = p.momentMap;     
426  this->flagXOutput       = p.flagXOutput;       
427  this->flagBlankPix      = p.flagBlankPix;   
428  this->blankPixValue     = p.blankPixValue; 
429  this->blankKeyword      = p.blankKeyword;   
430  this->bscaleKeyword     = p.bscaleKeyword; 
431  this->bzeroKeyword      = p.bzeroKeyword;   
432  this->flagUsingBlank    = p.flagUsingBlank;
433  this->flagMW            = p.flagMW;         
434  this->maxMW             = p.maxMW;         
435  this->minMW             = p.minMW;         
436  this->numPixBeam        = p.numPixBeam;     
437  this->flagTrimmed       = p.flagTrimmed;   
438  this->borderLeft        = p.borderLeft;     
439  this->borderRight       = p.borderRight;   
440  this->borderBottom      = p.borderBottom;   
441  this->borderTop         = p.borderTop;     
442  this->sizeOffsets       = p.sizeOffsets;
443  this->offsets           = new long[this->sizeOffsets];
444  if(this->sizeOffsets>0)
445    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
446  this->xSubOffset        = p.xSubOffset;     
447  this->ySubOffset        = p.ySubOffset;     
448  this->zSubOffset        = p.zSubOffset;
449  this->flagBaseline      = p.flagBaseline;
450  this->flagNegative      = p.flagNegative;
451  this->flagGrowth        = p.flagGrowth;
452  this->growthCut         = p.growthCut;
453  this->flagFDR           = p.flagFDR;
454  this->alphaFDR          = p.alphaFDR;
455  this->snrCut            = p.snrCut;
456  this->threshold         = p.threshold;
457  this->flagUserThreshold = p.flagUserThreshold;
458  this->flagSmooth        = p.flagSmooth;
459  this->hanningWidth      = p.hanningWidth;
460  this->flagATrous        = p.flagATrous;
461  this->reconDim          = p.reconDim;
462  this->scaleMin          = p.scaleMin;
463  this->snrRecon          = p.snrRecon;
464  this->filterCode        = p.filterCode;
465  this->flagAdjacent      = p.flagAdjacent;
466  this->threshSpatial     = p.threshSpatial;
467  this->threshVelocity    = p.threshVelocity;
468  this->minChannels       = p.minChannels;
469  this->minPix            = p.minPix;
470  this->spectralMethod    = p.spectralMethod;
471  this->borders           = p.borders;
472  this->verbose           = p.verbose;
473  this->spectralUnits     = p.spectralUnits;
474}
475
476/****************************************************************/
477///////////////////////////////////////////////////
478//// Other Functions using the  Parameter class:
479///////////////////////////////////////////////////
480
481inline string makelower( string s )
482{
483  // "borrowed" from Matt Howlett's 'fred'
484  string out = "";
485  for( int i=0; i<s.size(); ++i ) {
486    out += tolower(s[i]);
487  }
488  return out;
489}
490
491inline bool boolify( string s )
492{
493  /**
494   * bool boolify(string)
495   *  Convert a string to a bool variable
496   *  "1" and "true" get converted to true
497   *  "0" and "false" (and anything else) get converted to false
498   */
499  if((s=="1") || (makelower(s)=="true")) return true;
500  else if((s=="0") || (makelower(s)=="false")) return false;
501  else return false;
502}
503
504inline string readSval(std::stringstream& ss)
505{
506  string val; ss >> val; return val;
507}
508
509inline bool readFlag(std::stringstream& ss)
510{
511  string val; ss >> val; return boolify(val);
512}
513
514inline float readFval(std::stringstream& ss)
515{
516  float val; ss >> val; return val;
517}
518
519inline int readIval(std::stringstream& ss)
520{
521  int val; ss >> val; return val;
522}
523
524int Param::readParams(string paramfile)
525{
526  /**
527   * The parameters are read in from a disk file, on the assumption that each
528   *  line of the file has the format "parameter value" (eg. alphafdr 0.1)
529   *
530   * The case of the parameter name does not matter, nor does the
531   * formatting of the spaces (it can be any amount of whitespace or
532   * tabs).
533   *
534   * \param paramfile A std::string containing the parameter filename.
535   */
536  std::ifstream fin(paramfile.c_str());
537  if(!fin.is_open()) return FAILURE;
538  string line;
539  while( !std::getline(fin,line,'\n').eof()){
540
541    if(line[0]!='#'){
542      std::stringstream ss;
543      ss.str(line);
544      string arg;
545      ss >> arg;
546      arg = makelower(arg);
547      if(arg=="imagefile")       this->imageFile = readSval(ss);
548      if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
549      if(arg=="subsection")      this->subsection = readSval(ss);
550      if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
551      if(arg=="reconfile")       this->reconFile = readSval(ss);
552      if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
553      if(arg=="smoothfile")      this->smoothFile = readSval(ss);
554
555      if(arg=="flaglog")         this->flagLog = readFlag(ss);
556      if(arg=="logfile")         this->logFile = readSval(ss);
557      if(arg=="outfile")         this->outFile = readSval(ss);
558      if(arg=="spectrafile")     this->spectraFile = readSval(ss);
559      if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
560      if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
561      if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
562      if(arg=="flagvot")         this->flagVOT = readFlag(ss);
563      if(arg=="votfile")         this->votFile = readSval(ss);
564      if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
565      if(arg=="karmafile")       this->karmaFile = readSval(ss);
566      if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
567      if(arg=="detectionmap")    this->detectionMap = readSval(ss);
568      if(arg=="momentmap")       this->momentMap = readSval(ss);
569      if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
570
571      if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
572      if(arg=="flagblankpix")    this->flagBlankPix = readFlag(ss);
573      if(arg=="blankpixvalue")   this->blankPixValue = readFval(ss);
574      if(arg=="flagmw")          this->flagMW = readFlag(ss);
575      if(arg=="maxmw")           this->maxMW = readIval(ss);
576      if(arg=="minmw")           this->minMW = readIval(ss);
577      if(arg=="beamsize")        this->numPixBeam = readFval(ss);
578
579      if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
580      if(arg=="minpix")          this->minPix = readIval(ss);
581      if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
582      if(arg=="growthcut")       this->growthCut = readFval(ss);
583
584      if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
585      if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
586
587      if(arg=="snrcut")          this->snrCut = readFval(ss);
588      if(arg=="threshold"){
589                                 this->threshold = readFval(ss);
590                                 this->flagUserThreshold = true;
591      }
592     
593      if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
594      if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
595
596      if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
597      if(arg=="recondim")        this->reconDim = readIval(ss);
598      if(arg=="scalemin")        this->scaleMin = readIval(ss);
599      if(arg=="snrrecon")        this->snrRecon = readFval(ss);
600      if(arg=="filtercode")      this->filterCode = readIval(ss);
601
602      if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
603      if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
604      if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
605      if(arg=="minchannels")     this->minChannels = readIval(ss);
606
607      if(arg=="spectralmethod")  this->spectralMethod=makelower(readSval(ss));
608      if(arg=="spectralunits")   this->spectralUnits=makelower(readSval(ss));
609      if(arg=="drawborders")     this->borders = readFlag(ss);
610      if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
611      if(arg=="verbose")         this->verbose = readFlag(ss);
612    }
613  }
614  if(this->flagATrous) this->flagSmooth = false;
615  return SUCCESS;
616}
617
618
619std::ostream& operator<< ( std::ostream& theStream, Param& par)
620{
621  /**
622   * Print out the parameter set in a formatted, easy to read style.
623   * Lists the parameters, a description of them, and their value.
624   */
625
626  // Only show the [blankPixValue] bit if we are using the parameter
627  // otherwise we have read it from the FITS header.
628  string blankParam = "";
629  if(par.getFlagUsingBlank()) blankParam = "[blankPixValue]";
630  string beamParam = "";
631  if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
632
633  // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
634  //   theStream.setf(std::ios::boolalpha);
635  theStream.setf(std::ios::left);
636  theStream  <<"\n---- Parameters ----"<<endl;
637  theStream  << std::setfill('.');
638  const int widthText = 38;
639  const int widthPar  = 18;
640  if(par.getFlagSubsection())
641    theStream<<setw(widthText)<<"Image to be analysed"                 
642             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
643             <<"  =  " <<resetiosflags(std::ios::right)
644             <<(par.getImageFile()+par.getSubsection()) <<endl;
645  else
646    theStream<<setw(widthText)<<"Image to be analysed"                 
647             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
648             <<"  =  " <<resetiosflags(std::ios::right)
649             <<par.getImageFile()      <<endl;
650  if(par.getFlagReconExists() && par.getFlagATrous()){
651    theStream<<setw(widthText)<<"Reconstructed array exists?"         
652             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
653             <<"  =  " <<resetiosflags(std::ios::right)
654             <<stringize(par.getFlagReconExists())<<endl;
655    theStream<<setw(widthText)<<"FITS file containing reconstruction" 
656             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
657             <<"  =  " <<resetiosflags(std::ios::right)
658             <<par.getReconFile()      <<endl;
659  }
660  if(par.getFlagSmoothExists() && par.getFlagSmooth()){
661    theStream<<setw(widthText)<<"Hanning-smoothed array exists?"         
662             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
663             <<"  =  " <<resetiosflags(std::ios::right)
664             <<stringize(par.getFlagSmoothExists())<<endl;
665    theStream<<setw(widthText)<<"FITS file containing smoothed array" 
666             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
667             <<"  =  " <<resetiosflags(std::ios::right)
668             <<par.getSmoothFile()      <<endl;
669  }
670  theStream  <<setw(widthText)<<"Intermediate Logfile"
671             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
672             <<"  =  " <<resetiosflags(std::ios::right)
673             <<par.getLogFile()        <<endl;
674  theStream  <<setw(widthText)<<"Final Results file"                   
675             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
676             <<"  =  " <<resetiosflags(std::ios::right)
677             <<par.getOutFile()        <<endl;
678  theStream  <<setw(widthText)<<"Spectrum file"                       
679             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
680             <<"  =  " <<resetiosflags(std::ios::right)
681             <<par.getSpectraFile()    <<endl;
682  if(par.getFlagVOT()){
683    theStream<<setw(widthText)<<"VOTable file"                         
684             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
685             <<"  =  " <<resetiosflags(std::ios::right)
686             <<par.getVOTFile()        <<endl;
687  }
688  if(par.getFlagKarma()){
689    theStream<<setw(widthText)<<"Karma annotation file"               
690             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
691             <<"  =  " <<resetiosflags(std::ios::right)
692             
693             <<par.getKarmaFile()      <<endl;
694  }
695  if(par.getFlagMaps()){
696    theStream<<setw(widthText)<<"0th Moment Map"                       
697             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
698             <<"  =  " <<resetiosflags(std::ios::right)
699             <<par.getMomentMap()      <<endl;
700    theStream<<setw(widthText)<<"Detection Map"                       
701             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
702             <<"  =  " <<resetiosflags(std::ios::right)
703             <<par.getDetectionMap()   <<endl;
704  }
705  theStream  <<setw(widthText)<<"Display a map in a pgplot xwindow?"
706             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
707             <<"  =  " <<resetiosflags(std::ios::right)
708             <<stringize(par.getFlagXOutput())     <<endl;
709  if(par.getFlagATrous()){                             
710    theStream<<setw(widthText)<<"Saving reconstructed cube?"           
711             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputrecon]"
712             <<"  =  " <<resetiosflags(std::ios::right)
713             <<stringize(par.getFlagOutputRecon())<<endl;
714    theStream<<setw(widthText)<<"Saving residuals from reconstruction?"
715             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputresid]"
716             <<"  =  " <<resetiosflags(std::ios::right)
717             <<stringize(par.getFlagOutputResid())<<endl;
718  }                                                   
719  if(par.getFlagSmooth()){                             
720    theStream<<setw(widthText)<<"Saving Hanning-smoothed cube?"           
721             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputsmooth]"
722             <<"  =  " <<resetiosflags(std::ios::right)
723             <<stringize(par.getFlagOutputSmooth())<<endl;
724  }                                                   
725  theStream  <<"------"<<endl;
726  theStream  <<setw(widthText)<<"Searching for Negative features?"     
727             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
728             <<"  =  " <<resetiosflags(std::ios::right)
729             <<stringize(par.getFlagNegative())   <<endl;
730  theStream  <<setw(widthText)<<"Fixing Blank Pixels?"                 
731             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBlankPix]"
732             <<"  =  " <<resetiosflags(std::ios::right)
733             <<stringize(par.getFlagBlankPix())   <<endl;
734  if(par.getFlagBlankPix()){
735    theStream<<setw(widthText)<<"Blank Pixel Value"                   
736             <<setw(widthPar)<<setiosflags(std::ios::right)<< blankParam
737             <<"  =  " <<resetiosflags(std::ios::right)
738             <<par.getBlankPixVal()    <<endl;
739  }
740  theStream  <<setw(widthText)<<"Removing Milky Way channels?"         
741             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
742             <<"  =  " <<resetiosflags(std::ios::right)
743             <<stringize(par.getFlagMW())         <<endl;
744  if(par.getFlagMW()){
745    theStream<<setw(widthText)<<"Milky Way Channels"                   
746             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
747             <<"  =  " <<resetiosflags(std::ios::right)
748             <<par.getMinMW()
749             <<"-" <<par.getMaxMW()          <<endl;
750  }
751  theStream  <<setw(widthText)<<"Beam Size (pixels)"                   
752             <<setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
753             <<"  =  " <<resetiosflags(std::ios::right)
754             <<par.getBeamSize()       <<endl;
755  theStream  <<setw(widthText)<<"Removing baselines before search?"   
756             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
757             <<"  =  " <<resetiosflags(std::ios::right)
758             <<stringize(par.getFlagBaseline())   <<endl;
759  theStream  <<setw(widthText)<<"Minimum # Pixels in a detection"     
760             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
761             <<"  =  " <<resetiosflags(std::ios::right)
762             <<par.getMinPix()         <<endl;
763  theStream  <<setw(widthText)<<"Minimum # Channels in a detection"   
764             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
765             <<"  =  " <<resetiosflags(std::ios::right)
766             <<par.getMinChannels()    <<endl;
767  theStream  <<setw(widthText)<<"Growing objects after detection?"     
768             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
769             <<"  =  " <<resetiosflags(std::ios::right)
770             <<stringize(par.getFlagGrowth())     <<endl;
771  if(par.getFlagGrowth()) {                           
772    theStream<<setw(widthText)<<"SNR Threshold for growth"             
773             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
774             <<"  =  " <<resetiosflags(std::ios::right)
775             <<par.getGrowthCut()      <<endl;
776  }
777  theStream  <<setw(widthText)<<"Hanning-smoothing each spectrum first?"       
778             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
779             <<"  =  " <<resetiosflags(std::ios::right)
780             <<stringize(par.getFlagSmooth())     <<endl;
781  if(par.getFlagSmooth())                             
782    theStream<<setw(widthText)<<"Width of hanning filter"     
783             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
784             <<"  =  " <<resetiosflags(std::ios::right)
785             <<par.getHanningWidth()       <<endl;
786  theStream  <<setw(widthText)<<"Using A Trous reconstruction?"       
787             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
788             <<"  =  " <<resetiosflags(std::ios::right)
789             <<stringize(par.getFlagATrous())     <<endl;
790  if(par.getFlagATrous()){                             
791    theStream<<setw(widthText)<<"Number of dimensions in reconstruction"     
792             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
793             <<"  =  " <<resetiosflags(std::ios::right)
794             <<par.getReconDim()       <<endl;
795    theStream<<setw(widthText)<<"Minimum scale in reconstruction"     
796             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
797             <<"  =  " <<resetiosflags(std::ios::right)
798             <<par.getMinScale()       <<endl;
799    theStream<<setw(widthText)<<"SNR Threshold within reconstruction" 
800             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
801             <<"  =  " <<resetiosflags(std::ios::right)
802             <<par.getAtrousCut()      <<endl;
803    theStream<<setw(widthText)<<"Filter being used for reconstruction"
804             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
805             <<"  =  " <<resetiosflags(std::ios::right)
806             <<par.getFilterCode()
807             << " (" << par.getFilterName()  << ")" <<endl;
808  }                                                   
809  theStream  <<setw(widthText)<<"Using FDR analysis?"                 
810             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
811             <<"  =  " <<resetiosflags(std::ios::right)
812             <<stringize(par.getFlagFDR())        <<endl;
813  if(par.getFlagFDR()){                               
814    theStream<<setw(widthText)<<"Alpha value for FDR analysis"         
815             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
816             <<"  =  " <<resetiosflags(std::ios::right)
817             <<par.getAlpha()          <<endl;
818  }                                                   
819  else {
820    if(par.getFlagUserThreshold()){
821      theStream<<setw(widthText)<<"Detection Threshold"                       
822               <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
823               <<"  =  " <<resetiosflags(std::ios::right)
824               <<par.getThreshold()            <<endl;
825    }
826    else{
827      theStream<<setw(widthText)<<"SNR Threshold (in sigma)"
828               <<setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
829               <<"  =  " <<resetiosflags(std::ios::right)
830               <<par.getCut()            <<endl;
831    }
832  }
833  theStream  <<setw(widthText)<<"Using Adjacent-pixel criterion?"     
834             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
835             <<"  =  " <<resetiosflags(std::ios::right)
836             <<stringize(par.getFlagAdjacent())   <<endl;
837  if(!par.getFlagAdjacent()){
838    theStream<<setw(widthText)<<"Max. spatial separation for merging" 
839             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
840             <<"  =  " <<resetiosflags(std::ios::right)
841             <<par.getThreshS()        <<endl;
842  }
843  theStream  <<setw(widthText)<<"Max. velocity separation for merging"
844             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
845             <<"  =  " <<resetiosflags(std::ios::right)
846             <<par.getThreshV()        <<endl;
847  theStream  <<setw(widthText)<<"Method of spectral plotting"         
848             <<setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
849             <<"  =  " <<resetiosflags(std::ios::right)
850             <<par.getSpectralMethod() <<endl;
851  theStream  <<"--------------------\n\n";
852  theStream  << std::setfill(' ');
853  theStream.unsetf(std::ios::left);
854  //  theStream.unsetf(std::ios::boolalpha);
855}
856
857
858void Param::copyHeaderInfo(FitsHeader &head)
859{
860  /**
861   * A function to copy across relevant header keywords from the
862   *  FitsHeader class to the Param class, as they are needed by
863   *  functions in the Param class.
864   * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
865   */
866
867  this->blankKeyword  = head.getBlankKeyword();
868  this->bscaleKeyword = head.getBscaleKeyword();
869  this->bzeroKeyword  = head.getBzeroKeyword();
870  this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
871    this->bzeroKeyword;
872
873  this->numPixBeam    = head.getBeamSize();
874}
875
876string Param::outputSmoothFile()
877{
878  /**
879   * This function produces the required filename in which to save
880   *  the Hanning-smoothed array. If the input image is image.fits, then
881   *  the output will be eg. image.SMOOTH-3.fits, where the width of the
882   *  Hanning filter was 3 pixels.
883   */
884  string inputName = this->imageFile;
885  std::stringstream ss;
886  ss << inputName.substr(0,inputName.size()-5); 
887                          // remove the ".fits" on the end.
888  if(this->flagSubsection) ss<<".sub";
889  ss << ".SMOOTH-" << this->hanningWidth
890     << ".fits";
891  return ss.str();
892}
893
894string Param::outputReconFile()
895{
896  /**
897   * This function produces the required filename in which to save
898   *  the reconstructed array. If the input image is image.fits, then
899   *  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
900   *  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
901   */
902  string inputName = this->imageFile;
903  std::stringstream ss;
904  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
905  if(this->flagSubsection) ss<<".sub";
906  ss << ".RECON-" << this->reconDim
907     << "-"       << this->filterCode
908     << "-"       << this->snrRecon
909     << "-"       << this->scaleMin
910     << ".fits";
911  return ss.str();
912}
913
914string Param::outputResidFile()
915{
916  /**
917   * This function produces the required filename in which to save
918   *  the reconstructed array. If the input image is image.fits, then
919   *  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
920   *  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
921   */
922  string inputName = this->imageFile;
923  std::stringstream ss;
924  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
925  if(this->flagSubsection) ss<<".sub";
926  ss << ".RESID-" << this->reconDim
927     << "-"       << this->filterCode
928     << "-"       << this->snrRecon
929     << "-"       << this->scaleMin
930     << ".fits";
931  return ss.str();
932}
Note: See TracBrowser for help on using the repository browser.