1 | #include <iostream> |
---|
2 | #include <iomanip> |
---|
3 | #include <fstream> |
---|
4 | #include <vector> |
---|
5 | #include <param.hh> |
---|
6 | #include <PixelMap/Object3D.hh> |
---|
7 | #include <Cubes/cubes.hh> |
---|
8 | #include <Utils/utils.hh> |
---|
9 | #include <Utils/feedback.hh> |
---|
10 | #include <Utils/Statistics.hh> |
---|
11 | |
---|
12 | using std::vector; |
---|
13 | using namespace PixelInfo; |
---|
14 | |
---|
15 | void Cube::CubicSearch() |
---|
16 | { |
---|
17 | /** |
---|
18 | * A front end to the cubic searching routine that does not |
---|
19 | * involve any wavelet reconstruction. |
---|
20 | * The statistics of the cube are calculated first of all. |
---|
21 | * If baseline-removal is required that is done prior to searching. |
---|
22 | * Once searching is complete, the detection map is updated and |
---|
23 | * the intermediate detections are logged in the log file. |
---|
24 | */ |
---|
25 | |
---|
26 | if(this->par.isVerbose()) std::cout << " "; |
---|
27 | |
---|
28 | this->setCubeStats(); |
---|
29 | |
---|
30 | if(this->par.isVerbose()) std::cout << " Searching... " << std::flush; |
---|
31 | |
---|
32 | // this->objectList = search3DArray(this->axisDim,this->array, |
---|
33 | // this->par,this->Stats); |
---|
34 | this->objectList = search3DArraySimple(this->axisDim,this->array, |
---|
35 | this->par,this->Stats); |
---|
36 | |
---|
37 | if(this->par.isVerbose()) std::cout << " Updating detection map... " |
---|
38 | << std::flush; |
---|
39 | this->updateDetectMap(); |
---|
40 | if(this->par.isVerbose()) std::cout << "Done.\n"; |
---|
41 | |
---|
42 | if(this->par.getFlagLog()){ |
---|
43 | if(this->par.isVerbose()) |
---|
44 | std::cout << " Logging intermediate detections... " << std::flush; |
---|
45 | this->logDetectionList(); |
---|
46 | if(this->par.isVerbose()) std::cout << "Done.\n"; |
---|
47 | } |
---|
48 | |
---|
49 | } |
---|
50 | //--------------------------------------------------------------- |
---|
51 | |
---|
52 | |
---|
53 | vector <Detection> search3DArray(long *dim, float *Array, Param &par, |
---|
54 | StatsContainer<float> &stats) |
---|
55 | { |
---|
56 | /** |
---|
57 | * Takes a dimension array and data array as input (and Parameter set) |
---|
58 | * and searches for detections in a combination of 1D and 2D searches. |
---|
59 | * Returns a vector list of Detections. |
---|
60 | * No reconstruction is assumed to have taken place, so statistics are |
---|
61 | * calculated (using robust methods) from the data array itself. |
---|
62 | * \param dim Array of dimension sizes for the data array. |
---|
63 | * \param Array Array of data. |
---|
64 | * \param par Param set defining how to do detection, and what a |
---|
65 | * BLANK pixel is etc. |
---|
66 | * \param stats The statistics that define what a detection is. |
---|
67 | * \return Vector of detected objects. |
---|
68 | */ |
---|
69 | |
---|
70 | vector <Detection> outputList; |
---|
71 | long zdim = dim[2]; |
---|
72 | long xySize = dim[0] * dim[1]; |
---|
73 | int num = 0; |
---|
74 | |
---|
75 | ProgressBar bar; |
---|
76 | // FIRST SEARCH -- IN EACH SPECTRUM. |
---|
77 | if(zdim>1){ |
---|
78 | if(par.isVerbose()) { |
---|
79 | std::cout << " 1D: "; |
---|
80 | bar.init(xySize); |
---|
81 | } |
---|
82 | |
---|
83 | bool *doPixel = new bool[xySize]; |
---|
84 | int goodSize=0; |
---|
85 | for(int npix=0; npix<xySize; npix++){ |
---|
86 | doPixel[npix] = false; |
---|
87 | for(int z=0;z<zdim;z++){ |
---|
88 | doPixel[npix] = doPixel[npix] || |
---|
89 | (!par.isBlank(Array[npix]) && !par.isInMW(z)); |
---|
90 | } |
---|
91 | // doPixel[i] is false only when there are no good pixels in spectrum |
---|
92 | // of pixel #i. |
---|
93 | } |
---|
94 | |
---|
95 | long *specdim = new long[2]; |
---|
96 | specdim[0] = zdim; specdim[1]=1; |
---|
97 | Image *spectrum = new Image(specdim); |
---|
98 | delete [] specdim; |
---|
99 | spectrum->saveParam(par); |
---|
100 | spectrum->saveStats(stats); |
---|
101 | spectrum->setMinSize(par.getMinChannels()); |
---|
102 | spectrum->pars().setBeamSize(2.); |
---|
103 | // beam size: for spectrum, only neighbouring channels correlated |
---|
104 | |
---|
105 | for(int y=0; y<dim[1]; y++){ |
---|
106 | for(int x=0; x<dim[0]; x++){ |
---|
107 | |
---|
108 | int npix = y*dim[0] + x; |
---|
109 | if( par.isVerbose() ) bar.update(npix+1); |
---|
110 | |
---|
111 | if(doPixel[npix]){ |
---|
112 | spectrum->extractSpectrum(Array,dim,npix); |
---|
113 | spectrum->removeMW(); // only works if flagMW is true |
---|
114 | std::vector<Scan> objlist = spectrum->spectrumDetect(); |
---|
115 | num += objlist.size(); |
---|
116 | for(int obj=0;obj<objlist.size();obj++){ |
---|
117 | Detection newObject; |
---|
118 | // Fix up coordinates of each pixel to match original array |
---|
119 | for(int z=objlist[obj].getX();z<=objlist[obj].getXmax();z++) { |
---|
120 | newObject.pixels().addPixel(x,y,z); |
---|
121 | } |
---|
122 | newObject.setOffsets(par); |
---|
123 | mergeIntoList(newObject,outputList,par); |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | delete spectrum; |
---|
130 | delete [] doPixel; |
---|
131 | |
---|
132 | if(par.isVerbose()) { |
---|
133 | bar.fillSpace("Found "); |
---|
134 | std::cout << num <<";" << std::flush; |
---|
135 | } |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | // SECOND SEARCH -- IN EACH CHANNEL |
---|
140 | if(par.isVerbose()){ |
---|
141 | std::cout << " 2D: "; |
---|
142 | bar.init(zdim); |
---|
143 | } |
---|
144 | |
---|
145 | num = 0; |
---|
146 | |
---|
147 | long *imdim = new long[2]; |
---|
148 | imdim[0] = dim[0]; imdim[1] = dim[1]; |
---|
149 | Image *channelImage = new Image(imdim); |
---|
150 | delete [] imdim; |
---|
151 | channelImage->saveParam(par); |
---|
152 | channelImage->saveStats(stats); |
---|
153 | // channelImage->setMinSize(par.getMinPix()); |
---|
154 | channelImage->setMinSize(1); |
---|
155 | |
---|
156 | for(int z=0; z<zdim; z++){ |
---|
157 | |
---|
158 | if( par.isVerbose() ) bar.update(z+1); |
---|
159 | |
---|
160 | if(!par.isInMW(z)){ |
---|
161 | |
---|
162 | channelImage->extractImage(Array,dim,z); |
---|
163 | std::vector<Object2D> objlist = channelImage->lutz_detect(); |
---|
164 | num += objlist.size(); |
---|
165 | for(int obj=0;obj<objlist.size();obj++){ |
---|
166 | Detection newObject; |
---|
167 | newObject.pixels().addChannel(z,objlist[obj]); |
---|
168 | newObject.setOffsets(par); |
---|
169 | mergeIntoList(newObject,outputList,par); |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | } |
---|
174 | |
---|
175 | delete channelImage; |
---|
176 | |
---|
177 | if(par.isVerbose()){ |
---|
178 | bar.fillSpace("Found "); |
---|
179 | std::cout << num << ".\n"; |
---|
180 | } |
---|
181 | |
---|
182 | return outputList; |
---|
183 | } |
---|
184 | //--------------------------------------------------------------- |
---|
185 | |
---|
186 | vector <Detection> search3DArraySimple(long *dim, float *Array, Param &par, |
---|
187 | StatsContainer<float> &stats) |
---|
188 | { |
---|
189 | /** |
---|
190 | * Takes a dimension array and data array as input (and Parameter |
---|
191 | * set) and searches for detections just in the channel maps -- no |
---|
192 | * 1D searches are done. * Returns a vector list of Detections. |
---|
193 | * No reconstruction is assumed to have taken place, so statistics |
---|
194 | * are calculated (using robust methods) from the data array |
---|
195 | * itself. |
---|
196 | * \param dim Array of dimension sizes for the data array. |
---|
197 | * \param Array Array of data. |
---|
198 | * \param par Param set defining how to do detection, and what a |
---|
199 | * BLANK pixel is etc. |
---|
200 | * \param stats The statistics that define what a detection is. |
---|
201 | * \return Vector of detected objects. |
---|
202 | */ |
---|
203 | |
---|
204 | vector <Detection> outputList; |
---|
205 | long zdim = dim[2]; |
---|
206 | long xySize = dim[0] * dim[1]; |
---|
207 | int num = 0; |
---|
208 | |
---|
209 | ProgressBar bar; |
---|
210 | if(par.isVerbose()) bar.init(zdim); |
---|
211 | |
---|
212 | num = 0; |
---|
213 | |
---|
214 | long *imdim = new long[2]; |
---|
215 | imdim[0] = dim[0]; imdim[1] = dim[1]; |
---|
216 | Image *channelImage = new Image(imdim); |
---|
217 | delete [] imdim; |
---|
218 | channelImage->saveParam(par); |
---|
219 | channelImage->saveStats(stats); |
---|
220 | channelImage->setMinSize(1); |
---|
221 | |
---|
222 | for(int z=0; z<zdim; z++){ |
---|
223 | |
---|
224 | if( par.isVerbose() ) bar.update(z+1); |
---|
225 | |
---|
226 | if(!par.isInMW(z)){ |
---|
227 | |
---|
228 | channelImage->extractImage(Array,dim,z); |
---|
229 | std::vector<Object2D> objlist = channelImage->lutz_detect(); |
---|
230 | num += objlist.size(); |
---|
231 | for(int obj=0;obj<objlist.size();obj++){ |
---|
232 | Detection newObject; |
---|
233 | newObject.pixels().addChannel(z,objlist[obj]); |
---|
234 | newObject.setOffsets(par); |
---|
235 | mergeIntoList(newObject,outputList,par); |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | } |
---|
240 | |
---|
241 | delete channelImage; |
---|
242 | |
---|
243 | if(par.isVerbose()){ |
---|
244 | bar.fillSpace("Found "); |
---|
245 | std::cout << num << ".\n"; |
---|
246 | } |
---|
247 | |
---|
248 | return outputList; |
---|
249 | } |
---|
250 | |
---|
251 | |
---|