source: tags/release-1.1/src/Cubes/CubicSearch.cc @ 1391

Last change on this file since 1391 was 299, checked in by Matthew Whiting, 17 years ago

Adding distribution text at the start of each file...

File size: 8.1 KB
Line 
1// -----------------------------------------------------------------------
2// CubicSearch.cc: Searching a 3-dimensional Cube.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <iostream>
29#include <iomanip>
30#include <fstream>
31#include <vector>
32#include <param.hh>
33#include <PixelMap/Object3D.hh>
34#include <Cubes/cubes.hh>
35#include <Utils/utils.hh>
36#include <Utils/feedback.hh>
37#include <Utils/Statistics.hh>
38
39using std::vector;
40using namespace PixelInfo;
41using namespace Statistics;
42
43void Cube::CubicSearch()
44{
45  /**
46   *  A front end to the cubic searching routine that does not
47   *  involve any wavelet reconstruction.
48   *  The statistics of the cube are calculated first of all.
49   *  If baseline-removal is required that is done prior to searching.
50   *  Once searching is complete, the detection map is updated and
51   *  the intermediate detections are logged in the log file.
52   */
53
54  if(this->par.isVerbose()) std::cout << "  ";
55
56  this->setCubeStats();
57   
58  if(this->par.isVerbose()) std::cout << "  Searching... " << std::flush;
59 
60//   this->objectList = search3DArray(this->axisDim,this->array,
61//                                 this->par,this->Stats);
62  *this->objectList = search3DArraySimple(this->axisDim,this->array,
63                                         this->par,this->Stats);
64
65  if(this->par.isVerbose()) std::cout << "  Updating detection map... "
66                                      << std::flush;
67  this->updateDetectMap();
68  if(this->par.isVerbose()) std::cout << "Done.\n";
69
70  if(this->par.getFlagLog()){
71    if(this->par.isVerbose())
72      std::cout << "  Logging intermediate detections... " << std::flush;
73    this->logDetectionList();
74    if(this->par.isVerbose()) std::cout << "Done.\n";
75  }
76
77}
78//---------------------------------------------------------------
79
80
81std::vector <Detection> search3DArray(long *dim, float *Array, Param &par,
82                                      StatsContainer<float> &stats)
83{
84  /**
85   *  Takes a dimension array and data array as input (and Parameter set)
86   *  and searches for detections in a combination of 1D and 2D searches.
87   *  Returns a vector list of Detections.
88   *  No reconstruction is assumed to have taken place, so statistics are
89   *  calculated (using robust methods) from the data array itself.
90   * \param dim Array of dimension sizes for the data array.
91   * \param Array Array of data.
92   * \param par Param set defining how to do detection, and what a
93   * BLANK pixel is etc.
94   * \param stats The statistics that define what a detection is.
95   * \return Vector of detected objects.
96   */
97
98  std::vector <Detection> outputList;
99  long zdim = dim[2];
100  long xySize = dim[0] * dim[1];
101  int num = 0;
102
103  ProgressBar bar;
104  // FIRST SEARCH --  IN EACH SPECTRUM.
105  if(zdim>1){
106    if(par.isVerbose()) {
107      std::cout << "  1D: ";
108      bar.init(xySize);
109    }
110
111    bool *doPixel = new bool[xySize];
112    for(int npix=0; npix<xySize; npix++){
113      doPixel[npix] = false;
114      for(int z=0;z<zdim;z++){
115        doPixel[npix] = doPixel[npix] ||
116          (!par.isBlank(Array[npix]) && !par.isInMW(z));
117      }
118      // doPixel[i] is false only when there are no good pixels in spectrum
119      //  of pixel #i.
120    }
121
122    long *specdim = new long[2];
123    specdim[0] = zdim; specdim[1]=1;
124    Image *spectrum = new Image(specdim);
125    delete [] specdim;
126    spectrum->saveParam(par);
127    spectrum->saveStats(stats);
128    spectrum->setMinSize(par.getMinChannels());
129    spectrum->pars().setBeamSize(2.);
130    // beam size: for spectrum, only neighbouring channels correlated
131
132    for(int y=0; y<dim[1]; y++){
133      for(int x=0; x<dim[0]; x++){
134
135        int npix = y*dim[0] + x;
136        if( par.isVerbose() ) bar.update(npix+1);
137       
138        if(doPixel[npix]){
139          spectrum->extractSpectrum(Array,dim,npix);
140          spectrum->removeMW(); // only works if flagMW is true
141          std::vector<Scan> objlist = spectrum->spectrumDetect();
142          num += objlist.size();
143          for(int obj=0;obj<objlist.size();obj++){
144            Detection newObject;
145            // Fix up coordinates of each pixel to match original array
146            for(int z=objlist[obj].getX();z<=objlist[obj].getXmax();z++) {
147              newObject.pixels().addPixel(x,y,z);
148            }
149            newObject.setOffsets(par);
150            mergeIntoList(newObject,outputList,par);
151          }
152        }
153      }
154    }
155
156    delete spectrum;
157    delete [] doPixel;
158 
159    if(par.isVerbose()) {
160      bar.fillSpace("Found ");
161      std::cout << num <<";" << std::flush;
162    }
163
164  }
165
166  // SECOND SEARCH --  IN EACH CHANNEL
167  if(par.isVerbose()){
168    std::cout << "  2D: ";
169    bar.init(zdim);
170  }
171 
172  num = 0;
173
174  long *imdim = new long[2];
175  imdim[0] = dim[0]; imdim[1] = dim[1];
176  Image *channelImage = new Image(imdim);
177  delete [] imdim;
178  channelImage->saveParam(par);
179  channelImage->saveStats(stats);
180  //  channelImage->setMinSize(par.getMinPix());
181  channelImage->setMinSize(1);
182
183  for(int z=0; z<zdim; z++){
184
185    if( par.isVerbose() ) bar.update(z+1);
186
187    if(!par.isInMW(z)){
188
189      channelImage->extractImage(Array,dim,z);
190      std::vector<Object2D> objlist = channelImage->lutz_detect();
191      num += objlist.size();
192      for(int obj=0;obj<objlist.size();obj++){
193        Detection newObject;
194        newObject.pixels().addChannel(z,objlist[obj]);
195        newObject.setOffsets(par);
196        mergeIntoList(newObject,outputList,par);
197      }
198    }
199
200  }
201
202  delete channelImage;
203
204  if(par.isVerbose()){
205    bar.fillSpace("Found ");
206    std::cout << num << ".\n";
207  }
208
209  return outputList;
210}
211//---------------------------------------------------------------
212
213std::vector <Detection> search3DArraySimple(long *dim, float *Array,
214                                            Param &par,
215                                            StatsContainer<float> &stats)
216{
217  /**
218   *  Takes a dimension array and data array as input (and Parameter
219   *  set) and searches for detections just in the channel maps -- no
220   *  1D searches are done.  * Returns a vector list of Detections.
221   *  No reconstruction is assumed to have taken place, so statistics
222   *  are calculated (using robust methods) from the data array
223   *  itself.
224   * \param dim Array of dimension sizes for the data array.
225   * \param Array Array of data.
226   * \param par Param set defining how to do detection, and what a
227   *              BLANK pixel is etc.
228   * \param stats The statistics that define what a detection is.
229   * \return Vector of detected objects.
230   */
231
232  std::vector <Detection> outputList;
233  long zdim = dim[2];
234  int num = 0;
235
236  ProgressBar bar;
237  if(par.isVerbose()) bar.init(zdim);
238 
239  num = 0;
240
241  long *imdim = new long[2];
242  imdim[0] = dim[0]; imdim[1] = dim[1];
243  Image *channelImage = new Image(imdim);
244  delete [] imdim;
245  channelImage->saveParam(par);
246  channelImage->saveStats(stats);
247  channelImage->setMinSize(1);
248
249  for(int z=0; z<zdim; z++){
250
251    if( par.isVerbose() ) bar.update(z+1);
252
253    if(!par.isInMW(z)){
254
255      channelImage->extractImage(Array,dim,z);
256      std::vector<Object2D> objlist = channelImage->lutz_detect();
257      num += objlist.size();
258      for(int obj=0;obj<objlist.size();obj++){
259        Detection newObject;
260        newObject.pixels().addChannel(z,objlist[obj]);
261        newObject.setOffsets(par);
262        mergeIntoList(newObject,outputList,par);
263      }
264    }
265
266  }
267
268  delete channelImage;
269
270  if(par.isVerbose()){
271    bar.fillSpace("Found ");
272    std::cout << num << ".\n";
273  }
274
275  return outputList;
276}
277
278
Note: See TracBrowser for help on using the repository browser.