source: branches/fitshead-branch/Cubes/cubicSearch.cc @ 1441

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

Two sets of large changes:
1) Added reconDim, to select which dimension of reconstruction to use.
2) Changed the way the MW channels are dealt with -- now not set to 0. but

simply ignored for searching purposes.

Summary of changes for each file:
duchamp.hh -- added keyword info for reconDim
param.hh -- Introduced reconDim and flagUsingBlank and isInMW.
param.cc -- Introduced reconDim and flagUsingBlank: initialisation etc commands
InputComplete? -- Added reconDim info
mainDuchamp.cc -- Removed the removeMW call. Changed search function names
docs/Guide.tex -- New code to deal with changes: reconDim, MW removal,

up-to-date output examples, better hints & notes section

Detection/thresholding_functions.cc -- minor typo correction

Cubes/cubes.hh -- added isBlank and removeMW functions in Image class, and

renamed search function prototypes

Cubes/cubes.cc -- added removeMW function for Image class, cleaned up

Cube::removeMW as well (although now not used)

Cubes/outputSpectra.cc -- Improved use of isBlank and isInMW functions: now

show MW channels but don't use them in calculating
the flux range

Cubes/getImage.cc -- added line to indicate whether the Param's blank value

is being used, rather than the FITS header.

Cubes/cubicSearch.cc -- renamed functions: front end is now CubicSearch?, and

searching function is search3DArray.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

Cubes/saveImage.cc -- added code for saving reconDim info
Cubes/readRecon.cc -- added code for reading reconDim info (and added status

intialisations before all cfitsio commands)

ATrous/ReconSearch.cc -- renamed functions: front end is now ReconSearch?, and

searching function is searchReconArray.
Using reconDim to decide which reconstruction to use.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

ATrous/atrous_1d_reconstruct.cc -- using Median stats
ATrous/atrous_2d_reconstruct.cc -- made code up to date, to conform with 1- &

3-d code. Removed boundary conditions.

ATrous/atrous_3d_reconstruct.cc -- corrected typo (avGapY /= float(xdim)).

Using median stats.

Cubes/cubicSearchNMerge.cc -- Deleted. (not used)
Cubes/readParams.cc -- Deleted. (not used)

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