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

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

Large commit, but mostly documentation-oriented.

Only non-doc-related changes are:

  • To remove two deprecated files and any declarations of the functions in them
  • To move drawBlankEdges to the Cubes/ directory
  • Some small changes to the implementation of the StatsContainer? functions.
  • Creation of Utils/devel.hh to hide functions not used in Duchamp
  • To move the trimmedHist stats functions to their own file, again to hide them.
File size: 4.5 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   *  Takes a dimension array and data array as input (and Parameter set)
39   *  and searches for detections in a combination of 1D and 2D searches.
40   *  Returns a vector list of Detections.
41   *  No reconstruction is assumed to have taken place, so statistics are
42   *  calculated (using robust methods) from the data array itself.
43   * \param dim Array of dimension sizes for the data array.
44   * \param Array Array of data.
45   * \param par Param set defining how to do detection, and what a BLANK pixel is etc.
46   * \param stats The statistics that define what a detection is.
47   * \return Vector of detected objects.
48   */
49
50  vector <Detection> outputList;
51  long zdim = dim[2];
52  long xySize = dim[0] * dim[1];
53  int num = 0;
54
55  bool *doPixel = new bool[xySize];
56  int goodSize=0;
57  for(int npix=0; npix<xySize; npix++){
58    doPixel[npix] = false;
59    for(int z=0;z<zdim;z++){
60      doPixel[npix] = doPixel[npix] ||
61        (!par.isBlank(Array[npix]) && !par.isInMW(z));
62    }
63    // doPixel[i] is false only when there are no good pixels in spectrum
64    //  of pixel #i.
65  }
66
67  ProgressBar bar;
68  // FIRST SEARCH --  IN EACH SPECTRUM.
69  if(zdim>1){
70    if(par.isVerbose()) {
71      std::cout << "  1D: ";
72      bar.init(xySize);
73    }
74
75    for(int npix=0; npix<xySize; npix++){
76
77      if( par.isVerbose() ) bar.update(npix+1);
78
79      if(doPixel[npix]){
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->saveStats(stats);
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->setMinSize(par.getMinChannels());
92        spectrum->spectrumDetect();
93        num += spectrum->getNumObj();
94        for(int obj=0;obj<spectrum->getNumObj();obj++){
95          Detection *object = new Detection;
96          *object = spectrum->getObject(obj);
97          for(int pix=0;pix<object->getSize();pix++) {
98            // Fix up coordinates of each pixel to match original array
99            object->setZ(pix, object->getX(pix));
100            object->setX(pix, npix%dim[0]);
101            object->setY(pix, npix/dim[0]);
102          }
103          object->setOffsets(par);
104          object->calcParams();
105          mergeIntoList(*object,outputList,par);
106          delete object;
107        }
108        delete spectrum;
109      }
110    }
111
112    //    num = outputList.size();
113    if(par.isVerbose()) {
114      bar.fillSpace("Found ");
115      std::cout << num <<";" << std::flush;
116    }
117
118  }
119
120  // SECOND SEARCH --  IN EACH CHANNEL
121  if(par.isVerbose()){
122    std::cout << "  2D: ";
123    bar.init(zdim);
124  }
125 
126  num = 0;
127
128  for(int z=0; z<zdim; z++){
129
130    if( par.isVerbose() ) bar.update(z+1);
131
132    if(!par.isInMW(z)){
133
134      long *imdim = new long[2];
135      imdim[0] = dim[0]; imdim[1] = dim[1];
136      Image *channelImage = new Image(imdim);
137      delete [] imdim;
138      channelImage->saveParam(par);
139      channelImage->saveStats(stats);
140      channelImage->extractImage(Array,dim,z);
141      channelImage->setMinSize(par.getMinPix());
142      channelImage->lutz_detect();
143      num += channelImage->getNumObj();
144      for(int obj=0;obj<channelImage->getNumObj();obj++){
145        Detection *object = new Detection;
146        *object = channelImage->getObject(obj);
147        // Fix up coordinates of each pixel to match original array
148        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
149        object->setOffsets(par);
150        object->calcParams();
151        mergeIntoList(*object,outputList,par);
152        delete object;
153      }
154      delete channelImage;
155    }
156
157  }
158
159  if(par.isVerbose()){
160    bar.fillSpace("Found ");
161    std::cout << num << ".\n";
162  }
163
164  delete [] doPixel;
165 
166  return outputList;
167}
Note: See TracBrowser for help on using the repository browser.