source: branches/pixel-map-branch/src/Cubes/CubicSearch.cc @ 251

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

Mainly changes to improve the execution speed and reliability of the searching:

  • Changed the extractSpectrum & extractImage functions, so that they don't call saveArray, but rather just write directly to the flux array.
  • In the searching functions, moved the definitions of spectrum and channelImage (the Image objects) out of the loops over pixels/channels. This way they are only defined once, rather than each time round the loop.
  • Fixed a bug so that the full number of individual detections in the 1D case are reported, rather than the number after the mergeIntoList has done its job.
  • When Merger prints out the counter/size information, the counter number now starts at 1, not 0 (more sensible when comparing to the size).
  • Otherwise, minor presentation tweaks.
File size: 4.8 KB
Line 
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
12using std::vector;
13
14void Cube::CubicSearch()
15{
16  /**
17   *  A front end to the cubic searching routine that does not
18   *  involve any wavelet reconstruction.
19   *  The statistics of the cube are calculated first of all.
20   *  If baseline-removal is required that is done prior to searching.
21   *  Once searching is complete, the detection map is updated and
22   *  the intermediate detections are logged in the log file.
23   */
24
25  if(this->par.isVerbose()) std::cout << "  ";
26
27  this->setCubeStats();
28   
29  if(this->par.isVerbose()) std::cout << "  Searching... " << std::flush;
30 
31  this->objectList = search3DArray(this->axisDim,this->array,
32                                   this->par,this->Stats);
33
34  if(this->par.isVerbose()) std::cout << "  Updating detection map... "
35                                      << std::flush;
36  this->updateDetectMap();
37  if(this->par.isVerbose()) std::cout << "Done.\n";
38
39  if(this->par.getFlagLog()){
40    if(this->par.isVerbose())
41      std::cout << "  Logging intermediate detections... " << std::flush;
42    this->logDetectionList();
43    if(this->par.isVerbose()) std::cout << "Done.\n";
44  }
45
46}
47
48
49vector <Detection> search3DArray(long *dim, float *Array, Param &par,
50                                 StatsContainer<float> &stats)
51{
52  /**
53   *  Takes a dimension array and data array as input (and Parameter set)
54   *  and searches for detections in a combination of 1D and 2D searches.
55   *  Returns a vector list of Detections.
56   *  No reconstruction is assumed to have taken place, so statistics are
57   *  calculated (using robust methods) from the data array itself.
58   * \param dim Array of dimension sizes for the data array.
59   * \param Array Array of data.
60   * \param par Param set defining how to do detection, and what a
61   * BLANK pixel is etc.
62   * \param stats The statistics that define what a detection is.
63   * \return Vector of detected objects.
64   */
65
66  vector <Detection> outputList;
67  long zdim = dim[2];
68  long xySize = dim[0] * dim[1];
69  int num = 0;
70
71  ProgressBar bar;
72  // FIRST SEARCH --  IN EACH SPECTRUM.
73  if(zdim>1){
74    if(par.isVerbose()) {
75      std::cout << "  1D: ";
76      bar.init(xySize);
77    }
78
79    bool *doPixel = new bool[xySize];
80    int goodSize=0;
81    for(int npix=0; npix<xySize; npix++){
82      doPixel[npix] = false;
83      for(int z=0;z<zdim;z++){
84        doPixel[npix] = doPixel[npix] ||
85          (!par.isBlank(Array[npix]) && !par.isInMW(z));
86      }
87      // doPixel[i] is false only when there are no good pixels in spectrum
88      //  of pixel #i.
89    }
90
91    long *specdim = new long[2];
92    specdim[0] = zdim; specdim[1]=1;
93    Image *spectrum = new Image(specdim);
94    delete [] specdim;
95    spectrum->saveParam(par);
96    spectrum->saveStats(stats);
97    spectrum->setMinSize(par.getMinChannels());
98    spectrum->pars().setBeamSize(2.);
99    // beam size: for spectrum, only neighbouring channels correlated
100
101    for(int y=0; y<dim[1]; y++){
102      for(int x=0; x<dim[0]; x++){
103
104        int npix = y*dim[0] + x;
105        if( par.isVerbose() ) bar.update(npix+1);
106       
107        if(doPixel[npix]){
108          spectrum->extractSpectrum(Array,dim,npix);
109          spectrum->removeMW(); // only works if flagMW is true
110          std::vector<Scan> objlist = spectrum->spectrumDetect();
111          num += objlist.size();
112          for(int obj=0;obj<objlist.size();obj++){
113            Detection newObject;
114            // Fix up coordinates of each pixel to match original array
115            for(int z=objlist[obj].getX();z<=objlist[obj].getXmax();z++) {
116              newObject.pixels().addPixel(x,y,z);
117            }
118            newObject.setOffsets(par);
119            mergeIntoList(newObject,outputList,par);
120          }
121        }
122      }
123    }
124
125    delete spectrum;
126    delete [] doPixel;
127 
128    if(par.isVerbose()) {
129      bar.fillSpace("Found ");
130      std::cout << num <<";" << std::flush;
131    }
132
133  }
134
135  // SECOND SEARCH --  IN EACH CHANNEL
136  if(par.isVerbose()){
137    std::cout << "  2D: ";
138    bar.init(zdim);
139  }
140 
141  num = 0;
142
143  long *imdim = new long[2];
144  imdim[0] = dim[0]; imdim[1] = dim[1];
145  Image *channelImage = new Image(imdim);
146  delete [] imdim;
147  channelImage->saveParam(par);
148  channelImage->saveStats(stats);
149  channelImage->setMinSize(par.getMinPix());
150
151  for(int z=0; z<zdim; z++){
152
153    if( par.isVerbose() ) bar.update(z+1);
154
155    if(!par.isInMW(z)){
156
157      channelImage->extractImage(Array,dim,z);
158      std::vector<Object2D> objlist = channelImage->lutz_detect();
159      num += objlist.size();
160      for(int obj=0;obj<objlist.size();obj++){
161        Detection newObject;
162        newObject.pixels().addChannel(z,objlist[obj]);
163        newObject.setOffsets(par);
164        mergeIntoList(newObject,outputList,par);
165      }
166    }
167
168  }
169
170  delete channelImage;
171
172  if(par.isVerbose()){
173    bar.fillSpace("Found ");
174    std::cout << num << ".\n";
175  }
176
177  return outputList;
178}
179
180
Note: See TracBrowser for help on using the repository browser.