source: trunk/src/param.cc @ 265

Last change on this file since 265 was 265, checked in by Matthew Whiting, 17 years ago
  • Enabled output for centroid and peak pixel locations (centroid is proper name for centre-of-mass):
    • New parameter: pixelCentre to determine preferred one for output. Needed similar parameter in the Detection class.
    • Detection::getXCentre() etc now return value based on this parameter. Have new function getXAverage() etc that accesses the average value from the Object3D.
    • Rejigged output functions so there is a difference between screen and file outputs -- screen doesn't have all the different pixel centres, but the file does.
    • Had to change the columns setup in the process.
  • Improved output for merging process.
  • Updated documentation.
File size: 38.5 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
6#include <stdlib.h>
7#include <math.h>
8#include <wcs.h>
9#include <wcsunits.h>
10#include <param.hh>
11#include <config.h>
12#include <duchamp.hh>
13#include <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->spectralUnits     = "km/s";
345  this->pixelCentre       = "centroid";
346  this->borders           = true;
347  this->blankEdge         = true;
348  this->verbose           = true;
349};
350
351Param::Param (const Param& p)
352{
353  this->imageFile         = p.imageFile;
354  this->flagSubsection    = p.flagSubsection;
355  this->pixelSec          = p.pixelSec;
356  this->flagReconExists   = p.flagReconExists;
357  this->reconFile         = p.reconFile;     
358  this->flagSmoothExists  = p.flagSmoothExists;
359  this->smoothFile        = p.smoothFile;     
360  this->flagLog           = p.flagLog;       
361  this->logFile           = p.logFile;       
362  this->outFile           = p.outFile;       
363  this->spectraFile       = p.spectraFile;   
364  this->flagOutputSmooth  = p.flagOutputSmooth;
365  this->flagOutputRecon   = p.flagOutputRecon;
366  this->flagOutputResid   = p.flagOutputResid;
367  this->flagVOT           = p.flagVOT;         
368  this->votFile           = p.votFile;       
369  this->flagKarma         = p.flagKarma;     
370  this->karmaFile         = p.karmaFile;     
371  this->flagMaps          = p.flagMaps;       
372  this->detectionMap      = p.detectionMap;   
373  this->momentMap         = p.momentMap;     
374  this->flagXOutput       = p.flagXOutput;       
375  this->flagBlankPix      = p.flagBlankPix;   
376  this->blankPixValue     = p.blankPixValue; 
377  this->blankKeyword      = p.blankKeyword;   
378  this->bscaleKeyword     = p.bscaleKeyword; 
379  this->bzeroKeyword      = p.bzeroKeyword;   
380  this->flagUsingBlank    = p.flagUsingBlank;
381  this->flagMW            = p.flagMW;         
382  this->maxMW             = p.maxMW;         
383  this->minMW             = p.minMW;         
384  this->numPixBeam        = p.numPixBeam;     
385  this->flagTrimmed       = p.flagTrimmed;   
386  this->borderLeft        = p.borderLeft;     
387  this->borderRight       = p.borderRight;   
388  this->borderBottom      = p.borderBottom;   
389  this->borderTop         = p.borderTop;     
390  this->sizeOffsets       = p.sizeOffsets;
391  this->offsets           = new long[this->sizeOffsets];
392  if(this->sizeOffsets>0)
393    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
394  this->xSubOffset        = p.xSubOffset;     
395  this->ySubOffset        = p.ySubOffset;     
396  this->zSubOffset        = p.zSubOffset;
397  this->flagBaseline      = p.flagBaseline;
398  this->flagNegative      = p.flagNegative;
399  this->flagGrowth        = p.flagGrowth;
400  this->growthCut         = p.growthCut;
401  this->flagFDR           = p.flagFDR;
402  this->alphaFDR          = p.alphaFDR;
403  this->flagStatSec       = p.flagStatSec;
404  this->statSec           = p.statSec;
405  this->snrCut            = p.snrCut;
406  this->threshold         = p.threshold;
407  this->flagUserThreshold = p.flagUserThreshold;
408  this->flagSmooth        = p.flagSmooth;
409  this->hanningWidth      = p.hanningWidth;
410  this->flagATrous        = p.flagATrous;
411  this->reconDim          = p.reconDim;
412  this->scaleMin          = p.scaleMin;
413  this->snrRecon          = p.snrRecon;
414  this->filterCode        = p.filterCode;
415  this->reconFilter       = p.reconFilter;
416  this->flagAdjacent      = p.flagAdjacent;
417  this->threshSpatial     = p.threshSpatial;
418  this->threshVelocity    = p.threshVelocity;
419  this->minChannels       = p.minChannels;
420  this->minPix            = p.minPix;
421  this->spectralMethod    = p.spectralMethod;
422  this->spectralUnits     = p.spectralUnits;
423  this->pixelCentre       = p.pixelCentre;
424  this->borders           = p.borders;
425  this->verbose           = p.verbose;
426}
427
428Param& Param::operator= (const Param& p)
429{
430  this->imageFile         = p.imageFile;
431  this->flagSubsection    = p.flagSubsection;
432  this->pixelSec          = p.pixelSec;
433  this->flagReconExists   = p.flagReconExists;
434  this->reconFile         = p.reconFile;     
435  this->flagSmoothExists  = p.flagSmoothExists;
436  this->smoothFile        = p.smoothFile;     
437  this->flagLog           = p.flagLog;       
438  this->logFile           = p.logFile;       
439  this->outFile           = p.outFile;       
440  this->spectraFile       = p.spectraFile;   
441  this->flagOutputSmooth  = p.flagOutputSmooth;
442  this->flagOutputRecon   = p.flagOutputRecon;
443  this->flagOutputResid   = p.flagOutputResid;
444  this->flagVOT           = p.flagVOT;         
445  this->votFile           = p.votFile;       
446  this->flagKarma         = p.flagKarma;     
447  this->karmaFile         = p.karmaFile;     
448  this->flagMaps          = p.flagMaps;       
449  this->detectionMap      = p.detectionMap;   
450  this->momentMap         = p.momentMap;     
451  this->flagXOutput       = p.flagXOutput;       
452  this->flagBlankPix      = p.flagBlankPix;   
453  this->blankPixValue     = p.blankPixValue; 
454  this->blankKeyword      = p.blankKeyword;   
455  this->bscaleKeyword     = p.bscaleKeyword; 
456  this->bzeroKeyword      = p.bzeroKeyword;   
457  this->flagUsingBlank    = p.flagUsingBlank;
458  this->flagMW            = p.flagMW;         
459  this->maxMW             = p.maxMW;         
460  this->minMW             = p.minMW;         
461  this->numPixBeam        = p.numPixBeam;     
462  this->flagTrimmed       = p.flagTrimmed;   
463  this->borderLeft        = p.borderLeft;     
464  this->borderRight       = p.borderRight;   
465  this->borderBottom      = p.borderBottom;   
466  this->borderTop         = p.borderTop;     
467  this->sizeOffsets       = p.sizeOffsets;
468  this->offsets           = new long[this->sizeOffsets];
469  if(this->sizeOffsets>0)
470    for(int i=0;i<this->sizeOffsets;i++) this->offsets[i] = p.offsets[i];
471  this->xSubOffset        = p.xSubOffset;     
472  this->ySubOffset        = p.ySubOffset;     
473  this->zSubOffset        = p.zSubOffset;
474  this->flagBaseline      = p.flagBaseline;
475  this->flagNegative      = p.flagNegative;
476  this->flagGrowth        = p.flagGrowth;
477  this->growthCut         = p.growthCut;
478  this->flagFDR           = p.flagFDR;
479  this->alphaFDR          = p.alphaFDR;
480  this->flagStatSec       = p.flagStatSec;
481  this->statSec           = p.statSec;
482  this->snrCut            = p.snrCut;
483  this->threshold         = p.threshold;
484  this->flagUserThreshold = p.flagUserThreshold;
485  this->flagSmooth        = p.flagSmooth;
486  this->hanningWidth      = p.hanningWidth;
487  this->flagATrous        = p.flagATrous;
488  this->reconDim          = p.reconDim;
489  this->scaleMin          = p.scaleMin;
490  this->snrRecon          = p.snrRecon;
491  this->filterCode        = p.filterCode;
492  this->reconFilter       = p.reconFilter;
493  this->flagAdjacent      = p.flagAdjacent;
494  this->threshSpatial     = p.threshSpatial;
495  this->threshVelocity    = p.threshVelocity;
496  this->minChannels       = p.minChannels;
497  this->minPix            = p.minPix;
498  this->spectralMethod    = p.spectralMethod;
499  this->spectralUnits     = p.spectralUnits;
500  this->pixelCentre       = p.pixelCentre;
501  this->borders           = p.borders;
502  this->verbose           = p.verbose;
503}
504
505/****************************************************************/
506///////////////////////////////////////////////////
507//// Other Functions using the  Parameter class:
508///////////////////////////////////////////////////
509
510inline std::string makelower( std::string s )
511{
512  // "borrowed" from Matt Howlett's 'fred'
513  std::string out = "";
514  for( int i=0; i<s.size(); ++i ) {
515    out += tolower(s[i]);
516  }
517  return out;
518}
519
520inline bool boolify( std::string s )
521{
522  /**
523   * bool boolify(string)
524   *  Convert a std::string to a bool variable
525   *  "1" and "true" get converted to true
526   *  "0" and "false" (and anything else) get converted to false
527   */
528  if((s=="1") || (makelower(s)=="true")) return true;
529  else if((s=="0") || (makelower(s)=="false")) return false;
530  else return false;
531}
532
533inline std::string readSval(std::stringstream& ss)
534{
535  std::string val; ss >> val; return val;
536}
537
538inline bool readFlag(std::stringstream& ss)
539{
540  std::string val; ss >> val; return boolify(val);
541}
542
543inline float readFval(std::stringstream& ss)
544{
545  float val; ss >> val; return val;
546}
547
548inline int readIval(std::stringstream& ss)
549{
550  int val; ss >> val; return val;
551}
552
553int Param::readParams(std::string paramfile)
554{
555  /**
556   * The parameters are read in from a disk file, on the assumption that each
557   *  line of the file has the format "parameter value" (eg. alphafdr 0.1)
558   *
559   * The case of the parameter name does not matter, nor does the
560   * formatting of the spaces (it can be any amount of whitespace or
561   * tabs).
562   *
563   * \param paramfile A std::string containing the parameter filename.
564   */
565  std::ifstream fin(paramfile.c_str());
566  if(!fin.is_open()) return FAILURE;
567  std::string line;
568  while( !std::getline(fin,line,'\n').eof()){
569
570    if(line[0]!='#'){
571      std::stringstream ss;
572      ss.str(line);
573      std::string arg;
574      ss >> arg;
575      arg = makelower(arg);
576      if(arg=="imagefile")       this->imageFile = readSval(ss);
577      if(arg=="flagsubsection")  this->flagSubsection = readFlag(ss);
578      if(arg=="subsection")      this->pixelSec.setSection(readSval(ss));
579      if(arg=="flagreconexists") this->flagReconExists = readFlag(ss);
580      if(arg=="reconfile")       this->reconFile = readSval(ss);
581      if(arg=="flagsmoothexists")this->flagSmoothExists = readFlag(ss);
582      if(arg=="smoothfile")      this->smoothFile = readSval(ss);
583
584      if(arg=="flaglog")         this->flagLog = readFlag(ss);
585      if(arg=="logfile")         this->logFile = readSval(ss);
586      if(arg=="outfile")         this->outFile = readSval(ss);
587      if(arg=="spectrafile")     this->spectraFile = readSval(ss);
588      if(arg=="flagoutputsmooth")this->flagOutputSmooth = readFlag(ss);
589      if(arg=="flagoutputrecon") this->flagOutputRecon = readFlag(ss);
590      if(arg=="flagoutputresid") this->flagOutputResid = readFlag(ss);
591      if(arg=="flagvot")         this->flagVOT = readFlag(ss);
592      if(arg=="votfile")         this->votFile = readSval(ss);
593      if(arg=="flagkarma")       this->flagKarma = readFlag(ss);
594      if(arg=="karmafile")       this->karmaFile = readSval(ss);
595      if(arg=="flagmaps")        this->flagMaps = readFlag(ss);
596      if(arg=="detectionmap")    this->detectionMap = readSval(ss);
597      if(arg=="momentmap")       this->momentMap = readSval(ss);
598      if(arg=="flagxoutput")     this->flagXOutput = readFlag(ss);
599
600      if(arg=="flagnegative")    this->flagNegative = readFlag(ss);
601      if(arg=="flagblankpix")    this->flagBlankPix = readFlag(ss);
602      if(arg=="blankpixvalue")   this->blankPixValue = readFval(ss);
603      if(arg=="flagmw")          this->flagMW = readFlag(ss);
604      if(arg=="maxmw")           this->maxMW = readIval(ss);
605      if(arg=="minmw")           this->minMW = readIval(ss);
606      if(arg=="beamsize")        this->numPixBeam = readFval(ss);
607
608      if(arg=="flagbaseline")    this->flagBaseline = readFlag(ss);
609      if(arg=="minpix")          this->minPix = readIval(ss);
610      if(arg=="flaggrowth")      this->flagGrowth = readFlag(ss);
611      if(arg=="growthcut")       this->growthCut = readFval(ss);
612
613      if(arg=="flagfdr")         this->flagFDR = readFlag(ss);
614      if(arg=="alphafdr")        this->alphaFDR = readFval(ss);
615
616      if(arg=="flagstatsec")     this->flagStatSec = readFlag(ss);
617      if(arg=="statsec")         this->statSec.setSection(readSval(ss));
618      if(arg=="snrcut")          this->snrCut = readFval(ss);
619      if(arg=="threshold"){
620                                 this->threshold = readFval(ss);
621                                 this->flagUserThreshold = true;
622      }
623     
624      if(arg=="flagsmooth")      this->flagSmooth = readFlag(ss);
625      if(arg=="hanningwidth")    this->hanningWidth = readIval(ss);
626
627      if(arg=="flagatrous")      this->flagATrous = readFlag(ss);
628      if(arg=="recondim")        this->reconDim = readIval(ss);
629      if(arg=="scalemin")        this->scaleMin = readIval(ss);
630      if(arg=="snrrecon")        this->snrRecon = readFval(ss);
631      if(arg=="filtercode"){
632                                 this->filterCode = readIval(ss);
633                                 this->reconFilter.define(this->filterCode);
634      }
635
636      if(arg=="flagadjacent")    this->flagAdjacent = readFlag(ss);
637      if(arg=="threshspatial")   this->threshSpatial = readFval(ss);
638      if(arg=="threshvelocity")  this->threshVelocity = readFval(ss);
639      if(arg=="minchannels")     this->minChannels = readIval(ss);
640
641      if(arg=="spectralmethod")  this->spectralMethod = makelower(readSval(ss));
642      if(arg=="spectralunits")   this->spectralUnits = makelower(readSval(ss));
643      if(arg=="pixelcentre")     this->pixelCentre = makelower(readSval(ss));
644      if(arg=="drawborders")     this->borders = readFlag(ss);
645      if(arg=="drawblankedges")  this->blankEdge = readFlag(ss);
646      if(arg=="verbose")         this->verbose = readFlag(ss);
647    }
648  }
649  if(this->flagATrous) this->flagSmooth = false;
650
651  // Make sure spectralMethod is an acceptable type -- default is "peak"
652  if((this->spectralMethod!="peak")&&(this->spectralMethod!="sum")){
653    duchampWarning("readParams","Changing spectralMethod to \"peak\".\n");
654    this->spectralMethod = "peak";
655  }
656
657  // Make sure pixelCentre is an acceptable type -- default is "peak"
658  if((this->pixelCentre!="centroid")&&
659     (this->pixelCentre!="average") &&
660     (this->pixelCentre!="peak")       ){
661    duchampWarning("readParams","Changing pixelCentre to \"centroid\".\n");
662    this->pixelCentre = "centroid";
663  }
664
665  return SUCCESS;
666}
667
668
669std::ostream& operator<< ( std::ostream& theStream, Param& par)
670{
671  /**
672   * Print out the parameter set in a formatted, easy to read style.
673   * Lists the parameters, a description of them, and their value.
674   */
675
676  // Only show the [blankPixValue] bit if we are using the parameter
677  // otherwise we have read it from the FITS header.
678  std::string blankParam = "";
679  if(par.getFlagUsingBlank()) blankParam = "[blankPixValue]";
680  std::string beamParam = "";
681  if(par.getFlagUsingBeam()) beamParam = "[beamSize]";
682
683  // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
684  //   theStream.setf(std::ios::boolalpha);
685  theStream.setf(std::ios::left);
686  theStream  <<"\n---- Parameters ----"<<std::endl;
687  theStream  << std::setfill('.');
688  const int widthText = 38;
689  const int widthPar  = 18;
690  if(par.getFlagSubsection())
691    theStream<<std::setw(widthText)<<"Image to be analysed"                 
692             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
693             <<"  =  " <<resetiosflags(std::ios::right)
694             <<(par.getImageFile()+par.getSubsection()) <<std::endl;
695  else
696    theStream<<std::setw(widthText)<<"Image to be analysed"                 
697             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[imageFile]"
698             <<"  =  " <<resetiosflags(std::ios::right)
699             <<par.getImageFile()      <<std::endl;
700  if(par.getFlagReconExists() && par.getFlagATrous()){
701    theStream<<std::setw(widthText)<<"Reconstructed array exists?"         
702             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconExists]"
703             <<"  =  " <<resetiosflags(std::ios::right)
704             <<stringize(par.getFlagReconExists())<<std::endl;
705    theStream<<std::setw(widthText)<<"FITS file containing reconstruction" 
706             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconFile]"
707             <<"  =  " <<resetiosflags(std::ios::right)
708             <<par.getReconFile()      <<std::endl;
709  }
710  if(par.getFlagSmoothExists() && par.getFlagSmooth()){
711    theStream<<std::setw(widthText)<<"Hanning-smoothed array exists?"         
712             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothExists]"
713             <<"  =  " <<resetiosflags(std::ios::right)
714             <<stringize(par.getFlagSmoothExists())<<std::endl;
715    theStream<<std::setw(widthText)<<"FITS file containing smoothed array" 
716             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[smoothFile]"
717             <<"  =  " <<resetiosflags(std::ios::right)
718             <<par.getSmoothFile()      <<std::endl;
719  }
720  theStream  <<std::setw(widthText)<<"Intermediate Logfile"
721             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[logFile]"
722             <<"  =  " <<resetiosflags(std::ios::right)
723             <<par.getLogFile()        <<std::endl;
724  theStream  <<std::setw(widthText)<<"Final Results file"                   
725             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[outFile]"
726             <<"  =  " <<resetiosflags(std::ios::right)
727             <<par.getOutFile()        <<std::endl;
728  theStream  <<std::setw(widthText)<<"Spectrum file"                       
729             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectraFile]"
730             <<"  =  " <<resetiosflags(std::ios::right)
731             <<par.getSpectraFile()    <<std::endl;
732  if(par.getFlagVOT()){
733    theStream<<std::setw(widthText)<<"VOTable file"                         
734             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[votFile]"
735             <<"  =  " <<resetiosflags(std::ios::right)
736             <<par.getVOTFile()        <<std::endl;
737  }
738  if(par.getFlagKarma()){
739    theStream<<std::setw(widthText)<<"Karma annotation file"               
740             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[karmaFile]"
741             <<"  =  " <<resetiosflags(std::ios::right)
742             
743             <<par.getKarmaFile()      <<std::endl;
744  }
745  if(par.getFlagMaps()){
746    theStream<<std::setw(widthText)<<"0th Moment Map"                       
747             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[momentMap]"
748             <<"  =  " <<resetiosflags(std::ios::right)
749             <<par.getMomentMap()      <<std::endl;
750    theStream<<std::setw(widthText)<<"Detection Map"                       
751             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[detectionMap]"
752             <<"  =  " <<resetiosflags(std::ios::right)
753             <<par.getDetectionMap()   <<std::endl;
754  }
755  theStream  <<std::setw(widthText)<<"Display a map in a pgplot xwindow?"
756             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagXOutput]"
757             <<"  =  " <<resetiosflags(std::ios::right)
758             <<stringize(par.getFlagXOutput())     <<std::endl;
759  if(par.getFlagATrous()){                             
760    theStream<<std::setw(widthText)<<"Saving reconstructed cube?"           
761             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputrecon]"
762             <<"  =  " <<resetiosflags(std::ios::right)
763             <<stringize(par.getFlagOutputRecon())<<std::endl;
764    theStream<<std::setw(widthText)<<"Saving residuals from reconstruction?"
765             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputresid]"
766             <<"  =  " <<resetiosflags(std::ios::right)
767             <<stringize(par.getFlagOutputResid())<<std::endl;
768  }                                                   
769  if(par.getFlagSmooth()){                             
770    theStream<<std::setw(widthText)<<"Saving Hanning-smoothed cube?"           
771             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagoutputsmooth]"
772             <<"  =  " <<resetiosflags(std::ios::right)
773             <<stringize(par.getFlagOutputSmooth())<<std::endl;
774  }                                                   
775  theStream  <<"------"<<std::endl;
776  theStream  <<std::setw(widthText)<<"Searching for Negative features?"     
777             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagNegative]"
778             <<"  =  " <<resetiosflags(std::ios::right)
779             <<stringize(par.getFlagNegative())   <<std::endl;
780  theStream  <<std::setw(widthText)<<"Fixing Blank Pixels?"                 
781             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBlankPix]"
782             <<"  =  " <<resetiosflags(std::ios::right)
783             <<stringize(par.getFlagBlankPix())   <<std::endl;
784  if(par.getFlagBlankPix()){
785    theStream<<std::setw(widthText)<<"Blank Pixel Value"                   
786             <<std::setw(widthPar)<<setiosflags(std::ios::right)<< blankParam
787             <<"  =  " <<resetiosflags(std::ios::right)
788             <<par.getBlankPixVal()    <<std::endl;
789  }
790  theStream  <<std::setw(widthText)<<"Removing Milky Way channels?"         
791             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagMW]"
792             <<"  =  " <<resetiosflags(std::ios::right)
793             <<stringize(par.getFlagMW())         <<std::endl;
794  if(par.getFlagMW()){
795    theStream<<std::setw(widthText)<<"Milky Way Channels"                   
796             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minMW - maxMW]"
797             <<"  =  " <<resetiosflags(std::ios::right)
798             <<par.getMinMW()
799             <<"-" <<par.getMaxMW()          <<std::endl;
800  }
801  theStream  <<std::setw(widthText)<<"Beam Size (pixels)"                   
802             <<std::setw(widthPar)<<setiosflags(std::ios::right)<< beamParam
803             <<"  =  " <<resetiosflags(std::ios::right)
804             <<par.getBeamSize()       <<std::endl;
805  theStream  <<std::setw(widthText)<<"Removing baselines before search?"   
806             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagBaseline]"
807             <<"  =  " <<resetiosflags(std::ios::right)
808             <<stringize(par.getFlagBaseline())   <<std::endl;
809  theStream  <<std::setw(widthText)<<"Minimum # Pixels in a detection"     
810             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minPix]"
811             <<"  =  " <<resetiosflags(std::ios::right)
812             <<par.getMinPix()         <<std::endl;
813  theStream  <<std::setw(widthText)<<"Minimum # Channels in a detection"   
814             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[minChannels]"
815             <<"  =  " <<resetiosflags(std::ios::right)
816             <<par.getMinChannels()    <<std::endl;
817  theStream  <<std::setw(widthText)<<"Growing objects after detection?"     
818             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagGrowth]"
819             <<"  =  " <<resetiosflags(std::ios::right)
820             <<stringize(par.getFlagGrowth())     <<std::endl;
821  if(par.getFlagGrowth()) {                           
822    theStream<<std::setw(widthText)<<"SNR Threshold for growth"             
823             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[growthCut]"
824             <<"  =  " <<resetiosflags(std::ios::right)
825             <<par.getGrowthCut()      <<std::endl;
826  }
827  theStream  <<std::setw(widthText)<<"Hanning-smoothing each spectrum first?"       
828             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagSmooth]"
829             <<"  =  " <<resetiosflags(std::ios::right)
830             <<stringize(par.getFlagSmooth())     <<std::endl;
831  if(par.getFlagSmooth())                             
832    theStream<<std::setw(widthText)<<"Width of hanning filter"     
833             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[hanningWidth]"
834             <<"  =  " <<resetiosflags(std::ios::right)
835             <<par.getHanningWidth()       <<std::endl;
836  theStream  <<std::setw(widthText)<<"Using A Trous reconstruction?"       
837             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagATrous]"
838             <<"  =  " <<resetiosflags(std::ios::right)
839             <<stringize(par.getFlagATrous())     <<std::endl;
840  if(par.getFlagATrous()){                             
841    theStream<<std::setw(widthText)<<"Number of dimensions in reconstruction"     
842             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[reconDim]"
843             <<"  =  " <<resetiosflags(std::ios::right)
844             <<par.getReconDim()       <<std::endl;
845    theStream<<std::setw(widthText)<<"Minimum scale in reconstruction"     
846             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[scaleMin]"
847             <<"  =  " <<resetiosflags(std::ios::right)
848             <<par.getMinScale()       <<std::endl;
849    theStream<<std::setw(widthText)<<"SNR Threshold within reconstruction" 
850             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrRecon]"
851             <<"  =  " <<resetiosflags(std::ios::right)
852             <<par.getAtrousCut()      <<std::endl;
853    theStream<<std::setw(widthText)<<"Filter being used for reconstruction"
854             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[filterCode]"
855             <<"  =  " <<resetiosflags(std::ios::right)
856             <<par.getFilterCode()
857             << " (" << par.getFilterName()  << ")" <<std::endl;
858  }                                                   
859  if(par.getFlagStatSec()){
860    theStream<<std::setw(widthText)<<"Section used by statistics calculation"
861             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[statSec]"
862             <<"  =  " <<resetiosflags(std::ios::right)
863             <<par.statSec.getSection()          <<std::endl;
864  }
865  theStream  <<std::setw(widthText)<<"Using FDR analysis?"                 
866             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagFDR]"
867             <<"  =  " <<resetiosflags(std::ios::right)
868             <<stringize(par.getFlagFDR())        <<std::endl;
869  if(par.getFlagFDR()){                               
870    theStream<<std::setw(widthText)<<"Alpha value for FDR analysis"         
871             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[alphaFDR]"
872             <<"  =  " <<resetiosflags(std::ios::right)
873             <<par.getAlpha()          <<std::endl;
874  }                                                   
875  else {
876    if(par.getFlagUserThreshold()){
877      theStream<<std::setw(widthText)<<"Detection Threshold"                       
878               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshold]"
879               <<"  =  " <<resetiosflags(std::ios::right)
880               <<par.getThreshold()            <<std::endl;
881    }
882    else{
883      theStream<<std::setw(widthText)<<"SNR Threshold (in sigma)"
884               <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[snrCut]"
885               <<"  =  " <<resetiosflags(std::ios::right)
886               <<par.getCut()            <<std::endl;
887    }
888  }
889  theStream  <<std::setw(widthText)<<"Using Adjacent-pixel criterion?"     
890             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[flagAdjacent]"
891             <<"  =  " <<resetiosflags(std::ios::right)
892             <<stringize(par.getFlagAdjacent())   <<std::endl;
893  if(!par.getFlagAdjacent()){
894    theStream<<std::setw(widthText)<<"Max. spatial separation for merging" 
895             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshSpatial]"
896             <<"  =  " <<resetiosflags(std::ios::right)
897             <<par.getThreshS()        <<std::endl;
898  }
899  theStream  <<std::setw(widthText)<<"Max. velocity separation for merging"
900             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[threshVelocity]"
901             <<"  =  " <<resetiosflags(std::ios::right)
902             <<par.getThreshV()        <<std::endl;
903  theStream  <<std::setw(widthText)<<"Method of spectral plotting"         
904             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[spectralMethod]"
905             <<"  =  " <<resetiosflags(std::ios::right)
906             <<par.getSpectralMethod() <<std::endl;
907  theStream  <<std::setw(widthText)<<"Type of object centre used in results"
908             <<std::setw(widthPar)<<setiosflags(std::ios::right)<<"[pixelCentre]"
909             <<"  =  " <<resetiosflags(std::ios::right)
910             <<par.getPixelCentre() <<std::endl;
911  theStream  <<"--------------------\n\n";
912  theStream  << std::setfill(' ');
913  theStream.unsetf(std::ios::left);
914  //  theStream.unsetf(std::ios::boolalpha);
915}
916
917
918void Param::copyHeaderInfo(FitsHeader &head)
919{
920  /**
921   * A function to copy across relevant header keywords from the
922   *  FitsHeader class to the Param class, as they are needed by
923   *  functions in the Param class.
924   * The parameters are the keywords BLANK, BSCALE, BZERO, and the beam size.
925   */
926
927  this->blankKeyword  = head.getBlankKeyword();
928  this->bscaleKeyword = head.getBscaleKeyword();
929  this->bzeroKeyword  = head.getBzeroKeyword();
930  this->blankPixValue = this->blankKeyword * this->bscaleKeyword +
931    this->bzeroKeyword;
932
933  this->numPixBeam    = head.getBeamSize();
934}
935
936std::string Param::outputSmoothFile()
937{
938  /**
939   * This function produces the required filename in which to save
940   *  the Hanning-smoothed array. If the input image is image.fits, then
941   *  the output will be eg. image.SMOOTH-3.fits, where the width of the
942   *  Hanning filter was 3 pixels.
943   */
944  std::string inputName = this->imageFile;
945  std::stringstream ss;
946  ss << inputName.substr(0,inputName.size()-5); 
947                          // remove the ".fits" on the end.
948  if(this->flagSubsection) ss<<".sub";
949  ss << ".SMOOTH-" << this->hanningWidth
950     << ".fits";
951  return ss.str();
952}
953
954std::string Param::outputReconFile()
955{
956  /**
957   * This function produces the required filename in which to save
958   *  the reconstructed array. If the input image is image.fits, then
959   *  the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
960   *  3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
961   */
962  std::string inputName = this->imageFile;
963  std::stringstream ss;
964  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
965  if(this->flagSubsection) ss<<".sub";
966  ss << ".RECON-" << this->reconDim
967     << "-"       << this->filterCode
968     << "-"       << this->snrRecon
969     << "-"       << this->scaleMin
970     << ".fits";
971  return ss.str();
972}
973
974std::string Param::outputResidFile()
975{
976  /**
977   * This function produces the required filename in which to save
978   *  the reconstructed array. If the input image is image.fits, then
979   *  the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
980   *  3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
981   */
982  std::string inputName = this->imageFile;
983  std::stringstream ss;
984  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
985  if(this->flagSubsection) ss<<".sub";
986  ss << ".RESID-" << this->reconDim
987     << "-"       << this->filterCode
988     << "-"       << this->snrRecon
989     << "-"       << this->scaleMin
990     << ".fits";
991  return ss.str();
992}
Note: See TracBrowser for help on using the repository browser.