source: tags/release-1.0.5/src/Cubes/CubicSearch.cc @ 1455

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

Some minor fixes to code:

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