1 | #include <iostream> |
---|
2 | #include <iomanip> |
---|
3 | #include <fstream> |
---|
4 | #include <string> |
---|
5 | #include <Cubes/cubes.hh> |
---|
6 | |
---|
7 | string makelower( string s ) |
---|
8 | { |
---|
9 | // "borrowed" from Matt Howlett's 'fred' |
---|
10 | string out = ""; |
---|
11 | for( int i=0; i<s.size(); ++i ) { |
---|
12 | out += tolower(s[i]); |
---|
13 | } |
---|
14 | return out; |
---|
15 | } |
---|
16 | |
---|
17 | void readParams(string paramfile, Param &par) |
---|
18 | { |
---|
19 | |
---|
20 | ifstream fin(paramfile.c_str()); |
---|
21 | string input; |
---|
22 | string sval; |
---|
23 | float fval; |
---|
24 | int ival; |
---|
25 | bool bval; |
---|
26 | while( fin >> input){ |
---|
27 | |
---|
28 | if(input[0]!='#'){ |
---|
29 | if(makelower(input)=="nullpixvalue"){ fin >> fval; par.setNullPixVal(fval); } |
---|
30 | if(makelower(input)=="flagnullpix"){ fin >> bval; par.setFlagNullPix(bval); } |
---|
31 | if(makelower(input)=="flagmw"){ fin >> bval; par.setFlagMW(bval); } |
---|
32 | if(makelower(input)=="maxmw"){ fin >> ival; par.setMaxMW(ival); } |
---|
33 | if(makelower(input)=="minmw"){ fin >> ival; par.setMinMW(ival); } |
---|
34 | if(makelower(input)=="minpix"){ fin >> ival; par.setMinPix(ival); } |
---|
35 | if(makelower(input)=="flagfdr"){ fin >> bval; par.setFlagFDR(bval); } |
---|
36 | if(makelower(input)=="alphafdr"){ fin >> fval; par.setAlpha(fval); } |
---|
37 | if(makelower(input)=="numpixpsf"){ fin >> ival; par.setSizePSF(ival); } |
---|
38 | if(makelower(input)=="snrcut"){ fin >> fval; par.setCut(fval); } |
---|
39 | if(makelower(input)=="flaggrowth"){ fin >> bval; par.setFlagGrowth(bval); } |
---|
40 | if(makelower(input)=="growthcut"){ fin >> fval; par.setGrowthCut(fval); } |
---|
41 | if(makelower(input)=="flagatrous"){ fin >> bval; par.setFlagATrous(bval); } |
---|
42 | if(makelower(input)=="scalemin"){ fin >> ival; par.setMinScale(ival); } |
---|
43 | if(makelower(input)=="snrrecon"){ fin >> fval; par.setAtrousCut(fval); } |
---|
44 | if(makelower(input)=="flagadjacent"){ fin >> bval; par.setFlagAdjacent(bval); } |
---|
45 | if(makelower(input)=="threshspatial"){ fin >> fval; par.setThreshS(fval); } |
---|
46 | if(makelower(input)=="threshvelocity"){ fin >> fval; par.setThreshV(fval); } |
---|
47 | if(makelower(input)=="minchannels"){ fin >> ival; par.setMinChannels(ival); } |
---|
48 | if(makelower(input)=="flaglog"){ fin >> bval; par.setFlagLog(bval); } |
---|
49 | if(makelower(input)=="logfile"){ fin >> sval; par.setLogFile(sval); } |
---|
50 | if(makelower(input)=="outfile"){ fin >> sval; par.setOutFile(sval); } |
---|
51 | if(makelower(input)=="spectrafile"){ fin >> sval; par.setSpectraFile(sval); } |
---|
52 | if(makelower(input)=="imagefile"){ fin >> sval; par.setImageFile(sval); } |
---|
53 | if(makelower(input)=="flagsubsection"){ fin >> bval; par.setFlagSubsection(bval); } |
---|
54 | if(makelower(input)=="subsection"){ fin >> sval; par.setSubsection(sval); } |
---|
55 | if(makelower(input)=="flagoutputrecon"){ fin >> bval; par.setFlagOutputRecon(bval); } |
---|
56 | if(makelower(input)=="flagoutputresid"){ fin >> bval; par.setFlagOutputResid(bval); } |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | void showParams(Param &par) |
---|
63 | { |
---|
64 | cerr.setf(ios::boolalpha); |
---|
65 | cerr<<"---- Parameters ---"<<endl; |
---|
66 | if(par.getFlagSubsection()) |
---|
67 | cerr<<"Image to be analysed\t\t\t= " <<(par.getImageFile()+ |
---|
68 | par.getSubsection()) <<endl; |
---|
69 | else |
---|
70 | cerr<<"Image to be analysed\t\t\t= " <<par.getImageFile() <<endl; |
---|
71 | cerr<<"Intermediate Logfile\t\t\t= " <<par.getLogFile() <<endl; |
---|
72 | cerr<<"Final Results file\t\t\t= " <<par.getOutFile() <<endl; |
---|
73 | cerr<<"Spectrum file\t\t\t\t= " <<par.getSpectraFile() <<endl; |
---|
74 | if(par.getFlagATrous()){ |
---|
75 | cerr<<"Saving reconstructed cube?\t\t= " <<par.getFlagOutputRecon() <<endl; |
---|
76 | cerr<<"Saving residuals from reconstruction?\t= " <<par.getFlagOutputResid() <<endl; |
---|
77 | } |
---|
78 | cerr<<"-----"<<endl; |
---|
79 | cerr<<"Fixing Null Pixels?\t\t\t= " <<par.getFlagNullPix() <<endl; |
---|
80 | cerr<<"Null Pixel Value\t\t\t= " <<par.getNullPixVal() <<endl; |
---|
81 | cerr<<"Removing Milky Way channels?\t\t= " <<par.getFlagMW() <<endl; |
---|
82 | cerr<<"Milky Way Channels\t\t\t= " <<par.getMinMW() |
---|
83 | <<"-" <<par.getMaxMW() <<endl; |
---|
84 | cerr<<"Minimum # Pixels in a detection\t\t= " <<par.getMinPix() <<endl; |
---|
85 | cerr<<"Growing objects after detection?\t= " <<par.getFlagGrowth() <<endl; |
---|
86 | if(par.getFlagGrowth()) |
---|
87 | cerr<<"SNR Threshold for growth\t\t= " <<par.getGrowthCut() <<endl; |
---|
88 | cerr<<"Using A Trous reconstruction?\t\t= " <<par.getFlagATrous() <<endl; |
---|
89 | if(par.getFlagATrous()){ |
---|
90 | cerr<<"Minimum scale in reconstruction\t\t= " <<par.getMinScale() <<endl; |
---|
91 | cerr<<"SNR Threshold within reconstruction\t= " <<par.getAtrousCut() <<endl; |
---|
92 | } |
---|
93 | cerr<<"Using FDR analysis?\t\t\t= " <<par.getFlagFDR() <<endl; |
---|
94 | if(par.getFlagFDR()){ |
---|
95 | cerr<<"Alpha value for FDR analysis\t\t= " <<par.getAlpha() <<endl; |
---|
96 | cerr<<"Number of pixels in PSF (used by FDR)\t= " <<par.getSizePSF() <<endl; |
---|
97 | } |
---|
98 | else cerr<<"SNR Threshold\t\t\t\t= " <<par.getCut() <<endl; |
---|
99 | cerr<<"Using Adjacent-pixel criterion?\t\t= " <<par.getFlagAdjacent() <<endl; |
---|
100 | if(!par.getFlagAdjacent()){ |
---|
101 | cerr<<"Max. spatial separation for merging\t= " <<par.getThreshS() <<endl; |
---|
102 | cerr<<"Max. velocity separation for merging\t= " <<par.getThreshV() <<endl; |
---|
103 | } |
---|
104 | cerr<<"Min. # channels for merging\t\t= " <<par.getMinChannels() <<endl; |
---|
105 | cerr<<"-------------------"<<endl; |
---|
106 | cerr.unsetf(ios::boolalpha); |
---|
107 | } |
---|
108 | |
---|
109 | void showParams(Param &par, std::ostream &stream) |
---|
110 | { |
---|
111 | stream.setf(ios::boolalpha); |
---|
112 | stream<<"---- Parameters ---"<<endl; |
---|
113 | if(par.getFlagSubsection()) |
---|
114 | stream<<"Image to be analysed\t\t\t= " <<(par.getImageFile()+ |
---|
115 | par.getSubsection()) <<endl; |
---|
116 | else |
---|
117 | stream<<"Image to be analysed\t\t\t= " <<par.getImageFile() <<endl; |
---|
118 | stream<<"Intermediate Logfile\t\t\t= " <<par.getLogFile() <<endl; |
---|
119 | stream<<"Final Results file\t\t\t= " <<par.getOutFile() <<endl; |
---|
120 | stream<<"Spectrum file\t\t\t\t= " <<par.getSpectraFile() <<endl; |
---|
121 | if(par.getFlagATrous()){ |
---|
122 | stream<<"Saving reconstructed cube?\t\t= " <<par.getFlagOutputRecon() <<endl; |
---|
123 | stream<<"Saving residuals from reconstruction?\t= " <<par.getFlagOutputResid() <<endl; |
---|
124 | } |
---|
125 | stream<<"-----"<<endl; |
---|
126 | stream<<"Fixing Null Pixels?\t\t\t= " <<par.getFlagNullPix() <<endl; |
---|
127 | stream<<"Null Pixel Value\t\t\t= " <<par.getNullPixVal() <<endl; |
---|
128 | stream<<"Removing Milky Way channels?\t\t= " <<par.getFlagMW() <<endl; |
---|
129 | stream<<"Milky Way Channels\t\t\t= " <<par.getMinMW() |
---|
130 | <<"-" <<par.getMaxMW() <<endl; |
---|
131 | stream<<"Minimum # Pixels in a detection\t\t= " <<par.getMinPix() <<endl; |
---|
132 | stream<<"Growing objects after detection?\t= " <<par.getFlagGrowth() <<endl; |
---|
133 | if(par.getFlagGrowth()) |
---|
134 | stream<<"SNR Threshold for growth\t\t= " <<par.getGrowthCut() <<endl; |
---|
135 | stream<<"Using A Trous reconstruction?\t\t= " <<par.getFlagATrous() <<endl; |
---|
136 | if(par.getFlagATrous()){ |
---|
137 | stream<<"Minimum scale in reconstruction\t\t= " <<par.getMinScale() <<endl; |
---|
138 | stream<<"SNR Threshold within reconstruction\t= " <<par.getAtrousCut() <<endl; |
---|
139 | } |
---|
140 | stream<<"Using FDR analysis?\t\t\t= " <<par.getFlagFDR() <<endl; |
---|
141 | if(par.getFlagFDR()){ |
---|
142 | stream<<"Alpha value for FDR analysis\t\t= " <<par.getAlpha() <<endl; |
---|
143 | stream<<"Number of pixels in PSF (used by FDR)\t= " <<par.getSizePSF() <<endl; |
---|
144 | } |
---|
145 | else stream<<"SNR Threshold\t\t\t\t= " <<par.getCut() <<endl; |
---|
146 | stream<<"Using Adjacent-pixel criterion?\t\t= " <<par.getFlagAdjacent() <<endl; |
---|
147 | if(!par.getFlagAdjacent()){ |
---|
148 | stream<<"Max. spatial separation for merging\t= " <<par.getThreshS() <<endl; |
---|
149 | stream<<"Max. velocity separation for merging\t= " <<par.getThreshV() <<endl; |
---|
150 | } |
---|
151 | stream<<"Min. # channels for merging\t\t= " <<par.getMinChannels() <<endl; |
---|
152 | stream<<"-------------------"<<endl; |
---|
153 | stream.unsetf(ios::boolalpha); |
---|
154 | } |
---|
155 | |
---|
156 | std::ostream& operator<< ( std::ostream& theStream, Param& par) |
---|
157 | { |
---|
158 | theStream.setf(ios::boolalpha); |
---|
159 | theStream<<"---- Parameters ---"<<endl; |
---|
160 | if(par.getFlagSubsection()) |
---|
161 | theStream<<"Image to be analysed\t\t\t= " <<(par.getImageFile()+ |
---|
162 | par.getSubsection()) <<endl; |
---|
163 | else |
---|
164 | theStream<<"Image to be analysed\t\t\t= " <<par.getImageFile() <<endl; |
---|
165 | theStream<<"Intermediate Logfile\t\t\t= " <<par.getLogFile() <<endl; |
---|
166 | theStream<<"Final Results file\t\t\t= " <<par.getOutFile() <<endl; |
---|
167 | theStream<<"Spectrum file\t\t\t\t= " <<par.getSpectraFile() <<endl; |
---|
168 | if(par.getFlagATrous()){ |
---|
169 | theStream<<"Saving reconstructed cube?\t\t= " <<par.getFlagOutputRecon() <<endl; |
---|
170 | theStream<<"Saving residuals from reconstruction?\t= " <<par.getFlagOutputResid() <<endl; |
---|
171 | } |
---|
172 | theStream<<"-----"<<endl; |
---|
173 | theStream<<"Fixing Null Pixels?\t\t\t= " <<par.getFlagNullPix() <<endl; |
---|
174 | theStream<<"Null Pixel Value\t\t\t= " <<par.getNullPixVal() <<endl; |
---|
175 | theStream<<"Removing Milky Way channels?\t\t= " <<par.getFlagMW() <<endl; |
---|
176 | theStream<<"Milky Way Channels\t\t\t= " <<par.getMinMW() |
---|
177 | <<"-" <<par.getMaxMW() <<endl; |
---|
178 | theStream<<"Minimum # Pixels in a detection\t\t= " <<par.getMinPix() <<endl; |
---|
179 | theStream<<"Growing objects after detection?\t= " <<par.getFlagGrowth() <<endl; |
---|
180 | if(par.getFlagGrowth()) |
---|
181 | theStream<<"SNR Threshold for growth\t\t= " <<par.getGrowthCut() <<endl; |
---|
182 | theStream<<"Using A Trous reconstruction?\t\t= " <<par.getFlagATrous() <<endl; |
---|
183 | if(par.getFlagATrous()){ |
---|
184 | theStream<<"Minimum scale in reconstruction\t\t= " <<par.getMinScale() <<endl; |
---|
185 | theStream<<"SNR Threshold within reconstruction\t= " <<par.getAtrousCut() <<endl; |
---|
186 | } |
---|
187 | theStream<<"Using FDR analysis?\t\t\t= " <<par.getFlagFDR() <<endl; |
---|
188 | if(par.getFlagFDR()){ |
---|
189 | theStream<<"Alpha value for FDR analysis\t\t= " <<par.getAlpha() <<endl; |
---|
190 | theStream<<"Number of pixels in PSF (used by FDR)\t= " <<par.getSizePSF() <<endl; |
---|
191 | } |
---|
192 | else theStream<<"SNR Threshold\t\t\t\t= " <<par.getCut() <<endl; |
---|
193 | theStream<<"Using Adjacent-pixel criterion?\t\t= " <<par.getFlagAdjacent() <<endl; |
---|
194 | if(!par.getFlagAdjacent()){ |
---|
195 | theStream<<"Max. spatial separation for merging\t= " <<par.getThreshS() <<endl; |
---|
196 | theStream<<"Max. velocity separation for merging\t= " <<par.getThreshV() <<endl; |
---|
197 | } |
---|
198 | theStream<<"Min. # channels for merging\t\t= " <<par.getMinChannels() <<endl; |
---|
199 | theStream<<"-------------------"<<endl; |
---|
200 | theStream.unsetf(ios::boolalpha); |
---|
201 | } |
---|
202 | |
---|