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

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

A large commit, based on improving memory usage, allocation, etc:

  • src/param.hh :
    • Added a delete command for the offsets array in Param. Keep track of size via new sizeOffsets variable.
    • Changed "wcsprm" to "struct wcsprm", for clarity.
    • Put wcsvfree in the FitsHeader? destructor so that memory is deallocated correctly.
  • src/param.cc :
    • Improved the FitsHeader? constructor functions, so that memory for the wcsprm structures is allocated appropriately.
    • Other wcsprm-related tweaks.
    • Included code for sizeOffsets -- the size of the offsets array in Param, so that we can properly deallocate its memory in the destructor function.
  • src/FitsIO/subsection.cc : Changed "wcsprm" to "struct wcsprm", for clarity, and added a sizeOffsets to track the memory allocation for offsets.
  • src/FitsIO/dataIO.cc : renamed the local variable array to pixarray so that there is no confusion. Added delete[] commands for local arrays.
  • src/FitsIO/wcsIO.cc : Improved the struct wcsprm memory allocation. Now using a local wcs variable so that we don't get confusion with the FitsHeader? one.
  • src/Utils/wcsFunctions.cc : changed "wcsprm" to "struct wcsprm", for clarity.
  • src/Cubes/CubicSearch.cc : removed two allocation calls (to new) that were not needed, as well as unused commented-out code.
  • src/Cubes/plotting.cc :
    • Corrected the way the detection map is worked out and the scale bar range calculated.
    • Changed "wcsprm" to "struct wcsprm", for clarity.
  • src/duchamp.hh : better implementation of the rewind() and remove() functions for ProgressBar?
  • src/Utils/getStats.cc : minor diffs
  • src/Utils/utils.hh : changed prototypes
  • src/Cubes/cubes.cc : Changed the way the setCubeStats() function works, so that stats aren't needlessly calculated if the threshold has already been specified.
  • src/Cubes/cubes.hh : minor presentation changes
  • src/Cubes/drawMomentCutout.cc : Tried to improve the scale-bar drawing function, to cope with very high angular resolution data. Not quite working properly yet.
  • src/Cubes/outputSpectra.cc : Corrected the flux labels so that the appropriate units are used, and not just Jy or Jy/beam.
File size: 4.5 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        long *specdim = new long[2];
83        specdim[0] = zdim; specdim[1]=1;
84        Image *spectrum = new Image(specdim);
85        delete [] specdim;
86        spectrum->saveParam(par);
87        spectrum->saveStats(stats);
88        spectrum->pars().setBeamSize(2.);
89        // beam size: for spectrum, only neighbouring channels correlated
90        spectrum->extractSpectrum(Array,dim,npix);
91        spectrum->removeMW(); // only works if flagMW is true
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      bar.rewind();
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    bar.init(zdim);
125  }
126 
127  num = 0;
128
129  for(int z=0; z<zdim; z++){
130
131    if( par.isVerbose() ) bar.update(z+1);
132
133    if(!par.isInMW(z)){
134
135      long *imdim = new long[2];
136      imdim[0] = dim[0]; imdim[1] = dim[1];
137      Image *channelImage = new Image(imdim);
138      delete [] imdim;
139      channelImage->saveParam(par);
140      channelImage->saveStats(stats);
141      channelImage->extractImage(Array,dim,z);
142      channelImage->setMinSize(par.getMinPix());
143      channelImage->lutz_detect();
144      num += channelImage->getNumObj();
145      for(int obj=0;obj<channelImage->getNumObj();obj++){
146        Detection *object = new Detection;
147        *object = channelImage->getObject(obj);
148        // Fix up coordinates of each pixel to match original array
149        for(int pix=0;pix<object->getSize();pix++) object->setZ(pix, z);
150        object->addOffsets(par);
151        object->calcParams();
152        mergeIntoList(*object,outputList,par);
153        delete object;
154      }
155      delete channelImage;
156    }
157
158  }
159
160  if(par.isVerbose()){
161    bar.rewind();
162    std::cout << "Found " << num << ".";
163    printSpace(44);
164    std::cout << std::endl << std::flush;
165  }
166
167//   delete [] isGood;
168  delete [] doPixel;
169 
170  return outputList;
171}
Note: See TracBrowser for help on using the repository browser.