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

Last change on this file since 1339 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
RevLine 
[3]1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
[205]6#include <stdlib.h>
[3]7#include <math.h>
[103]8#include <wcs.h>
9#include <wcsunits.h>
[3]10#include <param.hh>
[134]11#include <config.h>
[142]12#include <duchamp.hh>
[232]13#include <ATrous/filter.hh>
[103]14#include <Utils/utils.hh>
[254]15#include <Utils/Section.hh>
[3]16
[194]17// Define funtion to print bools as words, in case the compiler doesn't
18//  recognise the setf(ios::boolalpha) command...
[110]19#ifdef HAVE_STDBOOL_H
[232]20std::string stringize(bool b){
[110]21  std::stringstream ss;
22  ss.setf(std::ios::boolalpha);
23  ss << b;
24  return ss.str();
25}
26#else
[232]27std::string stringize(bool b){
[110]28  std::string output;
29  if(b) output="true";
30  else output="false";
31  return output;
32}
33#endif
34
[3]35/****************************************************************/
36///////////////////////////////////////////////////
[103]37//// Functions for FitsHeader class:
38///////////////////////////////////////////////////
39
[204]40FitsHeader::FitsHeader()
41{
[205]42  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]43  this->wcs->flag=-1;
[204]44  wcsini(true, 3, this->wcs);
[103]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
[204]53FitsHeader::FitsHeader(const FitsHeader& h)
54{
[205]55  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]56  this->wcs->flag=-1;
[204]57  wcsini(true, h.wcs->naxis, this->wcs);
58  wcscopy(true, h.wcs, this->wcs);
[103]59  wcsset(this->wcs);
[137]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;
[103]74}
75
[204]76FitsHeader& FitsHeader::operator= (const FitsHeader& h)
77{
[205]78  this->wcs = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]79  this->wcs->flag=-1;
[204]80  wcsini(true, h.wcs->naxis, this->wcs);
81  wcscopy(true, h.wcs, this->wcs);
[103]82  wcsset(this->wcs);
[137]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;
[103]97}
98
[204]99void FitsHeader::setWCS(struct wcsprm *w)
[103]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.
[221]107   * \param w A WCSLIB wcsprm struct with the correct parameters.
[103]108   */
[204]109  wcscopy(true, w, this->wcs);
[103]110  wcsset(this->wcs);
111  if( (w->lng!=-1) && (w->lat!=-1) ) this->wcsIsGood = true;
112}
113
[204]114struct wcsprm *FitsHeader::getWCS()
[103]115{
116  /**
[221]117   *  A function that returns a properly initilized wcsprm object
118   *  corresponding to the WCS.
[103]119   */
[205]120  struct wcsprm *wNew = (struct wcsprm *)calloc(1,sizeof(struct wcsprm));
[103]121  wNew->flag=-1;
[204]122  wcsini(true, this->wcs->naxis, wNew);
123  wcscopy(true, this->wcs, wNew);
[103]124  wcsset(wNew);
125  return wNew;
126}
127
[222]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
[204]142double FitsHeader::pixToVel(double &x, double &y, double &z)
[103]143{
[186]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;
[103]155  return vel;
156}
157
158double* FitsHeader::pixToVel(double &x, double &y, double *zarray, int size)
159{
[186]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++){
[187]164      pix[3*i]   = x;
165      pix[3*i+1] = y;
166      pix[3*i+2] = zarray[i];
[186]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;
[103]173  }
[186]174  else{
175    for(int i=0;i<size;i++) newzarray[i] = zarray[i];
176  }
[103]177  return newzarray;
178}
179
180double  FitsHeader::specToVel(const double &coord)
181{
182  double vel;
[139]183  if(power==1.0) vel =  coord*this->scale + this->offset;
[103]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
[232]193std::string  FitsHeader::getIAUName(double ra, double dec)
[103]194{
[201]195  if(strcmp(this->wcs->lngtyp,"RA")==0)
196    return getIAUNameEQ(ra, dec, this->wcs->equinox);
197  else
198    return getIAUNameGAL(ra, dec);
[103]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.;
[224]208  double po=1.;
[103]209  if(this->wcsIsGood){
[205]210    int status = wcsunits( this->wcs->cunit[this->wcs->spec],
[223]211                           this->spectralUnits.c_str(),
212                           &sc, &of, &po);
[205]213    if(status > 0){
[120]214      std::stringstream errmsg;
[205]215      errmsg << "WCSUNITS Error, Code = " << status
216             << ": " << wcsunits_errmsg[status];
[224]217      if(status == 10) errmsg << "\nTried to get conversion from \""
218                              << this->wcs->cunit[this->wcs->spec] << "\" to \""
219                              << this->spectralUnits.c_str() << "\".\n";
[204]220      this->spectralUnits = this->wcs->cunit[this->wcs->spec];
[103]221      if(this->spectralUnits==""){
[224]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";
[219]227        this->spectralUnits = "SPC";
[103]228      }
[120]229      duchampError("fixUnits", errmsg.str());
230     
[103]231    }
232  }
233  this->scale = sc;
234  this->offset= of;
235  this->power = po;
236
[142]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.
[103]241  if(this->fluxUnits.size()>0){
[142]242    if(this->fluxUnits.substr(this->fluxUnits.size()-5,
243                              this->fluxUnits.size()   ) == "/beam"){
[103]244      this->intFluxUnits = this->fluxUnits.substr(0,this->fluxUnits.size()-5)
245        +" " +this->spectralUnits;
246    }
[159]247    else this->intFluxUnits = this->fluxUnits + " " + this->spectralUnits;
[103]248  }
249
250}
251
252/****************************************************************/
253///////////////////////////////////////////////////
[3]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   */
[254]262  std::string baseSection = "[*,*,*]";
[3]263  // Input files
[190]264  this->imageFile         = "";
265  this->flagSubsection    = false;
[254]266  this->pixelSec.setSection(baseSection);
[190]267  this->flagReconExists   = false;
268  this->reconFile         = "";
[208]269  this->flagSmoothExists  = false;
270  this->smoothFile        = "";
[3]271  // Output files
[190]272  this->flagLog           = true;
273  this->logFile           = "duchamp-Logfile.txt";
274  this->outFile           = "duchamp-Results.txt";
275  this->spectraFile       = "duchamp-Spectra.ps";
[208]276  this->flagOutputSmooth  = false;
[190]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";
[195]286  this->flagXOutput       = true;
[3]287  // Cube related parameters
[190]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;
[3]299  // Trim-related         
[190]300  this->flagTrimmed       = false;
301  this->borderLeft        = 0;
302  this->borderRight       = 0;
303  this->borderBottom      = 0;
304  this->borderTop         = 0;
[3]305  // Subsection offsets
[204]306  this->sizeOffsets       = 0;
[190]307  this->xSubOffset        = 0;
308  this->ySubOffset        = 0;
309  this->zSubOffset        = 0;
[3]310  // Baseline related
[190]311  this->flagBaseline      = false;
[3]312  // Detection-related   
[190]313  this->flagNegative      = false;
[3]314  // Object growth       
[190]315  this->flagGrowth        = false;
316  this->growthCut         = 2.;
[3]317  // FDR analysis         
[190]318  this->flagFDR           = false;
319  this->alphaFDR          = 0.01;
[3]320  // Other detection     
[254]321  this->flagStatSec       = false;
322  this->statSec.setSection(baseSection);
[190]323  this->snrCut            = 3.;
324  this->threshold         = 0.;
325  this->flagUserThreshold = false;
[201]326  // Hanning Smoothing
327  this->flagSmooth        = false;
328  this->hanningWidth      = 5;
[3]329  // A trous reconstruction parameters
[190]330  this->flagATrous        = true;
[255]331  this->reconDim          = 1;
[190]332  this->scaleMin          = 1;
333  this->snrRecon          = 4.;
334  this->filterCode        = 1;
[232]335  this->reconFilter.define(this->filterCode);
[3]336  // Volume-merging parameters
[190]337  this->flagAdjacent      = true;
338  this->threshSpatial     = 3.;
339  this->threshVelocity    = 7.;
340  this->minChannels       = 3;
341  this->minPix            = 2;
[3]342  // Input-Output related
[190]343  this->spectralMethod    = "peak";
344  this->borders           = true;
345  this->blankEdge         = true;
346  this->verbose           = true;
347  this->spectralUnits     = "km/s";
[3]348};
349
[204]350Param::Param (const Param& p)
351{
352  this->imageFile         = p.imageFile;
353  this->flagSubsection    = p.flagSubsection;
[254]354  this->pixelSec          = p.pixelSec;
[204]355  this->flagReconExists   = p.flagReconExists;
356  this->reconFile         = p.reconFile;     
[208]357  this->flagSmoothExists  = p.flagSmoothExists;
358  this->smoothFile        = p.smoothFile;     
[204]359  this->flagLog           = p.flagLog;       
360  this->logFile           = p.logFile;       
361  this->outFile           = p.outFile;       
362  this->spectraFile       = p.spectraFile;   
[208]363  this->flagOutputSmooth  = p.flagOutputSmooth;
[204]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;
[213]390  this->offsets           = new long[this->sizeOffsets];
[204]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;
[254]402  this->flagStatSec       = p.flagStatSec;
403  this->statSec           = p.statSec;
[204]404  this->snrCut            = p.snrCut;
405  this->threshold         = p.threshold;
[205]406  this->flagUserThreshold = p.flagUserThreshold;
[204]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;
[232]414  this->reconFilter       = p.reconFilter;
[204]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
[137]426Param& Param::operator= (const Param& p)
427{
[190]428  this->imageFile         = p.imageFile;
429  this->flagSubsection    = p.flagSubsection;
[254]430  this->pixelSec          = p.pixelSec;
[190]431  this->flagReconExists   = p.flagReconExists;
432  this->reconFile         = p.reconFile;     
[208]433  this->flagSmoothExists  = p.flagSmoothExists;
434  this->smoothFile        = p.smoothFile;     
[190]435  this->flagLog           = p.flagLog;       
436  this->logFile           = p.logFile;       
437  this->outFile           = p.outFile;       
438  this->spectraFile       = p.spectraFile;   
[208]439  this->flagOutputSmooth  = p.flagOutputSmooth;
[190]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;     
[195]449  this->flagXOutput       = p.flagXOutput;       
[190]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;     
[204]465  this->sizeOffsets       = p.sizeOffsets;
[213]466  this->offsets           = new long[this->sizeOffsets];
[204]467  if(this->sizeOffsets>0)
468    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
[190]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;
[254]478  this->flagStatSec       = p.flagStatSec;
479  this->statSec           = p.statSec;
[190]480  this->snrCut            = p.snrCut;
481  this->threshold         = p.threshold;
[205]482  this->flagUserThreshold = p.flagUserThreshold;
[201]483  this->flagSmooth        = p.flagSmooth;
484  this->hanningWidth      = p.hanningWidth;
[190]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;
[232]490  this->reconFilter       = p.reconFilter;
[190]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;
[137]500}
501
[3]502/****************************************************************/
503///////////////////////////////////////////////////
504//// Other Functions using the  Parameter class:
505///////////////////////////////////////////////////
506
[232]507inline std::string makelower( std::string s )
[3]508{
509  // "borrowed" from Matt Howlett's 'fred'
[232]510  std::string out = "";
[3]511  for( int i=0; i<s.size(); ++i ) {
512    out += tolower(s[i]);
513  }
514  return out;
515}
516
[232]517inline bool boolify( std::string s )
[132]518{
519  /**
[133]520   * bool boolify(string)
[232]521   *  Convert a std::string to a bool variable
[132]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
[232]530inline std::string readSval(std::stringstream& ss)
[163]531{
[232]532  std::string val; ss >> val; return val;
[163]533}
534
535inline bool readFlag(std::stringstream& ss)
536{
[232]537  std::string val; ss >> val; return boolify(val);
[163]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
[232]550int Param::readParams(std::string paramfile)
[3]551{
[221]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   */
[3]562  std::ifstream fin(paramfile.c_str());
[160]563  if(!fin.is_open()) return FAILURE;
[232]564  std::string line;
[3]565  while( !std::getline(fin,line,'\n').eof()){
566
567    if(line[0]!='#'){
568      std::stringstream ss;
569      ss.str(line);
[232]570      std::string arg;
[163]571      ss >> arg;
572      arg = makelower(arg);
573      if(arg=="imagefile")       this->imageFile = readSval(ss);
574      if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
[254]575      if(arg=="subsection")      this->pixelSec.setSection(readSval(ss));
[163]576      if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
577      if(arg=="reconfile")       this->reconFile = readSval(ss);
[208]578      if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
579      if(arg=="smoothfile")      this->smoothFile = readSval(ss);
[71]580
[163]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);
[208]585      if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
[163]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);
[195]595      if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
[3]596
[163]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);
[71]604
[163]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);
[71]609
[163]610      if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
611      if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
[103]612
[254]613      if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
614      if(arg=="statsec")         this->statSec.setSection(readSval(ss));
[163]615      if(arg=="snrcut")          this->snrCut = readFval(ss);
[190]616      if(arg=="threshold"){
617                                 this->threshold = readFval(ss);
618                                 this->flagUserThreshold = true;
619      }
[201]620     
621      if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
622      if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
[103]623
[163]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);
[232]628      if(arg=="filtercode"){
629                                 this->filterCode = readIval(ss);
630                                 this->reconFilter.define(this->filterCode);
631      }
[71]632
[163]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);
[71]637
[163]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);
[3]643    }
644  }
[208]645  if(this->flagATrous) this->flagSmooth = false;
[232]646
[160]647  return SUCCESS;
[3]648}
649
650
651std::ostream& operator<< ( std::ostream& theStream, Param& par)
652{
[221]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
[103]658  // Only show the [blankPixValue] bit if we are using the parameter
659  // otherwise we have read it from the FITS header.
[232]660  std::string blankParam = "";
[103]661  if(par.getFlagUsingBlank()) blankParam = "[blankPixValue]";
[232]662  std::string beamParam = "";
[172]663  if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
[103]664
[107]665  // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
[172]666  //   theStream.setf(std::ios::boolalpha);
[3]667  theStream.setf(std::ios::left);
[232]668  theStream  <<"\n---- Parameters ----"<<std::endl;
[103]669  theStream  << std::setfill('.');
[187]670  const int widthText = 38;
671  const int widthPar  = 18;
[3]672  if(par.getFlagSubsection())
[232]673    theStream<<std::setw(widthText)<<"Image to be analysed"                 
674             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
[103]675             <<"  =  " <<resetiosflags(std::ios::right)
[232]676             <<(par.getImageFile()+par.getSubsection()) <<std::endl;
[3]677  else
[232]678    theStream<<std::setw(widthText)<<"Image to be analysed"                 
679             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
[172]680             <<"  =  " <<resetiosflags(std::ios::right)
[232]681             <<par.getImageFile()      <<std::endl;
[81]682  if(par.getFlagReconExists() && par.getFlagATrous()){
[232]683    theStream<<std::setw(widthText)<<"Reconstructed array exists?"         
684             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
[172]685             <<"  =  " <<resetiosflags(std::ios::right)
[232]686             <<stringize(par.getFlagReconExists())<<std::endl;
687    theStream<<std::setw(widthText)<<"FITS file containing reconstruction" 
688             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
[172]689             <<"  =  " <<resetiosflags(std::ios::right)
[232]690             <<par.getReconFile()      <<std::endl;
[71]691  }
[208]692  if(par.getFlagSmoothExists() && par.getFlagSmooth()){
[232]693    theStream<<std::setw(widthText)<<"Hanning-smoothed array exists?"         
694             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
[208]695             <<"  =  " <<resetiosflags(std::ios::right)
[232]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]"
[208]699             <<"  =  " <<resetiosflags(std::ios::right)
[232]700             <<par.getSmoothFile()      <<std::endl;
[208]701  }
[232]702  theStream  <<std::setw(widthText)<<"Intermediate Logfile"
703             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
[172]704             <<"  =  " <<resetiosflags(std::ios::right)
[232]705             <<par.getLogFile()        <<std::endl;
706  theStream  <<std::setw(widthText)<<"Final Results file"                   
707             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
[172]708             <<"  =  " <<resetiosflags(std::ios::right)
[232]709             <<par.getOutFile()        <<std::endl;
710  theStream  <<std::setw(widthText)<<"Spectrum file"                       
711             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
[172]712             <<"  =  " <<resetiosflags(std::ios::right)
[232]713             <<par.getSpectraFile()    <<std::endl;
[3]714  if(par.getFlagVOT()){
[232]715    theStream<<std::setw(widthText)<<"VOTable file"                         
716             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
[172]717             <<"  =  " <<resetiosflags(std::ios::right)
[232]718             <<par.getVOTFile()        <<std::endl;
[3]719  }
[20]720  if(par.getFlagKarma()){
[232]721    theStream<<std::setw(widthText)<<"Karma annotation file"               
722             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
[172]723             <<"  =  " <<resetiosflags(std::ios::right)
724             
[232]725             <<par.getKarmaFile()      <<std::endl;
[20]726  }
[3]727  if(par.getFlagMaps()){
[232]728    theStream<<std::setw(widthText)<<"0th Moment Map"                       
729             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
[172]730             <<"  =  " <<resetiosflags(std::ios::right)
[232]731             <<par.getMomentMap()      <<std::endl;
732    theStream<<std::setw(widthText)<<"Detection Map"                       
733             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
[172]734             <<"  =  " <<resetiosflags(std::ios::right)
[232]735             <<par.getDetectionMap()   <<std::endl;
[3]736  }
[232]737  theStream  <<std::setw(widthText)<<"Display a map in a pgplot xwindow?"
738             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
[195]739             <<"  =  " <<resetiosflags(std::ios::right)
[232]740             <<stringize(par.getFlagXOutput())     <<std::endl;
[3]741  if(par.getFlagATrous()){                             
[232]742    theStream<<std::setw(widthText)<<"Saving reconstructed cube?"           
743             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputrecon]"
[172]744             <<"  =  " <<resetiosflags(std::ios::right)
[232]745             <<stringize(par.getFlagOutputRecon())<<std::endl;
746    theStream<<std::setw(widthText)<<"Saving residuals from reconstruction?"
747             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputresid]"
[172]748             <<"  =  " <<resetiosflags(std::ios::right)
[232]749             <<stringize(par.getFlagOutputResid())<<std::endl;
[3]750  }                                                   
[208]751  if(par.getFlagSmooth()){                             
[232]752    theStream<<std::setw(widthText)<<"Saving Hanning-smoothed cube?"           
753             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputsmooth]"
[208]754             <<"  =  " <<resetiosflags(std::ios::right)
[232]755             <<stringize(par.getFlagOutputSmooth())<<std::endl;
[208]756  }                                                   
[232]757  theStream  <<"------"<<std::endl;
758  theStream  <<std::setw(widthText)<<"Searching for Negative features?"     
759             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
[172]760             <<"  =  " <<resetiosflags(std::ios::right)
[232]761             <<stringize(par.getFlagNegative())   <<std::endl;
762  theStream  <<std::setw(widthText)<<"Fixing Blank Pixels?"                 
763             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBlankPix]"
[172]764             <<"  =  " <<resetiosflags(std::ios::right)
[232]765             <<stringize(par.getFlagBlankPix())   <<std::endl;
[3]766  if(par.getFlagBlankPix()){
[232]767    theStream<<std::setw(widthText)<<"Blank Pixel Value"                   
768             <<std::setw(widthPar)<<setiosflags(std::ios::right)<< blankParam
[172]769             <<"  =  " <<resetiosflags(std::ios::right)
[232]770             <<par.getBlankPixVal()    <<std::endl;
[3]771  }
[232]772  theStream  <<std::setw(widthText)<<"Removing Milky Way channels?"         
773             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
[172]774             <<"  =  " <<resetiosflags(std::ios::right)
[232]775             <<stringize(par.getFlagMW())         <<std::endl;
[3]776  if(par.getFlagMW()){
[232]777    theStream<<std::setw(widthText)<<"Milky Way Channels"                   
778             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
[172]779             <<"  =  " <<resetiosflags(std::ios::right)
780             <<par.getMinMW()
[232]781             <<"-" <<par.getMaxMW()          <<std::endl;
[3]782  }
[232]783  theStream  <<std::setw(widthText)<<"Beam Size (pixels)"                   
784             <<std::setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
[172]785             <<"  =  " <<resetiosflags(std::ios::right)
[232]786             <<par.getBeamSize()       <<std::endl;
787  theStream  <<std::setw(widthText)<<"Removing baselines before search?"   
788             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
[172]789             <<"  =  " <<resetiosflags(std::ios::right)
[232]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]"
[172]793             <<"  =  " <<resetiosflags(std::ios::right)
[232]794             <<par.getMinPix()         <<std::endl;
795  theStream  <<std::setw(widthText)<<"Minimum # Channels in a detection"   
796             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
[172]797             <<"  =  " <<resetiosflags(std::ios::right)
[232]798             <<par.getMinChannels()    <<std::endl;
799  theStream  <<std::setw(widthText)<<"Growing objects after detection?"     
800             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
[172]801             <<"  =  " <<resetiosflags(std::ios::right)
[232]802             <<stringize(par.getFlagGrowth())     <<std::endl;
[3]803  if(par.getFlagGrowth()) {                           
[232]804    theStream<<std::setw(widthText)<<"SNR Threshold for growth"             
805             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
[172]806             <<"  =  " <<resetiosflags(std::ios::right)
[232]807             <<par.getGrowthCut()      <<std::endl;
[3]808  }
[232]809  theStream  <<std::setw(widthText)<<"Hanning-smoothing each spectrum first?"       
810             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
[201]811             <<"  =  " <<resetiosflags(std::ios::right)
[232]812             <<stringize(par.getFlagSmooth())     <<std::endl;
[201]813  if(par.getFlagSmooth())                             
[232]814    theStream<<std::setw(widthText)<<"Width of hanning filter"     
815             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
[201]816             <<"  =  " <<resetiosflags(std::ios::right)
[232]817             <<par.getHanningWidth()       <<std::endl;
818  theStream  <<std::setw(widthText)<<"Using A Trous reconstruction?"       
819             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
[172]820             <<"  =  " <<resetiosflags(std::ios::right)
[232]821             <<stringize(par.getFlagATrous())     <<std::endl;
[3]822  if(par.getFlagATrous()){                             
[232]823    theStream<<std::setw(widthText)<<"Number of dimensions in reconstruction"     
824             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
[172]825             <<"  =  " <<resetiosflags(std::ios::right)
[232]826             <<par.getReconDim()       <<std::endl;
827    theStream<<std::setw(widthText)<<"Minimum scale in reconstruction"     
828             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
[172]829             <<"  =  " <<resetiosflags(std::ios::right)
[232]830             <<par.getMinScale()       <<std::endl;
831    theStream<<std::setw(widthText)<<"SNR Threshold within reconstruction" 
832             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
[172]833             <<"  =  " <<resetiosflags(std::ios::right)
[232]834             <<par.getAtrousCut()      <<std::endl;
835    theStream<<std::setw(widthText)<<"Filter being used for reconstruction"
836             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
[172]837             <<"  =  " <<resetiosflags(std::ios::right)
838             <<par.getFilterCode()
[232]839             << " (" << par.getFilterName()  << ")" <<std::endl;
[3]840  }                                                   
[254]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  }
[232]847  theStream  <<std::setw(widthText)<<"Using FDR analysis?"                 
848             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
[172]849             <<"  =  " <<resetiosflags(std::ios::right)
[232]850             <<stringize(par.getFlagFDR())        <<std::endl;
[3]851  if(par.getFlagFDR()){                               
[232]852    theStream<<std::setw(widthText)<<"Alpha value for FDR analysis"         
853             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
[172]854             <<"  =  " <<resetiosflags(std::ios::right)
[232]855             <<par.getAlpha()          <<std::endl;
[3]856  }                                                   
857  else {
[190]858    if(par.getFlagUserThreshold()){
[232]859      theStream<<std::setw(widthText)<<"Detection Threshold"                       
860               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
[189]861               <<"  =  " <<resetiosflags(std::ios::right)
[232]862               <<par.getThreshold()            <<std::endl;
[189]863    }
864    else{
[232]865      theStream<<std::setw(widthText)<<"SNR Threshold (in sigma)"
866               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
[189]867               <<"  =  " <<resetiosflags(std::ios::right)
[232]868               <<par.getCut()            <<std::endl;
[189]869    }
[3]870  }
[232]871  theStream  <<std::setw(widthText)<<"Using Adjacent-pixel criterion?"     
872             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
[172]873             <<"  =  " <<resetiosflags(std::ios::right)
[232]874             <<stringize(par.getFlagAdjacent())   <<std::endl;
[3]875  if(!par.getFlagAdjacent()){
[232]876    theStream<<std::setw(widthText)<<"Max. spatial separation for merging" 
877             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
[172]878             <<"  =  " <<resetiosflags(std::ios::right)
[232]879             <<par.getThreshS()        <<std::endl;
[3]880  }
[232]881  theStream  <<std::setw(widthText)<<"Max. velocity separation for merging"
882             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
[172]883             <<"  =  " <<resetiosflags(std::ios::right)
[232]884             <<par.getThreshV()        <<std::endl;
885  theStream  <<std::setw(widthText)<<"Method of spectral plotting"         
886             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
[172]887             <<"  =  " <<resetiosflags(std::ios::right)
[232]888             <<par.getSpectralMethod() <<std::endl;
[219]889  theStream  <<"--------------------\n\n";
[103]890  theStream  << std::setfill(' ');
[3]891  theStream.unsetf(std::ios::left);
[110]892  //  theStream.unsetf(std::ios::boolalpha);
[3]893}
894
[120]895
[112]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.
[221]902   * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
[112]903   */
904
905  this->blankKeyword  = head.getBlankKeyword();
906  this->bscaleKeyword = head.getBscaleKeyword();
907  this->bzeroKeyword  = head.getBzeroKeyword();
[159]908  this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
909    this->bzeroKeyword;
[112]910
911  this->numPixBeam    = head.getBeamSize();
912}
913
[232]914std::string Param::outputSmoothFile()
[208]915{
916  /**
[221]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.
[208]921   */
[232]922  std::string inputName = this->imageFile;
[208]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
[232]932std::string Param::outputReconFile()
[103]933{
934  /**
[221]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
[103]939   */
[232]940  std::string inputName = this->imageFile;
[103]941  std::stringstream ss;
942  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
[106]943  if(this->flagSubsection) ss<<".sub";
[103]944  ss << ".RECON-" << this->reconDim
945     << "-"       << this->filterCode
946     << "-"       << this->snrRecon
947     << "-"       << this->scaleMin
948     << ".fits";
949  return ss.str();
950}
951
[232]952std::string Param::outputResidFile()
[103]953{
954  /**
[221]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
[103]959   */
[232]960  std::string inputName = this->imageFile;
[103]961  std::stringstream ss;
962  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
[106]963  if(this->flagSubsection) ss<<".sub";
[103]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.