source: trunk/src/Cubes/cubicSearch.cc @ 160

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

Corrected a bug in the call to Cube::setupColumns() -- the object ID had not
been set when the logfile is written to, so the obj# column was oversized.
Now fixed. Verification files also updated.

File size: 5.5 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::CubicSearch()
9{
10  /**
11   * Cube::SimpleSearch3D()
12   *  A front end to the cubic searching routine that does not
13   *  involve any wavelet reconstruction.
14   *  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 = search3DArray(this->axisDim,this->array,this->par);
20   
21  this->updateDetectMap();
22  if(this->par.getFlagLog()) this->logDetectionList();
23
24}
25
26
27vector <Detection> search3DArray(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  long zdim = dim[2];
40  long xySize = dim[0] * dim[1];
41  long 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]) && !par.isInMW(pos/xySize);
48  }
49  bool *doChannel = new bool[xySize];
50  int goodSize=0;
51  for(int npix=0; npix<xySize; npix++){
52    for(int z=0;z<zdim;z++) if(isGood[z*xySize+npix]) goodSize++;
53    if(goodSize==0) doChannel[npix] = false;
54    else doChannel[npix] = true;
55  }
56 
57  // FIRST SEARCH --  IN EACH SPECTRUM.
58  if(zdim>1){
59    if(par.isVerbose()) std::cout << "  1D: |                    |"
60                                  << std::flush;
61
62    for(int npix=0; npix<xySize; npix++){
63
64      if( par.isVerbose() && ((100*(npix+1)/xySize)%5 == 0) ){
65        std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|";
66        for(int i=0;i<(100*(npix+1)/xySize)/5;i++) std::cout << "#";
67        for(int i=(100*(npix+1)/xySize)/5;i<20;i++) std::cout << " ";
68        std::cout << "|" << std::flush;
69      }
70
71      if(doChannel[npix]){
72
73        float *spec = new float[zdim];
74        float specMedian,specSigma;
75        goodSize=0;
76        for(int z=0;z<zdim;z++)
77          if(isGood[z*xySize+npix]) spec[goodSize++] = Array[z*xySize+npix];
78        findMedianStats(spec,goodSize,specMedian,specSigma);
79        specSigma /= correctionFactor;
80
81
82        long *specdim = new long[2];
83        specdim[0] = zdim; specdim[1]=1;
84        Image *spectrum = new Image(specdim);
85        delete specdim;
86        spectrum->saveParam(par);
87        spectrum->pars().setBeamSize(2.);
88        // beam size: for spectrum, only neighbouring channels correlated
89        spectrum->extractSpectrum(Array,dim,npix);
90        spectrum->removeMW(); // only works if flagMW is true
91        spectrum->setStats(specMedian,specSigma,par.getCut());
92        if(par.getFlagFDR()) spectrum->setupFDR();
93        spectrum->setMinSize(par.getMinChannels());
94        spectrum->spectrumDetect();
95        num += spectrum->getNumObj();
96        for(int obj=0;obj<spectrum->getNumObj();obj++){
97          Detection *object = new Detection;
98          *object = spectrum->getObject(obj);
99          for(int pix=0;pix<object->getSize();pix++) {
100            // Fix up coordinates of each pixel to match original array
101            object->setZ(pix, object->getX(pix));
102            object->setX(pix, npix%dim[0]);
103            object->setY(pix, npix/dim[0]);
104          }
105          object->addOffsets(par);
106          object->calcParams();
107          mergeIntoList(*object,outputList,par);
108          delete object;
109        }
110        delete spectrum;
111      }
112    }
113
114    //    num = outputList.size();
115    if(par.isVerbose())
116      std::cout <<"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound "
117                << num <<";" << std::flush;
118
119  }
120
121  // SECOND SEARCH --  IN EACH CHANNEL
122  if(par.isVerbose()) std::cout << "  2D: |                    |"
123                                << std::flush;
124  num = 0;
125
126  for(int z=0; z<zdim; z++){
127
128    if( par.isVerbose() && ((100*(z+1)/zdim)%5 == 0) ){
129      std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b|";
130      for(int i=0;i<(100*(z+1)/zdim)/5;i++) std::cout << "#";
131      for(int i=(100*(z+1)/zdim)/5;i<20;i++) std::cout << " ";
132      std::cout << "|" << std::flush;
133    }
134
135    if(!par.isInMW(z)){
136
137      float *image = new float[xySize];
138      float imageMedian, imageSigma;
139      goodSize=0;
140      for(int npix=0; npix<xySize; npix++) {
141        if(isGood[z*xySize + npix])
142          image[goodSize++] = Array[z*xySize + npix];
143      }
144      findMedianStats(image,goodSize,imageMedian,imageSigma);
145      imageSigma /= correctionFactor;
146
147      long *imdim = new long[2];
148      imdim[0] = dim[0]; imdim[1] = dim[1];
149      Image *channelImage = new Image(imdim);
150      delete imdim;
151      channelImage->saveParam(par);
152      channelImage->extractImage(Array,dim,z);
153      channelImage->setStats(imageMedian,imageSigma,par.getCut());
154      if(par.getFlagFDR()) channelImage->setupFDR();
155      channelImage->setMinSize(par.getMinPix());
156      channelImage->lutz_detect();
157      num += channelImage->getNumObj();
158      for(int obj=0;obj<channelImage->getNumObj();obj++){
159        Detection *object = new Detection;
160        *object = channelImage->getObject(obj);
161        // Fix up coordinates of each pixel to match original array
162        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
163        object->addOffsets(par);
164        object->calcParams();
165        mergeIntoList(*object,outputList,par);
166        delete object;
167      }
168      delete channelImage;
169    }
170
171  }
172
173  if(par.isVerbose())
174    std::cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bFound "
175              << num
176              << ".                                           "
177              << std::endl << std::flush;
178
179  delete [] isGood;
180  delete [] doChannel;
181 
182  return outputList;
183}
Note: See TracBrowser for help on using the repository browser.