source: trunk/src/Detection/detection.hh @ 189

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

A suite of changes aimed at calculating a cube-wide threshold, rather than individual thresholds for each channel map & spectrum. Summary of changes:

  • New Cube::setCubeStats() function, that stores the cube's stats in Cube member variables (mean, median, stddev, madfm).
  • New Parameter threshold, which can be entered by the user.
  • Make use of the cube statistics in the search functions, so that the Image class receives the correct information. Some tidying up of the CubicSearch? and ReconSearch? functions as well.
  • Changing the thresholding functions to be able to use the new threshold parameter.

Warning though -- the FDR setup doesn't quite work at this stage!

File size: 10.9 KB
Line 
1#ifndef DETECTION_H
2#define DETECTION_H
3
4#include <iostream>
5#include <string>
6#include <vector>
7#include <param.hh>
8#ifndef COLUMNS_H
9#include <Detection/columns.hh>
10#endif
11#include <Utils/utils.hh>
12
13using std::string;
14using std::vector;
15using namespace Column;
16
17/**
18 * Voxel class
19 *  A 3-dimensional pixel, with x,y,z position + flux
20 */
21
22class Voxel
23{
24public:
25  Voxel(){};
26  Voxel(long x, long y, long z, float f){ itsX=x; itsY=y; itsZ=z; itsF=f;};
27  virtual ~Voxel(){};
28  friend class Detection;
29  // accessor functions
30  void   setX(long x){itsX = x;};
31  void   setY(long y){itsY = y;};
32  void   setZ(long z){itsZ = z;};
33  void   setF(float f){itsF = f;};
34  void   setXY(long x, long y){itsX = x; itsY = y;};
35  void   setXYZ(long x, long y, long z){itsX = x; itsY = y; itsZ = z;};
36  void   setXYF(long x, long y, float f){itsX = x; itsY = y; itsF = f;};
37  void   setXYZF(long x, long y, long z, float f){itsX = x; itsY = y; itsZ = z; itsF = f;};
38  long   getX(){return itsX;};
39  long   getY(){return itsY;};
40  long   getZ(){return itsZ;};
41  float  getF(){return itsF;};
42  //
43  friend std::ostream& operator<< ( std::ostream& theStream, Voxel& vox);
44  //
45protected:
46  long  itsX;         // x-position of pixel
47  long  itsY;         // y-position of pixel
48  long  itsZ;         // z-position of pixel
49  float itsF;         // flux of pixel
50};
51
52/**
53 * Pixel class
54 *  A 2-dimensional type of voxel, with just x & y position + flux
55 */
56
57
58class Pixel : public Voxel
59{
60public:
61  Pixel(){itsZ=0;};
62  Pixel(long x, long y, float f){ itsX=x; itsY=y; itsF=f; itsZ=0;};
63  virtual ~Pixel(){};
64  // accessor functions
65  void  setXY(long x, long y){itsX = x; itsY = y;};
66  void  setXYF(long x, long y, float f){itsX = x; itsY = y; itsF = f;};
67
68};
69
70/**
71 * Detection class
72 *  A detected object, featuring:
73 *   a vector of voxels, centroid positions, total & peak fluxes
74 *   the possibility of WCS-calculated parameters (RA, Dec, velocity) etc.
75 */
76
77class Detection
78{
79public:
80  Detection(){
81    flagWCS=false; negativeSource = false; flagText="";
82    xcentre = ycentre = zcentre = totalFlux = peakFlux = 0.;
83    xmin=xmax=ymin=ymax=zmin=zmax=0;
84  };
85  Detection(long numPix){
86    vector <Voxel> pix(numPix); flagWCS = false; negativeSource = false;
87  };
88  virtual ~Detection(){};
89
90  void   addPixel(Voxel point){pix.push_back(point);};
91  Voxel  getPixel(long pixNum){return pix[pixNum];};
92  int    getSize(){return pix.size();};
93  int    getSpatialSize();// in detection.cc
94  //
95  long   getX(long pixCount){return pix[pixCount].getX();};
96  void   setX(long pixCount, long x){pix[pixCount].setX(x);};
97  long   getY(long pixCount){return pix[pixCount].getY();};
98  void   setY(long pixCount, long y){pix[pixCount].setY(y);};
99  long   getZ(long pixCount){return pix[pixCount].getZ();};
100  void   setZ(long pixCount, long z){pix[pixCount].setZ(z);};
101  float  getF(long pixCount){return pix[pixCount].getF();};
102  void   setF(long pixCount, float f){pix[pixCount].setF(f);};
103  //
104  long   getXOffset(){return xSubOffset;};
105  void   setXOffset(long o){xSubOffset = o;};
106  long   getYOffset(){return ySubOffset;};
107  void   setYOffset(long o){ySubOffset = o;};
108  long   getZOffset(){return zSubOffset;};
109  void   setZOffset(long o){zSubOffset = o;};
110  //
111  float  getXcentre(){return xcentre;};
112  void   setXcentre(float x){xcentre = x;};
113  float  getYcentre(){return ycentre;};
114  void   setYcentre(float y){ycentre = y;};
115  float  getZcentre(){return zcentre;};
116  void   setCentre(float x, float y){xcentre = x; ycentre = y;};
117  float  getTotalFlux(){return totalFlux;};
118  void   setTotalFlux(float f){totalFlux = f;};
119  float  getIntegFlux(){return intFlux;};
120  void   setIntegFlux(float f){intFlux = f;};
121  float  getPeakFlux(){return peakFlux;};
122  void   setPeakFlux(float f){peakFlux = f;};
123  long   getXPeak(){return xpeak;};
124  void   setXPeak(long x){xpeak = x;};
125  long   getYPeak(){return ypeak;};
126  void   setYPeak(long y){ypeak = y;};
127  long   getZPeak(){return zpeak;};
128  void   setZPeak(long z){zpeak = z;};
129  bool   isNegative(){return negativeSource;};
130  void   setNegative(bool f){negativeSource = f;};
131  string getFlagText(){return flagText;};
132  void   setFlagText(string s){flagText = s;};
133  void   addToFlagText(string s){flagText += s;};
134  //
135  long   getXmin(){return xmin;};
136  long   getYmin(){return ymin;};
137  long   getZmin(){return zmin;};
138  long   getXmax(){return xmax;};
139  long   getYmax(){return ymax;};
140  long   getZmax(){return zmax;};
141  //
142  bool   isWCS(){return flagWCS;};
143  string getName(){return name;};
144  void   setName(string s){name = s;};
145  string getRAs(){return raS;};
146  void   setRAs(string s){raS = s;};
147  string getDecs(){return decS;};
148  void   setDecs(string s){decS = s;};
149  float  getRA(){return ra;};
150  void   setRA(float f){ra = f;};
151  float  getDec(){return dec;};
152  void   setDec(float f){dec = f;};
153  float  getRAWidth(){return raWidth;};
154  void   setRAWidth(float f){raWidth = f;};
155  float  getDecWidth(){return decWidth;};
156  void   setDecWidth(float f){decWidth = f;};
157//   string getLNGtype(){return lngtype;};
158//   void   setLNGtype(string s){lngtype = s;};
159//   string getLATtype(){return lattype;};
160//   void   setLATtype(string s){lattype = s;};
161//   string getZtype(){return ztype;};
162//   void   setZtype(string s){ztype = s;};
163//   float  getNuRest(){return nuRest;};
164//   void   setNuRest(float f){nuRest = f;};
165  float  getVel(){return vel;};
166  void   setVel(float f){vel = f;};
167  float  getVelWidth(){return velWidth;};
168  void   setVelWidth(float f){velWidth = f;};
169  float  getVelMin(){return velMin;};
170  void   setVelMin(float f){velMin = f;};
171  float  getVelMax(){return velMax;};
172  void   setVelMax(float f){velMax = f;};
173  int    getID(){return id;};
174  void   setID(int i){id = i;};
175  //
176  int    getPosPrec(){return posPrec;};
177  void   setPosPrec(int i){posPrec=i;};
178  int    getXYZPrec(){return xyzPrec;};
179  void   setXYZPrec(int i){xyzPrec=i;};
180  int    getFintPrec(){return fintPrec;};
181  void   setFintPrec(int i){fintPrec=i;};
182  int    getFpeakPrec(){return fpeakPrec;};
183  void   setFpeakPrec(int i){fpeakPrec=i;};
184  int    getVelPrec(){return velPrec;};
185  void   setVelPrec(int i){velPrec=i;};
186  //
187  void   addAnObject(Detection &toAdd);
188  void   calcWCSparams(FitsHeader &head);
189  float  getIntegFlux(FitsHeader &head);
190  void   calcParams();
191  void   clearDetection(){this->pix.clear();};
192  void   addOffsets(Param &par);
193  void   SortByZ();   // in Detection/sorting.cc
194  bool   hasEnoughChannels(int minNumber);
195  // Text Output -- all in Detection/outputDetection.cc
196  string outputLabelWCS();
197  string outputLabelPix();
198  string outputLabelInfo();
199  void   outputDetectionTextHeader(std::ostream &stream, vector<Col> columns);
200  void   outputDetectionTextWCS(std::ostream &stream, vector<Col> columns);
201  void   outputDetectionText(std::ostream &stream, vector<Col> columns,
202                             int idNumber);
203  // For plotting routines...
204  void   drawBorders(int xoffset, int yoffset); // in Cubes/drawMomentCutout.cc
205  //
206  friend std::ostream& operator<< ( std::ostream& theStream, Detection& obj);
207  //
208private:
209  vector <Voxel> pix;         // array of pixels
210  float          xcentre;     // x-value of centre pixel of object
211  float          ycentre;     // y-value of centre pixel of object
212  float          zcentre;     // z-value of centre pixel of object
213  long           xmin,xmax;   // min and max x-values of object
214  long           ymin,ymax;   // min and max y-values of object
215  long           zmin,zmax;   // min and max z-values of object
216  // Subsection offsets
217  long           xSubOffset;  // The x-offset from the subsectioned cube
218  long           ySubOffset;  // The y-offset from the subsectioned cube
219  long           zSubOffset;  // The z-offset from the subsectioned cube
220  // Flux related
221  float          totalFlux;   // sum of the fluxes of all the pixels
222  float          intFlux;     // integrated flux
223                              //   --> involves integration over velocity.
224  float          peakFlux;    // maximum flux over all the pixels
225  long           xpeak,ypeak,zpeak; // location of peak flux
226  bool           negativeSource; // is the source a negative feature?
227  string         flagText;    // any warning flags about the quality of
228                              //   the detection.
229  // WCS related
230  int            id;          // ID -- generally number in list
231  string         name;        // IAU-style name (based on position)
232  bool           flagWCS;     // A flag indicating whether the WCS parameters
233                              //  have been set.
234  string         raS;         // Central Right Ascension (or Longitude) in
235                              //  form 12:34:23
236  string         decS;        // Central Declination(or Latitude), in
237                              //  form -12:23:34
238  float          ra;          // Central Right Ascension in degrees
239  float          dec;         // Central Declination in degrees
240  float          raWidth;     // Width of detection in RA direction in arcmin
241  float          decWidth;    // Width of detection in Dec direction in arcmin
242  string         specUnits;   // Units of the spectral dimension
243  string         fluxUnits;   // Units of flux
244  string         intFluxUnits;// Units of integrated flux
245  string         lngtype;     // Type of longitude axis (RA/GLON)
246  string         lattype;     // Type of latitude axis (DEC/GLAT)
247//   string         ztype;            // Type of z-axis (FREQ/VEL/...)
248//   float          nuRest;      // Rest frequency
249  float          vel;         // Central velocity (from zCentre)
250  float          velWidth;    // Full velocity width
251  float          velMin;      // Minimum velocity
252  float          velMax;      // Maximum velocity
253  //  The next four are the precision of values printed in the spectral plots
254  int            posPrec;     // Precision of WCS positional values
255  int            xyzPrec;     // Precision of pixel positional values
256  int            fintPrec;    // Precision of F_int/F_tot values
257  int            fpeakPrec;   // Precision of F_peak values
258  int            velPrec;     // Precision of velocity values.
259
260};
261
262/****************************************************************/
263//////////////////////////////////////////////////////
264// Prototypes for functions that use above classes
265//////////////////////////////////////////////////////
266
267void SortByZ(vector <Detection> &inputList);
268void SortByVel(vector <Detection> &inputList);
269Detection combineObjects(Detection &first, Detection &second);
270vector <Detection> combineLists(vector <Detection> &first,
271                                vector <Detection> &second);
272
273bool areClose(Detection &object1, Detection &object2, Param &par);
274void mergeIntoList(Detection &object, vector <Detection> &objList, Param &par);
275void mergeList(vector<Detection> &objList, Param &par);    //in Cubes/Merger.cc
276void finaliseList(vector<Detection> &objList, Param &par); //in Cubes/Merger.cc
277void ObjectMerger(vector<Detection> &objList, Param &par); //in Cubes/Merger.cc
278
279// GENERIC DETECTION TESTS  -- in thresholding_functions.cc
280bool isDetection(float value, float mean, float sigma, float cut);
281bool isDetection(float value, float threshold);
282
283#endif
Note: See TracBrowser for help on using the repository browser.