source: trunk/src/param.cc @ 211

Last change on this file since 211 was 208, checked in by Matthew Whiting, 18 years ago
  • Enabled saving and reading in of a smoothed array, in manner directly analogous to that for the recon array.
    • New file : src/Cubes/readSmooth.cc
    • The other new functions go in existing files eg. saveImage.cc
    • Renamed some functions (like writeHeader...) to be more obvious what they do.
    • The reading in is taken care of by new function Cube::readSavedArrays() -- handles both smoothed and recon'd arrays.
    • Associated parameters in Param class
    • Clarified names of FITS header strings in duchamp.hh.
  • Updated the documentation to describe the ability to smooth a cube.
  • Added description of feedback mechanisms in the Install appendix.
  • Also, Hanning class improved to guard against memory leaks.


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