source: tags/release-0.9/param.cc @ 813

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

param.cc Made sure the velocity threshold is always

printed when parameters are outputted.

Detection/detection.cc Corrected determination of object name -- was

in the wrong place.

Detection/outputDetection.cc Added space so that F_peak is separated

from F_int.

File size: 13.4 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <string>
6#include <math.h>
7#include <param.hh>
8
9using std::setw;
10using std::endl;
11
12/****************************************************************/
13///////////////////////////////////////////////////
14//// Accessor Functions for Parameter class:
15///////////////////////////////////////////////////
16Param::Param(){
17  /**
18   * Param()
19   *  Default intial values for the parameters.
20   * imageFile has no default value!
21   */
22  // Input files
23  this->imageFile       = "";
24  this->flagSubsection  = false;
25  this->subsection      = "[*,*,*]";
26  // Output files
27  this->flagLog         = true;
28  this->logFile         = "./duchamp-Logfile";
29  this->outFile         = "./duchamp-Results";
30  this->spectraFile     = "./duchamp-Spectra.ps";
31  this->flagOutputRecon = false;
32  this->flagOutputResid = false;
33  this->flagVOT         = false;
34  this->votFile         = "./duchamp-Results.xml";
35  this->flagKarma       = false;
36  this->karmaFile       = "./duchamp-Results.ann";
37  this->flagMaps        = true;
38  this->detectionMap    = "./latest-detection-map.ps";
39  this->momentMap       = "./latest-moment-map.ps";
40  // Cube related parameters
41  this->flagBlankPix    = true;
42  this->blankPixValue   = -8.00061;
43  this->blankKeyword    = 1;
44  this->bscaleKeyword   = -8.00061;
45  this->bzeroKeyword    = 0.;
46  this->nanAsBlank      = false;
47  this->flagMW          = true;
48  this->maxMW           = 112;
49  this->minMW           = 75;
50  this->numPixBeam      = 0.;
51  // Trim-related         
52  this->flagTrimmed     = false;
53  this->borderLeft      = 0;
54  this->borderRight     = 0;
55  this->borderBottom    = 0;
56  this->borderTop       = 0;
57  // Subsection offsets
58  this->xSubOffset      = 0;
59  this->ySubOffset      = 0;
60  this->zSubOffset      = 0;
61  // Baseline related
62  this->flagBaseline    = false;
63  // Detection-related   
64  this->minPix          = 2;
65  // Object growth       
66  this->flagGrowth      = true;
67  this->growthCut       = 1.5;
68  // FDR analysis         
69  this->flagFDR         = false;
70  this->alphaFDR        = 0.01;
71  // Other detection     
72  this->snrCut          = 3.;
73  // A trous reconstruction parameters
74  this->flagATrous      = true;
75  this->scaleMin        = 1;
76  this->snrRecon        = 4.;
77  this->filterCode      = 2;
78  // Volume-merging parameters
79  this->flagAdjacent    = true;
80  this->threshSpatial   = 3.;
81  this->threshVelocity  = 7.;
82  this->minChannels     = 3;
83  // Input-Output related
84  this->borders         = true;
85  this->verbose         = true;
86};
87
88/****************************************************************/
89///////////////////////////////////////////////////
90//// Other Functions using the  Parameter class:
91///////////////////////////////////////////////////
92
93string makelower( string s )
94{
95  // "borrowed" from Matt Howlett's 'fred'
96  string out = "";
97  for( int i=0; i<s.size(); ++i ) {
98    out += tolower(s[i]);
99  }
100  return out;
101}
102
103void Param::readParams(string &paramfile)
104{
105
106  std::ifstream fin(paramfile.c_str());
107  string line;
108  string sval;
109  float fval;
110  int ival;
111  bool bval;
112  while( !std::getline(fin,line,'\n').eof()){
113
114    if(line[0]!='#'){
115      std::stringstream ss;
116      ss.str(line);
117      string arg;
118      ss >> arg;     
119      if(makelower(arg)=="imagefile"){       ss >> sval; this->imageFile = sval;}
120      if(makelower(arg)=="flaglog"){         ss >> bval; this->flagLog = bval; }
121      if(makelower(arg)=="logfile"){         ss >> sval; this->logFile = sval; }
122      if(makelower(arg)=="outfile"){         ss >> sval; this->outFile = sval; }
123      if(makelower(arg)=="spectrafile"){     ss >> sval; this->spectraFile = sval; }
124      if(makelower(arg)=="flagoutputrecon"){ ss >> bval; this->flagOutputRecon = bval; }
125      if(makelower(arg)=="flagoutputresid"){ ss >> bval; this->flagOutputResid = bval; }
126      if(makelower(arg)=="flagvot"){         ss >> bval; this->flagVOT = bval; }
127      if(makelower(arg)=="votfile"){         ss >> sval; this->votFile = sval; }
128      if(makelower(arg)=="flagkarma"){       ss >> bval; this->flagKarma = bval; }
129      if(makelower(arg)=="karmafile"){       ss >> sval; this->karmaFile = sval; }
130      if(makelower(arg)=="flagmaps"){        ss >> bval; this->flagMaps = bval; }
131      if(makelower(arg)=="detectionmap"){    ss >> sval; this->detectionMap = sval; }
132      if(makelower(arg)=="momentmap"){       ss >> sval; this->momentMap = sval; }
133
134      if(makelower(arg)=="flagblankpix"){    ss >> bval; this->flagBlankPix = bval; }
135      if(makelower(arg)=="blankpixvalue"){   ss >> fval; this->blankPixValue = fval; }
136      if(makelower(arg)=="flagmw"){          ss >> bval; this->flagMW = bval; }
137      if(makelower(arg)=="maxmw"){           ss >> ival; this->maxMW = ival; }
138      if(makelower(arg)=="minmw"){           ss >> ival; this->minMW = ival; }
139      if(makelower(arg)=="minpix"){          ss >> ival; this->minPix = ival; }
140      if(makelower(arg)=="flagfdr"){         ss >> bval; this->flagFDR = bval; }
141      if(makelower(arg)=="alphafdr"){        ss >> fval; this->alphaFDR = fval; }
142      if(makelower(arg)=="flagbaseline"){    ss >> bval; this->flagBaseline = bval; }
143      if(makelower(arg)=="snrcut"){          ss >> fval; this->snrCut = fval; }
144      if(makelower(arg)=="flaggrowth"){      ss >> bval; this->flagGrowth = bval; }
145      if(makelower(arg)=="growthcut"){       ss >> fval; this->growthCut = fval; }
146      if(makelower(arg)=="flagatrous"){      ss >> bval; this->flagATrous = bval; }
147      if(makelower(arg)=="scalemin"){        ss >> ival; this->scaleMin = ival; }
148      if(makelower(arg)=="snrrecon"){        ss >> fval; this->snrRecon = fval; }
149      if(makelower(arg)=="filtercode"){      ss >> ival; this->filterCode = ival; }
150      if(makelower(arg)=="flagadjacent"){    ss >> bval; this->flagAdjacent = bval; }
151      if(makelower(arg)=="threshspatial"){   ss >> fval; this->threshSpatial = fval; }
152      if(makelower(arg)=="threshvelocity"){  ss >> fval; this->threshVelocity = fval; }
153      if(makelower(arg)=="minchannels"){     ss >> ival; this->minChannels = ival; }
154      if(makelower(arg)=="flagsubsection"){  ss >> bval; this->flagSubsection = bval; }
155      if(makelower(arg)=="subsection"){      ss >> sval; this->subsection = sval; }
156      if(makelower(arg)=="drawborders"){     ss >> bval; this->borders = bval; }
157      if(makelower(arg)=="verbose"){         ss >> bval; this->verbose = bval; }
158    }
159  }
160}
161
162
163std::ostream& operator<< ( std::ostream& theStream, Param& par)
164{
165  theStream.setf(std::ios::boolalpha);
166  theStream.setf(std::ios::left);
167  theStream  <<"---- Parameters ----"<<endl;
168  if(par.getFlagSubsection())
169    theStream<<setw(40)<<"Image to be analysed"                 <<"= "<<(par.getImageFile()+
170                                                                         par.getSubsection())   <<endl;
171  else
172    theStream<<setw(40)<<"Image to be analysed"                 <<"= "<<par.getImageFile()      <<endl;
173  theStream  <<setw(40)<<"Intermediate Logfile"                 <<"= "<<par.getLogFile()        <<endl;
174  theStream  <<setw(40)<<"Final Results file"                   <<"= "<<par.getOutFile()        <<endl;
175  theStream  <<setw(40)<<"Spectrum file"                        <<"= "<<par.getSpectraFile()    <<endl;
176  if(par.getFlagVOT()){
177    theStream<<setw(40)<<"VOTable file"                         <<"= "<<par.getVOTFile()        <<endl;
178  }
179  if(par.getFlagKarma()){
180    theStream<<setw(40)<<"Karma annotation file"                <<"= "<<par.getKarmaFile()      <<endl;
181  }
182  if(par.getFlagMaps()){
183    theStream<<setw(40)<<"0th Moment Map"                       <<"= "<<par.getMomentMap()      <<endl;
184    theStream<<setw(40)<<"Detection Map"                        <<"= "<<par.getDetectionMap()   <<endl;
185  }
186  if(par.getFlagATrous()){                             
187    theStream<<setw(40)<<"Saving reconstructed cube?"           <<"= "<<par.getFlagOutputRecon()<<endl;
188    theStream<<setw(40)<<"Saving residuals from reconstruction?"<<"= "<<par.getFlagOutputResid()<<endl;
189  }                                                   
190  theStream  <<"------"<<endl;                                 
191  theStream  <<setw(40)<<"Fixing Blank Pixels?"                 <<"= "<<par.getFlagBlankPix()   <<endl;
192  if(par.getFlagBlankPix()){
193    theStream<<setw(40)<<"Blank Pixel Value"                    <<"= "<<par.getBlankPixVal()    <<endl;
194  }
195  theStream  <<setw(40)<<"Removing Milky Way channels?"         <<"= "<<par.getFlagMW()         <<endl;
196  if(par.getFlagMW()){
197    theStream<<setw(40)<<"Milky Way Channels"                   <<"= "<<par.getMinMW()
198                       <<"-"                                          <<par.getMaxMW()          <<endl;
199  }
200  theStream  <<setw(40)<<"Beam Size (pixels)"                   <<"= "<<par.getBeamSize()       <<endl;
201  theStream  <<setw(40)<<"Removing baselines before search?"    <<"= "<<par.getFlagBaseline()   <<endl;
202  theStream  <<setw(40)<<"Minimum # Pixels in a detection"      <<"= "<<par.getMinPix()         <<endl;
203  theStream  <<setw(40)<<"Growing objects after detection?"     <<"= "<<par.getFlagGrowth()     <<endl;
204  if(par.getFlagGrowth()) {                           
205    theStream<<setw(40)<<"SNR Threshold for growth"             <<"= "<<par.getGrowthCut()      <<endl;
206  }
207  theStream  <<setw(40)<<"Using A Trous reconstruction?"        <<"= "<<par.getFlagATrous()     <<endl;
208  if(par.getFlagATrous()){                             
209    theStream<<setw(40)<<"Minimum scale in reconstruction"      <<"= "<<par.getMinScale()       <<endl;
210    theStream<<setw(40)<<"SNR Threshold within reconstruction"  <<"= "<<par.getAtrousCut()      <<endl;
211    theStream<<setw(40)<<"Filter being used for reconstruction" <<"= "<<par.getFilterName()     <<endl;
212  }                                                   
213  theStream  <<setw(40)<<"Using FDR analysis?"                  <<"= "<<par.getFlagFDR()        <<endl;
214  if(par.getFlagFDR()){                               
215    theStream<<setw(40)<<"Alpha value for FDR analysis"         <<"= "<<par.getAlpha()          <<endl;
216  }                                                   
217  else {
218    theStream<<setw(40)<<"SNR Threshold"                        <<"= "<<par.getCut()            <<endl;
219  }
220  theStream  <<setw(40)<<"Using Adjacent-pixel criterion?"      <<"= "<<par.getFlagAdjacent()   <<endl;
221  if(!par.getFlagAdjacent()){
222    theStream<<setw(40)<<"Max. spatial separation for merging"  <<"= "<<par.getThreshS()        <<endl;
223  }
224  theStream  <<setw(40)<<"Max. velocity separation for merging" <<"= "<<par.getThreshV()        <<endl;
225  theStream  <<setw(40)<<"Min. # channels for merging"          <<"= "<<par.getMinChannels()    <<endl;
226  theStream  <<"--------------------"<<endl;
227  theStream.unsetf(std::ios::left);
228  theStream.unsetf(std::ios::boolalpha);
229}
230
231void Param::parseSubsection()
232{
233  std::stringstream ss;
234  ss.str(this->subsection);
235  bool removeStep = false;
236  string x,y,z;
237  getline(ss,x,'[');
238  getline(ss,x,',');
239  getline(ss,y,',');
240  getline(ss,z,']');
241  char *end;
242  if(x!="*") {
243    int x1,x2,dx;
244    int a = x.find(':');  // first occurence of ':' in x-subsection string
245    int b = x.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence.
246    x1 = atoi( x.substr(0,a).c_str() ); // minimum x in subsection
247    this->xSubOffset = x1 - 1;
248    if(b>0){ // there is a dx component
249      x2 = atoi( x.substr(a+1,b-a-1).c_str() ); // maximum x in subsection
250      dx = atoi( x.substr(b+1,x.size()).c_str() ); // delta x in subsection
251      x = x.substr(0,b); // rewrite x without the delta-x part.
252      removeStep = true;
253    }
254  }
255  if(y!="*") {
256    int y1,y2,dy;
257    int a = y.find(':');  // first occurence of ':' in y-subsection string
258    int b = y.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence.
259    y1 = atoi( y.substr(0,a).c_str() ); // minimum y in subsection
260    this->ySubOffset = y1 - 1;
261    if(b>0){ // there is a dy component
262      y2 = atoi( y.substr(a+1,b-a-1).c_str() ); // maximum y in subsection
263      dy = atoi( y.substr(b+1,y.size()).c_str() ); // delta y in subsection
264      y = y.substr(0,b); // rewrite y without the delta-y part.
265      removeStep = true;
266    }
267  }
268  if(z!="*") {
269    int z1,z2,dz;
270    int a = z.find(':');  // first occurence of ':' in z-subsection string
271    int b = z.find(':',a+1); // location of second ':' -- will be -1 if there is no second occurence.
272    z1 = atoi( z.substr(0,a).c_str() ); // minimum z in subsection
273    this->zSubOffset = z1 - 1;
274    if(b>0){ // there is a dz component
275      z2 = atoi( z.substr(a+1,b-a-1).c_str() ); // maximum z in subsection
276      dz = atoi( z.substr(b+1,z.size()).c_str() ); // delta z in subsection
277      z = z.substr(0,b); // rewrite z without the delta-z part.
278      removeStep = true;
279    }
280  }
281
282  if(removeStep){
283    std::cerr << "\a\tThe subsection given is " << this->subsection <<".\n";
284    std::cerr << "\tDuchamp is currently unable to deal with pixel steps in the subsection.\n";
285    std::cerr << "\tThese have been ignored, and so the subection used is ";   
286    this->subsection = "[" + x + "," + y + "," + z + "]";  // rewrite subsection without any step sizes.
287    std::cerr << this->subsection << std::endl;
288  }
289 
290//   if(x!="*") this->xSubOffset = strtol(x.c_str(),&end,10) - 1;   
291//   if(y!="*") this->ySubOffset = strtol(y.c_str(),&end,10) - 1;   
292//   if(z!="*") this->zSubOffset = strtol(z.c_str(),&end,10) - 1;   
293}
294
295bool Param::isBlank(float &val)
296{
297//   std::cerr << "val = " << val << " " << int((val-this->bzeroKeyword)/this->bscaleKeyword)
298//          <<" " <<this->blankKeyword << std::endl;
299  if(this->flagBlankPix){
300    if(this->nanAsBlank) return bool(isnan(val));
301    else//  return (val == this->blankPixValue);
302      return ( this->blankKeyword == int((val-this->bzeroKeyword)/this->bscaleKeyword) );
303  }
304  else return false;
305}
Note: See TracBrowser for help on using the repository browser.