source: branches/fitshead-branch/param.cc @ 1377

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

Four major sets of changes and a couple of minor ones:

  • Changed name of saved recon/resid FITS file, so that it incorporates all reconstruction parameters.
  • Removed MW parameters from header file
  • Added hashed box to be drawn over MW range in spectral plots
  • Fixed bug that meant reon would be done in 1- or 2-d even if recon array has been read in.

Summary:
param.hh -- prototypes for FITS file name calculation functions
param.cc -- FITS file name calculation functions
Cubes/plots.hh -- drawMWRange function
ATrous/ReconSearch.cc -- tests to see if reconExists for 1- and 2-D recon
Cubes/cubes.cc -- work out enclosed flux correctly for flagNegative
Cubes/detectionIO.cc -- added reconDim line to VOTable output
Cubes/outputSpectra.cc -- added code to draw MW range
Cubes/readRecon.cc -- added call to FITS file name function, and removed

MW params and superfluous tests on atrous parameters

Cubes/saveImage.cc -- improved logical flow. added call to FITS file name func

removed MW keywords.

Detection/columns.cc -- added extra column to fluxes if negative.

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