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

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

A large commit based around a few changes:

  • Implemented the new SNRpeak column, defining it in columns.cc and printing it out in outputDetection.cc.
  • Corrected a bug in the subsection parsing that miscalculated the pixel offset when "*" was given as an axis range.
  • setupFDR now calculates the flux threshold so this can be reported.
  • The object flags now distinguish between spatial edge and spectral edge locations.
  • Other minor changes for clarity's sake.
File size: 5.4 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <vector>
5#include <duchamp.hh>
6#include <param.hh>
7#include <Cubes/cubes.hh>
8#include <Utils/utils.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//   long fullSize = zdim * xySize;
49  int num = 0;
50
51//   float blankPixValue = par.getBlankPixVal();
52//   bool *isGood = new bool[fullSize];
53//   for(int pos=0;pos<fullSize;pos++){
54//     isGood[pos] = !par.isBlank(Array[pos]) && !par.isInMW(pos/xySize);
55//   }
56  bool *doPixel = new bool[xySize];
57  int goodSize=0;
58  for(int npix=0; npix<xySize; npix++){
59    doPixel[npix] = false;
60    for(int z=0;z<zdim;z++){
61      doPixel[npix] = doPixel[npix] ||
62        (!par.isBlank(Array[npix]) && !par.isInMW(z));
63    }
64    // doPixel[i] is false only when there are no good pixels in spectrum
65    //  of pixel #i.
66  }
67
68  ProgressBar bar;
69  // FIRST SEARCH --  IN EACH SPECTRUM.
70  if(zdim>1){
71    if(par.isVerbose()) {
72      std::cout << "  1D: ";
73      bar.init(xySize);
74    }
75
76    for(int npix=0; npix<xySize; npix++){
77
78      if( par.isVerbose() ) bar.update(npix+1);
79
80      if(doPixel[npix]){
81
82        float *spec = new float[zdim];
83//      float specMedian,specSigma;
84//      goodSize=0;
85//      for(int z=0;z<zdim;z++)
86//        if(isGood[z*xySize+npix]) spec[goodSize++] = Array[z*xySize+npix];
87//      findMedianStats(spec,goodSize,specMedian,specSigma);
88//      specSigma /= correctionFactor;
89
90
91        long *specdim = new long[2];
92        specdim[0] = zdim; specdim[1]=1;
93        Image *spectrum = new Image(specdim);
94        delete [] specdim;
95        spectrum->saveParam(par);
96        spectrum->saveStats(stats);
97        spectrum->pars().setBeamSize(2.);
98        // beam size: for spectrum, only neighbouring channels correlated
99        spectrum->extractSpectrum(Array,dim,npix);
100        spectrum->removeMW(); // only works if flagMW is true
101//      spectrum->setStats(specMedian,specSigma,par.getCut());
102//      if(par.getFlagFDR()) spectrum->setupFDR();
103        spectrum->setMinSize(par.getMinChannels());
104        spectrum->spectrumDetect();
105        num += spectrum->getNumObj();
106        for(int obj=0;obj<spectrum->getNumObj();obj++){
107          Detection *object = new Detection;
108          *object = spectrum->getObject(obj);
109          for(int pix=0;pix<object->getSize();pix++) {
110            // Fix up coordinates of each pixel to match original array
111            object->setZ(pix, object->getX(pix));
112            object->setX(pix, npix%dim[0]);
113            object->setY(pix, npix/dim[0]);
114          }
115          object->addOffsets(par);
116          object->calcParams();
117          mergeIntoList(*object,outputList,par);
118          delete object;
119        }
120        delete spectrum;
121      }
122    }
123
124    //    num = outputList.size();
125    if(par.isVerbose()) {
126      bar.rewind();
127      std::cout <<"Found " << num <<";" << std::flush;
128    }
129
130  }
131
132  // SECOND SEARCH --  IN EACH CHANNEL
133  if(par.isVerbose()){
134    std::cout << "  2D: ";
135    bar.init(zdim);
136  }
137 
138  num = 0;
139
140  for(int z=0; z<zdim; z++){
141
142    if( par.isVerbose() ) bar.update(z+1);
143
144    if(!par.isInMW(z)){
145
146      float *image = new float[xySize];
147//       float imageMedian, imageSigma;
148//       goodSize=0;
149//       for(int npix=0; npix<xySize; npix++) {
150//      if(isGood[z*xySize + npix])
151//        image[goodSize++] = Array[z*xySize + npix];
152//       }
153//       findMedianStats(image,goodSize,imageMedian,imageSigma);
154//       imageSigma /= correctionFactor;
155
156      long *imdim = new long[2];
157      imdim[0] = dim[0]; imdim[1] = dim[1];
158      Image *channelImage = new Image(imdim);
159      delete [] imdim;
160      channelImage->saveParam(par);
161      channelImage->saveStats(stats);
162      channelImage->extractImage(Array,dim,z);
163//       channelImage->setStats(imageMedian,imageSigma,par.getCut());
164//       if(par.getFlagFDR()) channelImage->setupFDR();
165      channelImage->setMinSize(par.getMinPix());
166      channelImage->lutz_detect();
167      num += channelImage->getNumObj();
168      for(int obj=0;obj<channelImage->getNumObj();obj++){
169        Detection *object = new Detection;
170        *object = channelImage->getObject(obj);
171        // Fix up coordinates of each pixel to match original array
172        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
173        object->addOffsets(par);
174        object->calcParams();
175        mergeIntoList(*object,outputList,par);
176        delete object;
177      }
178      delete channelImage;
179    }
180
181  }
182
183  if(par.isVerbose()){
184    bar.rewind();
185    std::cout << "Found " << num << ".";
186    printSpace(44);
187    std::cout << std::endl << std::flush;
188  }
189
190//   delete [] isGood;
191  delete [] doPixel;
192 
193  return outputList;
194}
Note: See TracBrowser for help on using the repository browser.