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

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