source: trunk/src/param.cc @ 117

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

Some bugfixes, and improved image/spectrum extraction routines:
Corrected bug that meant blank pixels weren't being seen by the
drawMomentMap function. Improved the blankpixel testing in that
function, and changed getImage so that the blank pixel info is
always stored (if it is in the fits header).
Added new functions to Image class that can read a spectrum or
channel map given a cube and a channel/pixel number.
Other minor corrections as well:
src/Utils/cpgcumul.c -- changed way _swap is declared (pointers
rather than references, which don't work in C)
src/Cubes/cubes.cc -- new extraction functions
src/Cubes/cubes.hh -- prototypes thereof
src/Cubes/drawMomentCutout.cc -- improved blank pixel handling
src/Cubes/getImage.cc -- made sure blank pixel info is always
read in.
src/param.cc -- tidied up code slightly.
src/Detection/thresholding_functions.cc -- corrected setupFDR
to remove potential for accessing outside allocated memory.

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