source: tags/release-1.0.7/src/Cubes/CubicSearch.cc

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

Summary:

  • Fixed the scale bar plotting for the spectral output, so that it can deal properly with very fine angular scales.
    • Improved the loop in Cube::drawScale
    • Included code in angularSeparation to deal with finely-separated positions.
  • Moved the ProgressBar? class to a new header file Utils/feedback.hh from duchamp.hh
    • Updated #include statements in many files
  • Fixed allocation bug in param copy constructor (related to offsets array).
File size: 4.3 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   * Cube::SimpleSearch3D()
15   *  A front end to the cubic searching routine that does not
16   *  involve any wavelet reconstruction.
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  this->setCubeStats();
23   
24  this->objectList = search3DArray(this->axisDim,this->array,
25                                   this->par,this->Stats);
26
27  this->updateDetectMap();
28  if(this->par.getFlagLog()) this->logDetectionList();
29
30}
31
32
33vector <Detection> search3DArray(long *dim, float *Array, Param &par,
34                                 StatsContainer<float> &stats)
35{
36  /**
37   * cubicSearch
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   */
44
45  vector <Detection> outputList;
46  long zdim = dim[2];
47  long xySize = dim[0] * dim[1];
48  int num = 0;
49
50  bool *doPixel = new bool[xySize];
51  int goodSize=0;
52  for(int npix=0; npix<xySize; npix++){
53    doPixel[npix] = false;
54    for(int z=0;z<zdim;z++){
55      doPixel[npix] = doPixel[npix] ||
56        (!par.isBlank(Array[npix]) && !par.isInMW(z));
57    }
58    // doPixel[i] is false only when there are no good pixels in spectrum
59    //  of pixel #i.
60  }
61
62  ProgressBar bar;
63  // FIRST SEARCH --  IN EACH SPECTRUM.
64  if(zdim>1){
65    if(par.isVerbose()) {
66      std::cout << "  1D: ";
67      bar.init(xySize);
68    }
69
70    for(int npix=0; npix<xySize; npix++){
71
72      if( par.isVerbose() ) bar.update(npix+1);
73
74      if(doPixel[npix]){
75
76        long *specdim = new long[2];
77        specdim[0] = zdim; specdim[1]=1;
78        Image *spectrum = new Image(specdim);
79        delete [] specdim;
80        spectrum->saveParam(par);
81        spectrum->saveStats(stats);
82        spectrum->pars().setBeamSize(2.);
83        // beam size: for spectrum, only neighbouring channels correlated
84        spectrum->extractSpectrum(Array,dim,npix);
85        spectrum->removeMW(); // only works if flagMW is true
86        spectrum->setMinSize(par.getMinChannels());
87        spectrum->spectrumDetect();
88        num += spectrum->getNumObj();
89        for(int obj=0;obj<spectrum->getNumObj();obj++){
90          Detection *object = new Detection;
91          *object = spectrum->getObject(obj);
92          for(int pix=0;pix<object->getSize();pix++) {
93            // Fix up coordinates of each pixel to match original array
94            object->setZ(pix, object->getX(pix));
95            object->setX(pix, npix%dim[0]);
96            object->setY(pix, npix/dim[0]);
97          }
98          object->addOffsets(par);
99          object->calcParams();
100          mergeIntoList(*object,outputList,par);
101          delete object;
102        }
103        delete spectrum;
104      }
105    }
106
107    //    num = outputList.size();
108    if(par.isVerbose()) {
109      bar.rewind();
110      std::cout <<"Found " << num <<";" << std::flush;
111    }
112
113  }
114
115  // SECOND SEARCH --  IN EACH CHANNEL
116  if(par.isVerbose()){
117    std::cout << "  2D: ";
118    bar.init(zdim);
119  }
120 
121  num = 0;
122
123  for(int z=0; z<zdim; z++){
124
125    if( par.isVerbose() ) bar.update(z+1);
126
127    if(!par.isInMW(z)){
128
129      long *imdim = new long[2];
130      imdim[0] = dim[0]; imdim[1] = dim[1];
131      Image *channelImage = new Image(imdim);
132      delete [] imdim;
133      channelImage->saveParam(par);
134      channelImage->saveStats(stats);
135      channelImage->extractImage(Array,dim,z);
136      channelImage->setMinSize(par.getMinPix());
137      channelImage->lutz_detect();
138      num += channelImage->getNumObj();
139      for(int obj=0;obj<channelImage->getNumObj();obj++){
140        Detection *object = new Detection;
141        *object = channelImage->getObject(obj);
142        // Fix up coordinates of each pixel to match original array
143        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
144        object->addOffsets(par);
145        object->calcParams();
146        mergeIntoList(*object,outputList,par);
147        delete object;
148      }
149      delete channelImage;
150    }
151
152  }
153
154  if(par.isVerbose()){
155    bar.rewind();
156    std::cout << "Found " << num << ".";
157    printSpace(44);
158    std::cout << std::endl << std::flush;
159  }
160
161  delete [] doPixel;
162 
163  return outputList;
164}
Note: See TracBrowser for help on using the repository browser.