source: trunk/src/Cubes/CubicSearch.cc @ 221

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

More documentation being added to source code, with a new file (src/Utils/Hanning.cc) added as well.

File size: 4.3 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <vector>
5#include <param.hh>
6#include <Cubes/cubes.hh>
7#include <Utils/utils.hh>
8#include <Utils/feedback.hh>
9#include <Utils/Statistics.hh>
10
11void Cube::CubicSearch()
12{
13  /**
14   *  A front end to the cubic searching routine that does not
15   *  involve any wavelet reconstruction.
16   *  The statistics of the cube are calculated first of all.
17   *  If baseline-removal is required that is done prior to searching.
18   *  Once searching is complete, the detection map is updated and
19   *  the intermediate detections are logged in the log file.
20   */
21
22  if(this->par.isVerbose()) std::cout << "  ";
23  this->setCubeStats();
24   
25  this->objectList = search3DArray(this->axisDim,this->array,
26                                   this->par,this->Stats);
27
28  this->updateDetectMap();
29  if(this->par.getFlagLog()) this->logDetectionList();
30
31}
32
33
34vector <Detection> search3DArray(long *dim, float *Array, Param &par,
35                                 StatsContainer<float> &stats)
36{
37  /**
38   * cubicSearch
39   *  Takes a dimension array and data array as input (and Parameter set)
40   *  and searches for detections in a combination of 1D and 2D searches.
41   *  Returns a vector list of Detections.
42   *  No reconstruction is assumed to have taken place, so statistics are
43   *  calculated (using robust methods) from the data array itself.
44   */
45
46  vector <Detection> outputList;
47  long zdim = dim[2];
48  long xySize = dim[0] * dim[1];
49  int num = 0;
50
51  bool *doPixel = new bool[xySize];
52  int goodSize=0;
53  for(int npix=0; npix<xySize; npix++){
54    doPixel[npix] = false;
55    for(int z=0;z<zdim;z++){
56      doPixel[npix] = doPixel[npix] ||
57        (!par.isBlank(Array[npix]) && !par.isInMW(z));
58    }
59    // doPixel[i] is false only when there are no good pixels in spectrum
60    //  of pixel #i.
61  }
62
63  ProgressBar bar;
64  // FIRST SEARCH --  IN EACH SPECTRUM.
65  if(zdim>1){
66    if(par.isVerbose()) {
67      std::cout << "  1D: ";
68      bar.init(xySize);
69    }
70
71    for(int npix=0; npix<xySize; npix++){
72
73      if( par.isVerbose() ) bar.update(npix+1);
74
75      if(doPixel[npix]){
76
77        long *specdim = new long[2];
78        specdim[0] = zdim; specdim[1]=1;
79        Image *spectrum = new Image(specdim);
80        delete [] specdim;
81        spectrum->saveParam(par);
82        spectrum->saveStats(stats);
83        spectrum->pars().setBeamSize(2.);
84        // beam size: for spectrum, only neighbouring channels correlated
85        spectrum->extractSpectrum(Array,dim,npix);
86        spectrum->removeMW(); // only works if flagMW is true
87        spectrum->setMinSize(par.getMinChannels());
88        spectrum->spectrumDetect();
89        num += spectrum->getNumObj();
90        for(int obj=0;obj<spectrum->getNumObj();obj++){
91          Detection *object = new Detection;
92          *object = spectrum->getObject(obj);
93          for(int pix=0;pix<object->getSize();pix++) {
94            // Fix up coordinates of each pixel to match original array
95            object->setZ(pix, object->getX(pix));
96            object->setX(pix, npix%dim[0]);
97            object->setY(pix, npix/dim[0]);
98          }
99          object->setOffsets(par);
100          object->calcParams();
101          mergeIntoList(*object,outputList,par);
102          delete object;
103        }
104        delete spectrum;
105      }
106    }
107
108    //    num = outputList.size();
109    if(par.isVerbose()) {
110      bar.fillSpace("Found ");
111      std::cout << num <<";" << std::flush;
112    }
113
114  }
115
116  // SECOND SEARCH --  IN EACH CHANNEL
117  if(par.isVerbose()){
118    std::cout << "  2D: ";
119    bar.init(zdim);
120  }
121 
122  num = 0;
123
124  for(int z=0; z<zdim; z++){
125
126    if( par.isVerbose() ) bar.update(z+1);
127
128    if(!par.isInMW(z)){
129
130      long *imdim = new long[2];
131      imdim[0] = dim[0]; imdim[1] = dim[1];
132      Image *channelImage = new Image(imdim);
133      delete [] imdim;
134      channelImage->saveParam(par);
135      channelImage->saveStats(stats);
136      channelImage->extractImage(Array,dim,z);
137      channelImage->setMinSize(par.getMinPix());
138      channelImage->lutz_detect();
139      num += channelImage->getNumObj();
140      for(int obj=0;obj<channelImage->getNumObj();obj++){
141        Detection *object = new Detection;
142        *object = channelImage->getObject(obj);
143        // Fix up coordinates of each pixel to match original array
144        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
145        object->setOffsets(par);
146        object->calcParams();
147        mergeIntoList(*object,outputList,par);
148        delete object;
149      }
150      delete channelImage;
151    }
152
153  }
154
155  if(par.isVerbose()){
156    bar.fillSpace("Found ");
157    std::cout << num << ".\n";
158  }
159
160  delete [] doPixel;
161 
162  return outputList;
163}
Note: See TracBrowser for help on using the repository browser.