source: trunk/src/param.cc @ 156

Last change on this file since 156 was 142, checked in by Matthew Whiting, 18 years ago

Large range of changes -- related to image cutouts and spectral units mostly.

duchamp.hh -- changed name of spectral type, and introduced one for frequency.
Cubes/getImage.cc -- changed the way the spectral type and spectral units are

looked at. Now is able to use frequency units (defaults
to MHz) when there isn't a good velocity transformation
possible (ie. if there is no restfreq defined).

Cubes/drawMomentCutout.cc -- Range of changes here:

  • improved the way unwanted pixels (those BLANK and outside image coundaries) are dealt with in the image array in drawMomentCutout
  • removed the way the blank pixel information was changed. Now behaves in a consistent way whether or not there are blank pixels
  • improved call to plotBlankEdges()
  • added call to drawFieldEdge() -- a new function that draws a yellow line around the boundary of the pixels of the image.
  • improved the tick mark that shows the angular scale of the cutout. Now adaptable to any pixel scale.
  • added calls to cpgtest() to all functions

Also these files were changed in relation to these edits:
Utils/drawBlankEdges.cc -- improved execution, with "blank" array.
Cubes/cubes.cc -- added call to Param::drawBlankEdge in Cube::plotBlankEdges()
Cubes/outputSpectra.cc -- moved spectra away from left and right axes.
param.cc -- added necessary calls for the new parameter. Other minor changes

to formatting. Added a missed call to stringize.

mainDuchamp.cc -- added #include <param.hh>
param.hh -- Added a new parameter: blankEdge
Cubes/cubes.hh -- improved appearance of comments
Cubes/plots.hh -- improved appearance of comments
InputComplete? -- added new parameter.
docs/Guide.tex -- added text about blank edge plotting.
All six images were changed as well.

CHANGES -- some of these changes -- not up to date yet!

File size: 30.4 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
6#include <math.h>
7#include <wcs.h>
8#include <wcsunits.h>
9#include <param.hh>
10#include <config.h>
11#include <duchamp.hh>
12#include <Utils/utils.hh>
13
14// Define funtion to print bools as words, in case the compiler doesn't recognise
15// the setf(ios::boolalpha) command...
16#ifdef HAVE_STDBOOL_H
17string stringize(bool b){
18  std::stringstream ss;
19  ss.setf(std::ios::boolalpha);
20  ss << b;
21  return ss.str();
22}
23#else
24string stringize(bool b){
25  std::string output;
26  if(b) output="true";
27  else output="false";
28  return output;
29}
30#endif
31
32using std::setw;
33using std::endl;
34
35/****************************************************************/
36///////////////////////////////////////////////////
37//// Functions for FitsHeader class:
38///////////////////////////////////////////////////
39
40FitsHeader::FitsHeader(){
41  this->wcs = new wcsprm;
42  this->wcs->flag=-1;
43  wcsini(true,3,this->wcs);
44  this->wcsIsGood = false;
45  this->nwcs = 0;
46  this->scale=1.;
47  this->offset=0.;
48  this->power=1.;
49  this->fluxUnits="counts";
50}
51
52FitsHeader::FitsHeader(const FitsHeader& h){
53  this->wcs = new wcsprm;
54  this->wcs->flag=-1;
55  wcsini(true,h.wcs->naxis,this->wcs);
56  wcscopy(true,h.wcs,this->wcs);
57  wcsset(this->wcs);
58  this->nwcs = h.nwcs;
59  this->wcsIsGood = h.wcsIsGood;
60  this->spectralUnits = h.spectralUnits;
61  this->fluxUnits = h.fluxUnits;
62  this->intFluxUnits = h.intFluxUnits;
63  this->beamSize = h.beamSize;
64  this->bmajKeyword = h.bmajKeyword;
65  this->bminKeyword = h.bminKeyword;
66  this->blankKeyword = h.blankKeyword;
67  this->bzeroKeyword = h.bzeroKeyword;
68  this->bscaleKeyword = h.bscaleKeyword;
69  this->scale = h.scale;
70  this->offset = h.offset;
71  this->power = h.power;
72}
73
74FitsHeader& FitsHeader::operator= (const FitsHeader& h){
75  this->wcs = new wcsprm;
76  this->wcs->flag=-1;
77  wcsini(true,h.wcs->naxis,this->wcs);
78  wcscopy(true,h.wcs,this->wcs);
79  wcsset(this->wcs);
80  this->nwcs = h.nwcs;
81  this->wcsIsGood = h.wcsIsGood;
82  this->spectralUnits = h.spectralUnits;
83  this->fluxUnits = h.fluxUnits;
84  this->intFluxUnits = h.intFluxUnits;
85  this->beamSize = h.beamSize;
86  this->bmajKeyword = h.bmajKeyword;
87  this->bminKeyword = h.bminKeyword;
88  this->blankKeyword = h.blankKeyword;
89  this->bzeroKeyword = h.bzeroKeyword;
90  this->bscaleKeyword = h.bscaleKeyword;
91  this->scale = h.scale;
92  this->offset = h.offset;
93  this->power = h.power;
94}
95
96void FitsHeader::setWCS(wcsprm *w)
97{
98  /**
99   * FitsHeader::setWCS(wcsprm *)
100   *  A function that assigns the wcs parameters, and runs
101   *   wcsset to set it up correctly.
102   *  Performs a check to see if the WCS is good (by looking at
103   *   the lng and lat wcsprm parameters), and sets the wcsIsGood
104   *   flag accordingly.
105   */
106  wcscopy(true,w,this->wcs);
107  wcsset(this->wcs);
108  if( (w->lng!=-1) && (w->lat!=-1) ) this->wcsIsGood = true;
109}
110
111wcsprm *FitsHeader::getWCS()
112{
113  /**
114   * FitsHeader::getWCS()
115   *  A function that returns a wcsprm object corresponding to the WCS.
116   */
117  wcsprm *wNew = new wcsprm;
118  wNew->flag=-1;
119  wcsini(true,this->wcs->naxis,wNew);
120  wcscopy(true,this->wcs,wNew);
121  wcsset(wNew);
122  return wNew;
123}
124
125int     FitsHeader::wcsToPix(const double *world, double *pix){
126  return wcsToPixSingle(this->wcs,world,pix);}
127int     FitsHeader::wcsToPix(const double *world, double *pix, const int npts){
128  return wcsToPixMulti(this->wcs,world,pix,npts);}
129int     FitsHeader::pixToWCS(const double *pix, double *world){
130  return pixToWCSSingle(this->wcs,pix,world);}
131int     FitsHeader::pixToWCS(const double *pix, double *world, const int npts){
132  return pixToWCSMulti(this->wcs,pix,world,npts);}
133
134double  FitsHeader::pixToVel(double &x, double &y, double &z)
135{
136//   return pixelToVelocity(this->wcs,x,y,z,this->spectralUnits);};
137  double *pix   = new double[3];
138  double *world = new double[3];
139  pix[0] = x; pix[1] = y; pix[2] = z;
140  pixToWCSSingle(this->wcs,pix,world);
141  double vel = this->specToVel(world[2]);
142  delete [] pix;
143  delete [] world;
144  return vel;
145}
146
147double* FitsHeader::pixToVel(double &x, double &y, double *zarray, int size)
148{
149//   return pixelToVelocity(this->wcs,x,y,z,this->spectralUnits);};
150  double *pix   = new double[size*3];
151  for(int i=0;i<size;i++){
152    pix[3*i] = x; pix[3*i+1] = y; pix[3*i+2] = zarray[i];
153  }
154  double *world = new double[size*3];
155  pixToWCSMulti(this->wcs,pix,world,size);
156  delete [] pix;
157  double *newzarray = new double[size];
158  for(int i=0;i<size;i++) newzarray[i] = this->specToVel(world[3*i+2]);
159  delete [] world;
160  return newzarray;
161}
162
163double  FitsHeader::specToVel(const double &coord)
164{
165  double vel;
166  if(power==1.0) vel =  coord*this->scale + this->offset;
167  else vel = pow( (coord*this->scale + this->offset), this->power);
168  return vel;
169}
170
171double  FitsHeader::velToSpec(const float &velocity)
172{
173//   return velToCoord(this->wcs,velocity,this->spectralUnits);};
174  return (pow(velocity, 1./this->power) - this->offset) / this->scale;}
175
176string  FitsHeader::getIAUName(double ra, double dec)
177{
178  if(strcmp(this->wcs->lngtyp,"RA")==0) return getIAUNameEQ(ra, dec, this->wcs->equinox);
179  else return getIAUNameGAL(ra, dec);
180}
181
182void FitsHeader::fixUnits(Param &par)
183{
184  // define spectral units from the param set
185  this->spectralUnits = par.getSpectralUnits();
186
187  double sc=1.;
188  double of=0.;
189  double po=1.;;
190  if(this->wcsIsGood){
191    int flag = wcsunits( this->wcs->cunit[2], this->spectralUnits.c_str(),
192                         &sc, &of, &po);
193    if(flag>0){
194      std::stringstream errmsg;
195      errmsg << "WCSUNITS Error, Code = " << flag
196             << ": "<< wcsunits_errmsg[flag];
197      if(flag==10) errmsg << "\nTried to get conversion from '"
198                          << wcs->cunit[2] << "' to '"
199                          << this->spectralUnits.c_str() << "'\n";
200      this->spectralUnits = this->wcs->cunit[2];
201      if(this->spectralUnits==""){
202        errmsg << "Setting coordinates to 'XX' for clarity.\n";
203        this->spectralUnits = "XX";
204      }
205      duchampError("fixUnits", errmsg.str());
206     
207    }
208  }
209  this->scale = sc;
210  this->offset= of;
211  this->power = po;
212
213  // Work out the integrated flux units, based on the spectral units.
214  // If flux is per beam, trim the /beam from the flux units and multiply
215  //  by the spectral units.
216  // Otherwise, just muliply by the spectral units.
217  if(this->fluxUnits.size()>0){
218    if(this->fluxUnits.substr(this->fluxUnits.size()-5,
219                              this->fluxUnits.size()   ) == "/beam"){
220      this->intFluxUnits = this->fluxUnits.substr(0,this->fluxUnits.size()-5)
221        +" " +this->spectralUnits;
222    }
223    else this->intFluxUnits = fluxUnits + " " + this->spectralUnits;
224  }
225
226}
227
228/****************************************************************/
229///////////////////////////////////////////////////
230//// Accessor Functions for Parameter class:
231///////////////////////////////////////////////////
232Param::Param(){
233  /**
234   * Param()
235   *  Default intial values for the parameters.
236   * imageFile has no default value!
237   */
238  // Input files
239  this->imageFile       = "";
240  this->flagSubsection  = false;
241  this->subsection      = "[*,*,*]";
242  this->flagReconExists = false;
243  this->reconFile       = "";
244  // Output files
245  this->flagLog         = true;
246  this->logFile         = "duchamp-Logfile.txt";
247  this->outFile         = "duchamp-Results.txt";
248  this->spectraFile     = "duchamp-Spectra.ps";
249  this->flagOutputRecon = false;
250  this->flagOutputResid = false;
251  this->flagVOT         = false;
252  this->votFile         = "duchamp-Results.xml";
253  this->flagKarma       = false;
254  this->karmaFile       = "duchamp-Results.ann";
255  this->flagMaps        = true;
256  this->detectionMap    = "duchamp-DetectionMap.ps";
257  this->momentMap       = "duchamp-MomentMap.ps";
258  // Cube related parameters
259  this->flagBlankPix    = true;
260  this->blankPixValue   = -8.00061;
261  this->blankKeyword    = 1;
262  this->bscaleKeyword   = -8.00061;
263  this->bzeroKeyword    = 0.;
264  this->flagUsingBlank  = false;
265  this->flagMW          = false;
266  this->maxMW           = 112;
267  this->minMW           = 75;
268  this->numPixBeam      = 0.;
269  // Trim-related         
270  this->flagTrimmed     = false;
271  this->borderLeft      = 0;
272  this->borderRight     = 0;
273  this->borderBottom    = 0;
274  this->borderTop       = 0;
275  // Subsection offsets
276  this->xSubOffset      = 0;
277  this->ySubOffset      = 0;
278  this->zSubOffset      = 0;
279  // Baseline related
280  this->flagBaseline    = false;
281  // Detection-related   
282  this->flagNegative    = false;
283  // Object growth       
284  this->flagGrowth      = false;
285  this->growthCut       = 2.;
286  // FDR analysis         
287  this->flagFDR         = false;
288  this->alphaFDR        = 0.01;
289  // Other detection     
290  this->snrCut          = 3.;
291  // A trous reconstruction parameters
292  this->flagATrous      = true;
293  this->reconDim        = 3;
294  this->scaleMin        = 1;
295  this->snrRecon        = 4.;
296  this->filterCode      = 1;
297  // Volume-merging parameters
298  this->flagAdjacent    = true;
299  this->threshSpatial   = 3.;
300  this->threshVelocity  = 7.;
301  this->minChannels     = 3;
302  this->minPix          = 2;
303  // Input-Output related
304  this->spectralMethod  = "peak";
305  this->borders         = true;
306  this->blankEdge       = true;
307  this->verbose         = true;
308  this->spectralUnits   = "km/s";
309};
310
311Param& Param::operator= (const Param& p)
312{
313  this->imageFile       = p.imageFile;
314  this->flagSubsection  = p.flagSubsection;
315  this->subsection      = p.subsection;     
316  this->flagReconExists = p.flagReconExists;
317  this->reconFile       = p.reconFile;     
318  this->flagLog         = p.flagLog;       
319  this->logFile         = p.logFile;       
320  this->outFile         = p.outFile;       
321  this->spectraFile     = p.spectraFile;   
322  this->flagOutputRecon = p.flagOutputRecon;
323  this->flagOutputResid = p.flagOutputResid;
324  this->flagVOT         = p.flagVOT;         
325  this->votFile         = p.votFile;       
326  this->flagKarma       = p.flagKarma;     
327  this->karmaFile       = p.karmaFile;     
328  this->flagMaps        = p.flagMaps;       
329  this->detectionMap    = p.detectionMap;   
330  this->momentMap       = p.momentMap;     
331  this->flagBlankPix    = p.flagBlankPix;   
332  this->blankPixValue   = p.blankPixValue; 
333  this->blankKeyword    = p.blankKeyword;   
334  this->bscaleKeyword   = p.bscaleKeyword; 
335  this->bzeroKeyword    = p.bzeroKeyword;   
336  this->flagUsingBlank  = p.flagUsingBlank;
337  this->flagMW          = p.flagMW;         
338  this->maxMW           = p.maxMW;         
339  this->minMW           = p.minMW;         
340  this->numPixBeam      = p.numPixBeam;     
341  this->flagTrimmed     = p.flagTrimmed;   
342  this->borderLeft      = p.borderLeft;     
343  this->borderRight     = p.borderRight;   
344  this->borderBottom    = p.borderBottom;   
345  this->borderTop       = p.borderTop;     
346  this->xSubOffset      = p.xSubOffset;     
347  this->ySubOffset      = p.ySubOffset;     
348  this->zSubOffset      = p.zSubOffset;
349  this->flagBaseline    = p.flagBaseline;
350  this->flagNegative    = p.flagNegative;
351  this->flagGrowth      = p.flagGrowth;
352  this->growthCut       = p.growthCut;
353  this->flagFDR         = p.flagFDR;
354  this->alphaFDR        = p.alphaFDR;
355  this->snrCut          = p.snrCut;
356  this->flagATrous      = p.flagATrous;
357  this->reconDim        = p.reconDim;
358  this->scaleMin        = p.scaleMin;
359  this->snrRecon        = p.snrRecon;
360  this->filterCode      = p.filterCode;
361  this->flagAdjacent    = p.flagAdjacent;
362  this->threshSpatial   = p.threshSpatial;
363  this->threshVelocity  = p.threshVelocity;
364  this->minChannels     = p.minChannels;
365  this->minPix          = p.minPix;
366  this->spectralMethod  = p.spectralMethod;
367  this->borders         = p.borders;
368  this->verbose         = p.verbose;
369  this->spectralUnits   = p.spectralUnits;
370}
371
372/****************************************************************/
373///////////////////////////////////////////////////
374//// Other Functions using the  Parameter class:
375///////////////////////////////////////////////////
376
377string makelower( string s )
378{
379  // "borrowed" from Matt Howlett's 'fred'
380  string out = "";
381  for( int i=0; i<s.size(); ++i ) {
382    out += tolower(s[i]);
383  }
384  return out;
385}
386
387bool boolify( string s )
388{
389  /**
390   * bool boolify(string)
391   *  Convert a string to a bool variable
392   *  "1" and "true" get converted to true
393   *  "0" and "false" (and anything else) get converted to false
394   */
395  if((s=="1") || (makelower(s)=="true")) return true;
396  else if((s=="0") || (makelower(s)=="false")) return false;
397  else return false;
398}
399
400void Param::readParams(string paramfile)
401{
402
403  std::ifstream fin(paramfile.c_str());
404  string line;
405  string sval;
406  float fval;
407  int ival;
408  while( !std::getline(fin,line,'\n').eof()){
409
410    if(line[0]!='#'){
411      std::stringstream ss;
412      ss.str(line);
413      string arg;
414      ss >> arg;     
415      if(makelower(arg)=="imagefile"){       ss >> sval; this->imageFile = sval;}
416      if(makelower(arg)=="flagsubsection"){  ss >> sval; this->flagSubsection = boolify(sval); }
417      if(makelower(arg)=="subsection"){      ss >> sval; this->subsection = sval; }
418      if(makelower(arg)=="flagreconexists"){ ss >> sval; this->flagReconExists = boolify(sval); }
419      if(makelower(arg)=="reconfile"){       ss >> sval; this->reconFile = sval; }
420
421      if(makelower(arg)=="flaglog"){         ss >> sval; this->flagLog = boolify(sval); }
422      if(makelower(arg)=="logfile"){         ss >> sval; this->logFile = sval; }
423      if(makelower(arg)=="outfile"){         ss >> sval; this->outFile = sval; }
424      if(makelower(arg)=="spectrafile"){     ss >> sval; this->spectraFile = sval; }
425      if(makelower(arg)=="flagoutputrecon"){ ss >> sval; this->flagOutputRecon = boolify(sval); }
426      if(makelower(arg)=="flagoutputresid"){ ss >> sval; this->flagOutputResid = boolify(sval); }
427      if(makelower(arg)=="flagvot"){         ss >> sval; this->flagVOT = boolify(sval); }
428      if(makelower(arg)=="votfile"){         ss >> sval; this->votFile = sval; }
429      if(makelower(arg)=="flagkarma"){       ss >> sval; this->flagKarma = boolify(sval); }
430      if(makelower(arg)=="karmafile"){       ss >> sval; this->karmaFile = sval; }
431      if(makelower(arg)=="flagmaps"){        ss >> sval; this->flagMaps = boolify(sval); }
432      if(makelower(arg)=="detectionmap"){    ss >> sval; this->detectionMap = sval; }
433      if(makelower(arg)=="momentmap"){       ss >> sval; this->momentMap = sval; }
434
435      if(makelower(arg)=="flagnegative"){    ss >> sval; this->flagNegative = boolify(sval);}
436      if(makelower(arg)=="flagblankpix"){    ss >> sval; this->flagBlankPix = boolify(sval); }
437      if(makelower(arg)=="blankpixvalue"){   ss >> fval; this->blankPixValue = fval; }
438      if(makelower(arg)=="flagmw"){          ss >> sval; this->flagMW = boolify(sval); }
439      if(makelower(arg)=="maxmw"){           ss >> ival; this->maxMW = ival; }
440      if(makelower(arg)=="minmw"){           ss >> ival; this->minMW = ival; }
441
442      if(makelower(arg)=="flagbaseline"){    ss >> sval; this->flagBaseline = boolify(sval); }
443      if(makelower(arg)=="minpix"){          ss >> ival; this->minPix = ival; }
444      if(makelower(arg)=="flaggrowth"){      ss >> sval; this->flagGrowth = boolify(sval); }
445      if(makelower(arg)=="growthcut"){       ss >> fval; this->growthCut = fval; }
446
447      if(makelower(arg)=="flagfdr"){         ss >> sval; this->flagFDR = boolify(sval); }
448      if(makelower(arg)=="alphafdr"){        ss >> fval; this->alphaFDR = fval; }
449
450      if(makelower(arg)=="snrcut"){          ss >> fval; this->snrCut = fval; }
451
452      if(makelower(arg)=="flagatrous"){      ss >> sval; this->flagATrous = boolify(sval); }
453      if(makelower(arg)=="recondim"){        ss >> ival; this->reconDim = ival; }
454      if(makelower(arg)=="scalemin"){        ss >> ival; this->scaleMin = ival; }
455      if(makelower(arg)=="snrrecon"){        ss >> fval; this->snrRecon = fval; }
456      if(makelower(arg)=="filtercode"){      ss >> ival; this->filterCode = ival; }
457
458      if(makelower(arg)=="flagadjacent"){    ss >> sval; this->flagAdjacent = boolify(sval); }
459      if(makelower(arg)=="threshspatial"){   ss >> fval; this->threshSpatial = fval; }
460      if(makelower(arg)=="threshvelocity"){  ss >> fval; this->threshVelocity = fval; }
461      if(makelower(arg)=="minchannels"){     ss >> ival; this->minChannels = ival; }
462
463      if(makelower(arg)=="spectralmethod"){  ss >> sval; this->spectralMethod = makelower(sval); }
464      if(makelower(arg)=="spectralunits"){   ss >> sval; this->spectralUnits = makelower(sval); }
465      if(makelower(arg)=="drawborders"){     ss >> sval; this->borders = boolify(sval); }
466      if(makelower(arg)=="drawblankedges"){  ss >> sval; this->blankEdge = boolify(sval); }
467      if(makelower(arg)=="verbose"){         ss >> sval; this->verbose = boolify(sval); }
468    }
469  }
470}
471
472
473std::ostream& operator<< ( std::ostream& theStream, Param& par)
474{
475  // Only show the [blankPixValue] bit if we are using the parameter
476  // otherwise we have read it from the FITS header.
477  string blankParam = "";
478  if(par.getFlagUsingBlank()) blankParam = "[blankPixValue]";
479
480  // BUG -- can get error: `boolalpha' is not a member of type `ios' -- old compilers: gcc 2.95.3?
481//   theStream.setf(std::ios::boolalpha);
482  theStream.setf(std::ios::left);
483  theStream  <<"---- Parameters ----"<<endl;
484  theStream  << std::setfill('.');
485  if(par.getFlagSubsection())
486    theStream<<setw(38)<<"Image to be analysed"                 
487             <<setw(18)<<setiosflags(std::ios::right)  <<"[imageFile]"
488             <<"  =  " <<resetiosflags(std::ios::right)
489             <<(par.getImageFile()+par.getSubsection())   <<endl;
490  else
491    theStream<<setw(38)<<"Image to be analysed"                 
492             <<setw(18)<<setiosflags(std::ios::right)  <<"[imageFile]"
493             <<"  =  " <<resetiosflags(std::ios::right)<<par.getImageFile()      <<endl;
494  if(par.getFlagReconExists() && par.getFlagATrous()){
495    theStream<<setw(38)<<"Reconstructed array exists?"         
496             <<setw(18)<<setiosflags(std::ios::right)  <<"[reconExists]"
497             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagReconExists())<<endl;
498    theStream<<setw(38)<<"FITS file containing reconstruction" 
499             <<setw(18)<<setiosflags(std::ios::right)  <<"[reconFile]"
500             <<"  =  " <<resetiosflags(std::ios::right)<<par.getReconFile()      <<endl;
501  }
502  theStream  <<setw(38)<<"Intermediate Logfile"
503             <<setw(18)<<setiosflags(std::ios::right)  <<"[logFile]"
504             <<"  =  " <<resetiosflags(std::ios::right)<<par.getLogFile()        <<endl;
505  theStream  <<setw(38)<<"Final Results file"                   
506             <<setw(18)<<setiosflags(std::ios::right)  <<"[outFile]"
507             <<"  =  " <<resetiosflags(std::ios::right)<<par.getOutFile()        <<endl;
508  theStream  <<setw(38)<<"Spectrum file"                       
509             <<setw(18)<<setiosflags(std::ios::right)  <<"[spectraFile]"
510             <<"  =  " <<resetiosflags(std::ios::right)<<par.getSpectraFile()    <<endl;
511  if(par.getFlagVOT()){
512    theStream<<setw(38)<<"VOTable file"                         
513             <<setw(18)<<setiosflags(std::ios::right)  <<"[votFile]"
514             <<"  =  " <<resetiosflags(std::ios::right)<<par.getVOTFile()        <<endl;
515  }
516  if(par.getFlagKarma()){
517    theStream<<setw(38)<<"Karma annotation file"               
518             <<setw(18)<<setiosflags(std::ios::right)  <<"[karmaFile]"
519             <<"  =  " <<resetiosflags(std::ios::right)<<par.getKarmaFile()      <<endl;
520  }
521  if(par.getFlagMaps()){
522    theStream<<setw(38)<<"0th Moment Map"                       
523             <<setw(18)<<setiosflags(std::ios::right)  <<"[momentMap]"
524             <<"  =  " <<resetiosflags(std::ios::right)<<par.getMomentMap()      <<endl;
525    theStream<<setw(38)<<"Detection Map"                       
526             <<setw(18)<<setiosflags(std::ios::right)  <<"[detectionMap]"
527             <<"  =  " <<resetiosflags(std::ios::right)<<par.getDetectionMap()   <<endl;
528  }
529  if(par.getFlagATrous()){                             
530    theStream<<setw(38)<<"Saving reconstructed cube?"           
531             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagoutputrecon]"
532             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagOutputRecon())<<endl;
533    theStream<<setw(38)<<"Saving residuals from reconstruction?"
534             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagoutputresid]"
535             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagOutputResid())<<endl;
536  }                                                   
537  theStream  <<"------"<<endl;
538  theStream  <<setw(38)<<"Searching for Negative features?"     
539             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagNegative]"
540             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagNegative())   <<endl;
541  theStream  <<setw(38)<<"Fixing Blank Pixels?"                 
542             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagBlankPix]"
543             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagBlankPix())   <<endl;
544  if(par.getFlagBlankPix()){
545    theStream<<setw(38)<<"Blank Pixel Value"                   
546             <<setw(18)<<setiosflags(std::ios::right)  << blankParam
547             <<"  =  " <<resetiosflags(std::ios::right)<<par.getBlankPixVal()    <<endl;
548  }
549  theStream  <<setw(38)<<"Removing Milky Way channels?"         
550             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagMW]"
551             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagMW())         <<endl;
552  if(par.getFlagMW()){
553    theStream<<setw(38)<<"Milky Way Channels"                   
554             <<setw(18)<<setiosflags(std::ios::right)  <<"[minMW - maxMW]"
555             <<"  =  " <<resetiosflags(std::ios::right)<<par.getMinMW()
556             <<"-" <<par.getMaxMW()          <<endl;
557  }
558  theStream  <<setw(38)<<"Beam Size (pixels)"                   
559             <<setw(18)<<setiosflags(std::ios::right)  <<""
560             <<"  =  " <<resetiosflags(std::ios::right)<<par.getBeamSize()       <<endl;
561  theStream  <<setw(38)<<"Removing baselines before search?"   
562             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagBaseline]"
563             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagBaseline())   <<endl;
564  theStream  <<setw(38)<<"Minimum # Pixels in a detection"     
565             <<setw(18)<<setiosflags(std::ios::right)  <<"[minPix]"
566             <<"  =  " <<resetiosflags(std::ios::right)<<par.getMinPix()         <<endl;
567  theStream  <<setw(38)<<"Minimum # Channels in a detection"   
568             <<setw(18)<<setiosflags(std::ios::right)  <<"[minChannels]"
569             <<"  =  " <<resetiosflags(std::ios::right)<<par.getMinChannels()    <<endl;
570  theStream  <<setw(38)<<"Growing objects after detection?"     
571             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagGrowth]"
572             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagGrowth())     <<endl;
573  if(par.getFlagGrowth()) {                           
574    theStream<<setw(38)<<"SNR Threshold for growth"             
575             <<setw(18)<<setiosflags(std::ios::right)  <<"[growthCut]"
576             <<"  =  " <<resetiosflags(std::ios::right)<<par.getGrowthCut()      <<endl;
577  }
578  theStream  <<setw(38)<<"Using A Trous reconstruction?"       
579             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagATrous]"
580             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagATrous())     <<endl;
581  if(par.getFlagATrous()){                             
582    theStream<<setw(38)<<"Number of dimensions in reconstruction"     
583             <<setw(18)<<setiosflags(std::ios::right)  <<"[reconDim]"
584             <<"  =  " <<resetiosflags(std::ios::right)<<par.getReconDim()       <<endl;
585    theStream<<setw(38)<<"Minimum scale in reconstruction"     
586             <<setw(18)<<setiosflags(std::ios::right)  <<"[scaleMin]"
587             <<"  =  " <<resetiosflags(std::ios::right)<<par.getMinScale()       <<endl;
588    theStream<<setw(38)<<"SNR Threshold within reconstruction" 
589             <<setw(18)<<setiosflags(std::ios::right)  <<"[snrRecon]"
590             <<"  =  " <<resetiosflags(std::ios::right)<<par.getAtrousCut()      <<endl;
591    theStream<<setw(38)<<"Filter being used for reconstruction"
592             <<setw(18)<<setiosflags(std::ios::right)  <<"[filterCode]"
593             <<"  =  " <<resetiosflags(std::ios::right)<<par.getFilterCode()
594             << " (" << par.getFilterName()  << ")" <<endl;
595  }                                                   
596  theStream  <<setw(38)<<"Using FDR analysis?"                 
597             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagFDR]"
598             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagFDR())        <<endl;
599  if(par.getFlagFDR()){                               
600    theStream<<setw(38)<<"Alpha value for FDR analysis"         
601             <<setw(18)<<setiosflags(std::ios::right)  <<"[alphaFDR]"
602             <<"  =  " <<resetiosflags(std::ios::right)<<par.getAlpha()          <<endl;
603  }                                                   
604  else {
605    theStream<<setw(38)<<"SNR Threshold"                       
606             <<setw(18)<<setiosflags(std::ios::right)  <<"[snrCut]"
607             <<"  =  " <<resetiosflags(std::ios::right)<<par.getCut()            <<endl;
608  }
609  theStream  <<setw(38)<<"Using Adjacent-pixel criterion?"     
610             <<setw(18)<<setiosflags(std::ios::right)  <<"[flagAdjacent]"
611             <<"  =  " <<resetiosflags(std::ios::right)<<stringize(par.getFlagAdjacent())   <<endl;
612  if(!par.getFlagAdjacent()){
613    theStream<<setw(38)<<"Max. spatial separation for merging" 
614             <<setw(18)<<setiosflags(std::ios::right)  <<"[threshSpatial]"
615             <<"  =  " <<resetiosflags(std::ios::right)<<par.getThreshS()        <<endl;
616  }
617  theStream  <<setw(38)<<"Max. velocity separation for merging"
618             <<setw(18)<<setiosflags(std::ios::right)  <<"[threshVelocity]"
619             <<"  =  " <<resetiosflags(std::ios::right)<<par.getThreshV()        <<endl;
620  theStream  <<setw(38)<<"Method of spectral plotting"         
621             <<setw(18)<<setiosflags(std::ios::right)  <<"[spectralMethod]"
622             <<"  =  " <<resetiosflags(std::ios::right)<<par.getSpectralMethod() <<endl;
623  theStream  <<"--------------------"<<endl;
624  theStream  << std::setfill(' ');
625  theStream.unsetf(std::ios::left);
626  //  theStream.unsetf(std::ios::boolalpha);
627}
628
629void Param::parseSubsection()
630{
631  /**
632   *  Param::parseSubsection()
633   *
634   *   Convert the Param::subsection string to a series of offset values
635   *    for each dimension.
636   *   This involves reading the individual substrings and converting to
637   *    integers, and storing in the {x,y,z}SubOffset parameters.
638   *   Steps in the subsection string are not dealt with -- a warning message
639   *    is written to the screen, and the step values are ignored.
640   */
641
642  std::stringstream ss;
643  ss.str(this->subsection);
644  bool removeStep = false;
645  string x,y,z;
646  getline(ss,x,'[');
647  getline(ss,x,',');
648  getline(ss,y,',');
649  getline(ss,z,']');
650  char *end;
651  if(x!="*") {
652    int x1,x2,dx;
653    int a = x.find(':');  // first occurence of ':' in x-subsection string
654    int b = x.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence.
655    x1 = atoi( x.substr(0,a).c_str() ); // minimum x in subsection
656    this->xSubOffset = x1 - 1;
657    if(b>0){ // there is a dx component
658      x2 = atoi( x.substr(a+1,b-a-1).c_str() ); // maximum x in subsection
659      dx = atoi( x.substr(b+1,x.size()).c_str() ); // delta x in subsection
660      x = x.substr(0,b); // rewrite x without the delta-x part.
661      removeStep = true;
662    }
663  }
664  if(y!="*") {
665    int y1,y2,dy;
666    int a = y.find(':');  // first occurence of ':' in y-subsection string
667    int b = y.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence.
668    y1 = atoi( y.substr(0,a).c_str() ); // minimum y in subsection
669    this->ySubOffset = y1 - 1;
670    if(b>0){ // there is a dy component
671      y2 = atoi( y.substr(a+1,b-a-1).c_str() ); // maximum y in subsection
672      dy = atoi( y.substr(b+1,y.size()).c_str() ); // delta y in subsection
673      y = y.substr(0,b); // rewrite y without the delta-y part.
674      removeStep = true;
675    }
676  }
677  if(z!="*") {
678    int z1,z2,dz;
679    int a = z.find(':');  // first occurence of ':' in z-subsection string
680    int b = z.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence.
681    z1 = atoi( z.substr(0,a).c_str() ); // minimum z in subsection
682    this->zSubOffset = z1 - 1;
683    if(b>0){ // there is a dz component
684      z2 = atoi( z.substr(a+1,b-a-1).c_str() ); // maximum z in subsection
685      dz = atoi( z.substr(b+1,z.size()).c_str() ); // delta z in subsection
686      z = z.substr(0,b); // rewrite z without the delta-z part.
687      removeStep = true;
688    }
689  }
690
691  if(removeStep){
692    std::stringstream errmsg;
693    errmsg << "\aThe subsection given is " << this->subsection <<".\n"
694           << "Duchamp is currently unable to deal with pixel steps"
695           << " in the subsection.\n"
696           << "These have been ignored, and so the subection used is ";
697    // rewrite subsection without any step sizes.
698   this->subsection = "[" + x + "," + y + "," + z + "]"; 
699   errmsg << this->subsection << std::endl;
700   duchampWarning("parseSubsection", errmsg.str());
701  }
702
703}
704
705void Param::copyHeaderInfo(FitsHeader &head)
706{
707  /**
708   *  Param::copyHeaderInfo(FitsHeader &head)
709   * A function to copy across relevant header keywords from the
710   *  FitsHeader class to the Param class, as they are needed by
711   *  functions in the Param class.
712   */
713
714  this->blankKeyword  = head.getBlankKeyword();
715  this->bscaleKeyword = head.getBscaleKeyword();
716  this->bzeroKeyword  = head.getBzeroKeyword();
717  this->blankPixValue = this->blankKeyword * this->bscaleKeyword + this->bzeroKeyword;
718
719  this->numPixBeam    = head.getBeamSize();
720}
721
722bool Param::isBlank(float &value)
723{
724  /**
725   *  Param::isBlank(float)
726   *   Tests whether the value passed as the argument is BLANK or not.
727   *   If flagBlankPix is false, return false.
728   *   Otherwise, compare to the relevant FITS keywords, using integer comparison.
729   *   Return a bool.
730   */
731
732  return this->flagBlankPix &&
733    (this->blankKeyword == int((value-this->bzeroKeyword)/this->bscaleKeyword));
734}
735
736string Param::outputReconFile()
737{
738  /**
739   *  outputReconFile()
740   *
741   *   This function produces the required filename in which to save
742   *    the reconstructed array. If the input image is image.fits, then
743   *    the output will be eg. image.RECON-3-2-4-1.fits, where the numbers are
744   *    3=reconDim, 2=filterCode, 4=snrRecon, 1=minScale
745   */
746  string inputName = this->imageFile;
747  std::stringstream ss;
748  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
749  if(this->flagSubsection) ss<<".sub";
750  ss << ".RECON-" << this->reconDim
751     << "-"       << this->filterCode
752     << "-"       << this->snrRecon
753     << "-"       << this->scaleMin
754     << ".fits";
755  return ss.str();
756}
757
758string Param::outputResidFile()
759{
760  /**
761   *  outputResidFile()
762   *
763   *   This function produces the required filename in which to save
764   *    the reconstructed array. If the input image is image.fits, then
765   *    the output will be eg. image.RESID-3-2-4-1.fits, where the numbers are
766   *    3=reconDim, 2=filterCode, 4=snrRecon, 1=scaleMin
767   */
768  string inputName = this->imageFile;
769  std::stringstream ss;
770  ss << inputName.substr(0,inputName.size()-5);  // remove the ".fits" on the end.
771  if(this->flagSubsection) ss<<".sub";
772  ss << ".RESID-" << this->reconDim
773     << "-"       << this->filterCode
774     << "-"       << this->snrRecon
775     << "-"       << this->scaleMin
776     << ".fits";
777  return ss.str();
778}
Note: See TracBrowser for help on using the repository browser.