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 | |
---|
35 | if(this->par.isVerbose()) std::cout << " Updating detection map... " |
---|
36 | << std::flush; |
---|
37 | this->updateDetectMap(); |
---|
38 | if(this->par.isVerbose()) std::cout << "Done.\n"; |
---|
39 | |
---|
40 | if(this->par.getFlagLog()){ |
---|
41 | if(this->par.isVerbose()) |
---|
42 | std::cout << " Logging intermediate detections... " << std::flush; |
---|
43 | this->logDetectionList(); |
---|
44 | if(this->par.isVerbose()) std::cout << "Done.\n"; |
---|
45 | } |
---|
46 | |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | vector <Detection> search3DArray(long *dim, float *Array, Param &par, |
---|
51 | StatsContainer<float> &stats) |
---|
52 | { |
---|
53 | /** |
---|
54 | * Takes a dimension array and data array as input (and Parameter set) |
---|
55 | * and searches for detections in a combination of 1D and 2D searches. |
---|
56 | * Returns a vector list of Detections. |
---|
57 | * No reconstruction is assumed to have taken place, so statistics are |
---|
58 | * calculated (using robust methods) from the data array itself. |
---|
59 | * \param dim Array of dimension sizes for the data array. |
---|
60 | * \param Array Array of data. |
---|
61 | * \param par Param set defining how to do detection, and what a |
---|
62 | * BLANK pixel is etc. |
---|
63 | * \param stats The statistics that define what a detection is. |
---|
64 | * \return Vector of detected objects. |
---|
65 | */ |
---|
66 | |
---|
67 | vector <Detection> outputList; |
---|
68 | long zdim = dim[2]; |
---|
69 | long xySize = dim[0] * dim[1]; |
---|
70 | int num = 0; |
---|
71 | |
---|
72 | ProgressBar bar; |
---|
73 | // FIRST SEARCH -- IN EACH SPECTRUM. |
---|
74 | if(zdim>1){ |
---|
75 | if(par.isVerbose()) { |
---|
76 | std::cout << " 1D: "; |
---|
77 | bar.init(xySize); |
---|
78 | } |
---|
79 | |
---|
80 | bool *doPixel = new bool[xySize]; |
---|
81 | int goodSize=0; |
---|
82 | for(int npix=0; npix<xySize; npix++){ |
---|
83 | doPixel[npix] = false; |
---|
84 | for(int z=0;z<zdim;z++){ |
---|
85 | doPixel[npix] = doPixel[npix] || |
---|
86 | (!par.isBlank(Array[npix]) && !par.isInMW(z)); |
---|
87 | } |
---|
88 | // doPixel[i] is false only when there are no good pixels in spectrum |
---|
89 | // of pixel #i. |
---|
90 | } |
---|
91 | |
---|
92 | long *specdim = new long[2]; |
---|
93 | specdim[0] = zdim; specdim[1]=1; |
---|
94 | Image *spectrum = new Image(specdim); |
---|
95 | delete [] specdim; |
---|
96 | spectrum->saveParam(par); |
---|
97 | spectrum->saveStats(stats); |
---|
98 | spectrum->setMinSize(par.getMinChannels()); |
---|
99 | spectrum->pars().setBeamSize(2.); |
---|
100 | // beam size: for spectrum, only neighbouring channels correlated |
---|
101 | |
---|
102 | for(int y=0; y<dim[1]; y++){ |
---|
103 | for(int x=0; x<dim[0]; x++){ |
---|
104 | |
---|
105 | int npix = y*dim[0] + x; |
---|
106 | if( par.isVerbose() ) bar.update(npix+1); |
---|
107 | |
---|
108 | if(doPixel[npix]){ |
---|
109 | spectrum->extractSpectrum(Array,dim,npix); |
---|
110 | spectrum->removeMW(); // only works if flagMW is true |
---|
111 | std::vector<Scan> objlist = spectrum->spectrumDetect(); |
---|
112 | num += objlist.size(); |
---|
113 | for(int obj=0;obj<objlist.size();obj++){ |
---|
114 | Detection newObject; |
---|
115 | // Fix up coordinates of each pixel to match original array |
---|
116 | for(int z=objlist[obj].getX();z<=objlist[obj].getXmax();z++) { |
---|
117 | newObject.pixels().addPixel(x,y,z); |
---|
118 | } |
---|
119 | newObject.setOffsets(par); |
---|
120 | mergeIntoList(newObject,outputList,par); |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | delete spectrum; |
---|
127 | delete [] doPixel; |
---|
128 | |
---|
129 | if(par.isVerbose()) { |
---|
130 | bar.fillSpace("Found "); |
---|
131 | std::cout << num <<";" << std::flush; |
---|
132 | } |
---|
133 | |
---|
134 | } |
---|
135 | |
---|
136 | // SECOND SEARCH -- IN EACH CHANNEL |
---|
137 | if(par.isVerbose()){ |
---|
138 | std::cout << " 2D: "; |
---|
139 | bar.init(zdim); |
---|
140 | } |
---|
141 | |
---|
142 | num = 0; |
---|
143 | |
---|
144 | long *imdim = new long[2]; |
---|
145 | imdim[0] = dim[0]; imdim[1] = dim[1]; |
---|
146 | Image *channelImage = new Image(imdim); |
---|
147 | delete [] imdim; |
---|
148 | channelImage->saveParam(par); |
---|
149 | channelImage->saveStats(stats); |
---|
150 | channelImage->setMinSize(par.getMinPix()); |
---|
151 | |
---|
152 | for(int z=0; z<zdim; z++){ |
---|
153 | |
---|
154 | if( par.isVerbose() ) bar.update(z+1); |
---|
155 | |
---|
156 | if(!par.isInMW(z)){ |
---|
157 | |
---|
158 | channelImage->extractImage(Array,dim,z); |
---|
159 | std::vector<Object2D> objlist = channelImage->lutz_detect(); |
---|
160 | num += objlist.size(); |
---|
161 | for(int obj=0;obj<objlist.size();obj++){ |
---|
162 | Detection newObject; |
---|
163 | newObject.pixels().addChannel(z,objlist[obj]); |
---|
164 | newObject.setOffsets(par); |
---|
165 | mergeIntoList(newObject,outputList,par); |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | } |
---|
170 | |
---|
171 | delete channelImage; |
---|
172 | |
---|
173 | if(par.isVerbose()){ |
---|
174 | bar.fillSpace("Found "); |
---|
175 | std::cout << num << ".\n"; |
---|
176 | } |
---|
177 | |
---|
178 | return outputList; |
---|
179 | } |
---|
180 | |
---|
181 | |
---|