source: trunk/src/Detection/sorting.cc @ 190

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

Large commit. The addition of a new Statistics namespace & class, plus a number of changes to the code to make the cube-wide statistics calculation work. The FDR calculations are incorporated into the new class, and a number of functions have been made into templates to ease the calculations. Details follow:

  • New namespace and class (StatsContainer? -- templated) in Statistics.hh, that holds mean,median,stddev & madfm, and provide accessor and calculator functions for these. It also holds the threshold values for sigma-clipping and FDR methods, as well as the PValue evaluation functions
  • The correctionFactor incorporated into the namespace, and given a conversion function that other functions can call (eg. the atrous_Xd_reconstruct functions).
  • Templated the statistics functions in getStats.cc.
  • Templated the sort functions, and made swap an inline one defined in utils.hh.
  • A number of changes to cubes.cc and cubes.hh:
    • DataArray? gains a StatsContainer? object, to store stats info.
    • Image has lost its pValue array (not needed as we calculate on the fly) and mask array (not used).
    • Image has also lost all its stats members, but keeps minPix.
    • Functions to go are Image::maskObject, Image::findStats. Removed calls to the former. Latter never used.
    • Cube::setCubeStats does the cube-wide stats calculations, including setupFDR (now a Cube function).
    • Cube loses the specMean etc arrays.
  • The Search functions (ReconSearch? and CubicSearch?) changed to accommodate the exchange of StatsContainer? objects. This changed the prototypes as well.
  • The growObject function incorporates the new StatsContainer? object.
  • Minor change to Merger, in the preparation for calling growObject.
  • A new par introduced: flagUserThreshold -- set to true when the user enters a value for the threshold.
  • Removed thresholding_functions.cc and incorporated its functions into cubes.cc and cubes.hh.
File size: 2.7 KB
Line 
1#include <vector>
2#include <Detection/detection.hh>
3#include <Utils/utils.hh>
4
5using std::vector;
6
7void Detection::SortByZ()
8{
9  /**
10   * Detection::SortByZ():
11   *   A Function that takes a Detection and
12   *   sorts the pixels by z-pixel
13   *   Upon return, the inputList is sorted.
14   */
15
16  long size = this->pix.size();
17  float *positions = new float[size];
18  float *z = new float[size];
19 
20  for(int i=0;i<size;i++){
21    positions[i] = float(i);
22    z[i] = this->pix[i].getZ();
23  }
24
25  sort(z, positions, 0, size);
26 
27  vector <Voxel> sorted(size);
28  for(int i=0;i<size;i++) sorted[i] = this->pix[ int(positions[i]) ] ;
29
30  delete [] positions;
31  delete [] z;
32
33  for(int i=0;i<size;i++){
34    this->pix.erase(this->pix.begin()+i);
35    this->pix.insert(this->pix.begin()+i, sorted[i]);
36  }
37
38  sorted.clear();
39 
40}
41
42/**
43 * SortByZ(vector <Detection> &):
44 *   A Function that takes a list of Detections and
45 *   sorts them in order of increasing z-pixel value.
46 *   Upon return, the inputList is sorted.
47 */
48
49void SortByZ(vector <Detection> &inputList)
50{
51
52  long size = inputList.size();
53  float *positions = new float[size];
54  float *z = new float[size];
55 
56  for(int i=0;i<size;i++){
57    positions[i] = float(i);
58    Detection *obj = new Detection;
59    *obj = inputList[i];
60    z[i] = obj->getZcentre();
61    delete obj;
62  }
63
64  sort(z, positions, 0, size);
65 
66  vector <Detection> sorted;
67  for(int i=0;i<size;i++) sorted.push_back( inputList[ int(positions[i]) ] );
68
69  delete [] positions;
70  delete [] z;
71
72  inputList.clear();
73  for(int i=0;i<size;i++) inputList.push_back( sorted[i] );
74  sorted.clear();
75 
76}
77
78/**
79 * SortByVel(vector <Detection> &):
80 *   A Function that takes a list of Detections and
81 *   sorts them in order of increasing velocity.
82 *   Every member of the vector needs to have WCS defined, (and if so,
83 *     then vel is assumed to be defined for all), otherwise no sorting
84 *     is done.
85 *   Upon return (if all WCS are good), the inputList is sorted.
86 */
87
88void SortByVel(vector <Detection> &inputList)
89{
90
91  bool isGood = true;
92  for(int i=0;i<inputList.size();i++) isGood = isGood && inputList[i].isWCS();
93
94  if(isGood){
95
96    long size = inputList.size();
97    float *positions = new float[size];
98    float *vel = new float[size];
99 
100    for(int i=0;i<size;i++){
101      positions[i] = float(i);
102      Detection *obj = new Detection;
103      *obj = inputList[i];
104      vel[i] = obj->getVel();
105      delete obj;
106    }
107
108    sort(vel, positions, 0, size);
109 
110    vector <Detection> sorted;
111    for(int i=0;i<size;i++) sorted.push_back( inputList[ int(positions[i]) ] );
112
113    delete [] positions;
114    delete [] vel;
115
116    inputList.clear();
117    for(int i=0;i<size;i++) inputList.push_back( sorted[i] );
118    sorted.clear();
119 
120  }
121
122
Note: See TracBrowser for help on using the repository browser.