source: branches/pixel-map-branch/src/param.cc @ 236

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

Large raft of changes. Most are minor ones related to fixing up the use of std::string and std::vector (whether they are declared as using, or not...). Other changes include:

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