source: trunk/Cubes/cubicSearch.cc @ 50

Last change on this file since 50 was 50, checked in by Matthew Whiting, 18 years ago

Added a simpler search routine for 1-D data, called spectrumDetect (in
Detection/), that doesn't use the extra row that is involved in the
lutz_detect routine. This should make the 1-D search run 2x as fast...
Changed the calls to lutz_detect in cubicSearch & reconSearch to
spectrumDetect for the 1-D cases.

File size: 6.7 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <vector>
5#include <Cubes/cubes.hh>
6#include <Utils/utils.hh>
7
8void Cube::SimpleSearch3D()
9{
10  /**
11   * Cube::SimpleSearch3D()
12   *  A front end to the cubic searching routine that does not
13   *  involve any wavelet reconstruction.
14   *  Although if baseline-removal is required that is done prior to searching.
15   *  Once searching is complete, the detection map is updated and
16   *  the intermediate detections are logged in the log file.
17   */
18
19  this->objectList = cubicSearch(this->axisDim,this->array,this->par);
20   
21  this->updateDetectMap();
22  if(this->par.getFlagLog()) this->logDetectionList();
23
24}
25
26
27vector <Detection> cubicSearch(long *dim, float *Array, Param &par)
28{
29  /**
30   * cubicSearch
31   *  Takes a dimension array and data array as input (and Parameter set)
32   *  and searches for detections in a combination of 1D and 2D searches.
33   *  Returns a vector list of Detections.
34   *  No reconstruction is assumed to have taken place, so statistics are
35   *  calculated (using robust methods) from the data array itself.
36   */
37
38  vector <Detection> outputList;
39  int zdim = dim[2];
40  int xySize = dim[0] * dim[1];
41  int fullSize = zdim * xySize;
42  int num = 0;
43
44  float blankPixValue = par.getBlankPixVal();
45  bool *isGood = new bool[fullSize];
46  for(int pos=0;pos<fullSize;pos++)
47    isGood[pos] = !par.isBlank(Array[pos]);
48 
49  float dud;
50
51  // FIRST SEARCH --  IN EACH SPECTRUM.
52  // FIRST, GET STATS
53  if(zdim>1){
54    if(par.isVerbose()) std::cout << "  1D: |                    |" << std::flush;
55//     if(par.isVerbose()) std::cout << "Done  0%" << "\b\b\b\b\b\b\b\b" << std::flush;
56    float *specMedian = new float[xySize];
57    float *specSigma = new float[xySize];
58
59    for(int npix=0; npix<xySize; npix++){
60      float *spec = new float[zdim];
61      int goodSize=0;
62      for(int z=0;z<zdim;z++) if(isGood[z*xySize+npix]) spec[goodSize++] = Array[z*xySize+npix];
63      if(goodSize>0) findMedianStats(spec,goodSize,specMedian[npix],dud);
64      else specMedian[npix] = blankPixValue;
65      //     if(goodSize>0) findNormalStats(spec,goodSize,dud,specSigma[npix]);
66      if(goodSize>0){
67        findMedianStats(spec,goodSize,dud,specSigma[npix]);
68        specSigma[npix] /= correctionFactor;
69      }
70      else specSigma[npix] = 1.;
71      delete spec;
72    }
73    // NEXT, DO SOURCE FINDING
74    int numSearches = xySize + zdim;
75    for(int npix=0; npix<xySize; npix++){
76
77      if( par.isVerbose() && ((100*(npix+1)/xySize)%5 == 0) ){
78        std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|";
79        for(int i=0;i<(100*(npix+1)/xySize)/5;i++) std::cout << "#";
80        for(int i=(100*(npix+1)/xySize)/5;i<20;i++) std::cout << " ";
81        std::cout << "|" << std::flush;
82      }
83
84      float *spec = new float[zdim];
85      for(int z=0;z<zdim;z++) spec[z] = Array[z*xySize + npix];
86      long *specdim = new long[2];
87      specdim[0] = zdim; specdim[1]=1;
88      Image *spectrum = new Image(specdim);
89      spectrum->saveParam(par);
90      spectrum->pars().setBeamSize(2.); // for spectrum, only neighbouring channels correlated
91      spectrum->saveArray(spec,zdim);
92      spectrum->setStats(specMedian[npix],specSigma[npix],par.getCut());
93      if(par.getFlagFDR()) spectrum->setupFDR();
94      spectrum->setMinSize(par.getMinChannels());
95      //      spectrum->lutz_detect();
96      spectrum->spectrumDetect();
97      for(int obj=0;obj<spectrum->getNumObj();obj++){
98        Detection *object = new Detection;
99        *object = spectrum->getObject(obj);
100//      if(par.getFlagGrowth()) growObject(*object,*spectrum);
101        for(int pix=0;pix<object->getSize();pix++) {
102          // Fix up coordinates of each pixel to match original array
103          object->setZ(pix, object->getX(pix));
104          object->setX(pix, npix%dim[0]);
105          object->setY(pix, npix/dim[0]);
106        }
107        object->addOffsets(par);
108        object->calcParams();
109//      outputList.push_back(*object);
110        mergeIntoList(*object,outputList,par);
111        delete object;
112      }
113      delete spectrum;
114      delete spec;
115      delete specdim;
116    }
117
118    delete [] specMedian;
119    delete [] specSigma;
120
121    num = outputList.size();
122    if(par.isVerbose())
123      std::cout <<"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound " << num <<";" << std::flush;
124
125  }
126
127  // SECOND SEARCH --  IN EACH CHANNEL
128  // FIRST, GET STATS
129  if(par.isVerbose()) std::cout << "  2D: |                    |" << std::flush;
130//   if(par.isVerbose()) std::cout << "Done  0%" << "\b\b\b\b\b\b\b\b" << std::flush;
131  float *imageMedian = new float[zdim];
132  float *imageSigma = new float[zdim];
133  for(int z=0; z<zdim; z++){
134    float *image = new float[xySize];
135    int goodSize=0;
136    for(int npix=0; npix<xySize; npix++)
137      if(isGood[z*xySize + npix]) image[goodSize++] = Array[z*xySize + npix];
138    if(goodSize>0) findMedianStats(image,goodSize,imageMedian[z],dud);
139    else imageMedian[z] = blankPixValue;
140    if(goodSize>0) findNormalStats(image,goodSize,dud,imageSigma[z]);
141    else imageSigma[z] = 1.;
142    delete image;
143  }
144  // NEXT, DO SOURCE FINDING
145  bool *doChannel = new bool[zdim];
146  for(int z=0;z<zdim;z++)
147    doChannel[z] = !( par.getFlagMW() && (z>=par.getMinMW()) && (z<=par.getMaxMW()) );
148
149  for(int z=0; z<zdim; z++){
150
151    if( par.isVerbose() && ((100*(z+1)/zdim)%5 == 0) ){
152      std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|";
153      for(int i=0;i<(100*(z+1)/zdim)/5;i++) std::cout << "#";
154      for(int i=(100*(z+1)/zdim)/5;i<20;i++) std::cout << " ";
155      std::cout << "|" << std::flush;
156    }
157
158    if( doChannel[z] ){
159
160      float *image = new float[xySize];
161      for(int npix=0; npix<xySize; npix++) image[npix] = Array[z*xySize + npix];
162      long *imdim = new long[2];
163      imdim[0] = dim[0]; imdim[1] = dim[1];
164      Image *channelImage = new Image(imdim);
165      channelImage->saveParam(par);
166      channelImage->saveArray(image,xySize);
167      channelImage->setStats(imageMedian[z],imageSigma[z],par.getCut());
168      if(par.getFlagFDR()) channelImage->setupFDR();
169      channelImage->setMinSize(par.getMinPix());
170      channelImage->lutz_detect();
171      for(int obj=0;obj<channelImage->getNumObj();obj++){
172        Detection *object = new Detection;
173        *object = channelImage->getObject(obj);
174//      if(par.getFlagGrowth()) growObject(*object,*channelImage);
175        // Fix up coordinates of each pixel to match original array
176        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
177        object->addOffsets(par);
178        object->calcParams();
179//      outputList.push_back(*object);
180        mergeIntoList(*object,outputList,par);
181        delete object;
182      }
183      delete image;
184      delete channelImage;
185      delete imdim;
186    }
187
188  }
189
190  if(par.isVerbose())
191    std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound " << outputList.size() - num
192              << ".                                           " << std::endl << std::flush;
193
194  delete [] imageMedian;
195  delete [] imageSigma;
196  delete [] isGood;
197  delete [] doChannel;
198
199  return outputList;
200}
Note: See TracBrowser for help on using the repository browser.