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
RevLine 
[3]1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <vector>
[189]5#include <param.hh>
[3]6#include <Cubes/cubes.hh>
7#include <Utils/utils.hh>
[213]8#include <Utils/feedback.hh>
[192]9#include <Utils/Statistics.hh>
[3]10
[103]11void Cube::CubicSearch()
[3]12{
13  /**
14   *  A front end to the cubic searching routine that does not
15   *  involve any wavelet reconstruction.
[220]16   *  The statistics of the cube are calculated first of all.
[153]17   *  If baseline-removal is required that is done prior to searching.
[3]18   *  Once searching is complete, the detection map is updated and
19   *  the intermediate detections are logged in the log file.
20   */
21
[219]22  if(this->par.isVerbose()) std::cout << "  ";
[189]23  this->setCubeStats();
24   
[190]25  this->objectList = search3DArray(this->axisDim,this->array,
26                                   this->par,this->Stats);
[189]27
[3]28  this->updateDetectMap();
29  if(this->par.getFlagLog()) this->logDetectionList();
30
31}
32
33
[190]34vector <Detection> search3DArray(long *dim, float *Array, Param &par,
35                                 StatsContainer<float> &stats)
[3]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;
[103]47  long zdim = dim[2];
48  long xySize = dim[0] * dim[1];
[3]49  int num = 0;
50
[189]51  bool *doPixel = new bool[xySize];
[103]52  int goodSize=0;
53  for(int npix=0; npix<xySize; npix++){
[189]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.
[103]61  }
[187]62
63  ProgressBar bar;
[3]64  // FIRST SEARCH --  IN EACH SPECTRUM.
65  if(zdim>1){
[175]66    if(par.isVerbose()) {
67      std::cout << "  1D: ";
[187]68      bar.init(xySize);
[175]69    }
[3]70
71    for(int npix=0; npix<xySize; npix++){
[86]72
[187]73      if( par.isVerbose() ) bar.update(npix+1);
[3]74
[189]75      if(doPixel[npix]){
[103]76
77        long *specdim = new long[2];
78        specdim[0] = zdim; specdim[1]=1;
79        Image *spectrum = new Image(specdim);
[187]80        delete [] specdim;
[103]81        spectrum->saveParam(par);
[190]82        spectrum->saveStats(stats);
[146]83        spectrum->pars().setBeamSize(2.);
84        // beam size: for spectrum, only neighbouring channels correlated
[103]85        spectrum->extractSpectrum(Array,dim,npix);
86        spectrum->removeMW(); // only works if flagMW is true
87        spectrum->setMinSize(par.getMinChannels());
88        spectrum->spectrumDetect();
[146]89        num += spectrum->getNumObj();
[103]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          }
[221]99          object->setOffsets(par);
[103]100          object->calcParams();
101          mergeIntoList(*object,outputList,par);
102          delete object;
[3]103        }
[103]104        delete spectrum;
[3]105      }
[103]106    }
[3]107
[146]108    //    num = outputList.size();
[175]109    if(par.isVerbose()) {
[219]110      bar.fillSpace("Found ");
111      std::cout << num <<";" << std::flush;
[175]112    }
[3]113
114  }
115
116  // SECOND SEARCH --  IN EACH CHANNEL
[175]117  if(par.isVerbose()){
118    std::cout << "  2D: ";
[187]119    bar.init(zdim);
[175]120  }
121 
[146]122  num = 0;
[3]123
124  for(int z=0; z<zdim; z++){
125
[187]126    if( par.isVerbose() ) bar.update(z+1);
[3]127
[103]128    if(!par.isInMW(z)){
[3]129
130      long *imdim = new long[2];
131      imdim[0] = dim[0]; imdim[1] = dim[1];
132      Image *channelImage = new Image(imdim);
[187]133      delete [] imdim;
[3]134      channelImage->saveParam(par);
[190]135      channelImage->saveStats(stats);
[53]136      channelImage->extractImage(Array,dim,z);
[13]137      channelImage->setMinSize(par.getMinPix());
[3]138      channelImage->lutz_detect();
[146]139      num += channelImage->getNumObj();
[3]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);
[221]145        object->setOffsets(par);
[3]146        object->calcParams();
147        mergeIntoList(*object,outputList,par);
148        delete object;
149      }
150      delete channelImage;
151    }
152
153  }
154
[175]155  if(par.isVerbose()){
[219]156    bar.fillSpace("Found ");
157    std::cout << num << ".\n";
[175]158  }
[3]159
[189]160  delete [] doPixel;
[86]161 
[3]162  return outputList;
163}
Note: See TracBrowser for help on using the repository browser.