source: tags/release-1.0.6/src/Cubes/cubes.hh @ 1323

Last change on this file since 1323 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: 13.2 KB
Line 
1#ifndef CUBES_H
2#define CUBES_H
3
4#include <iostream>
5#include <string>
6#include <vector>
7
8#ifndef PARAM_H
9#include <param.hh>
10#endif
11#ifndef DETECTION_H
12#include <Detection/detection.hh>
13#endif
14#ifndef COLUMNS_H
15#include <Detection/columns.hh>
16#endif
17#ifndef PLOTS_H
18#include <Cubes/plots.hh>
19#endif
20#ifndef STATS_H
21#include <Utils/Statistics.hh>
22#endif
23
24using std::string;
25using std::vector;
26using namespace Column;
27using namespace Statistics;
28
29/****************************************************************/
30/////////////////////////////////////////////////////////////
31//// Definition of an n-dimensional data array:
32////     array of pixel values, size & dimensions
33////     array of Detection objects
34/////////////////////////////////////////////////////////////
35
36
37class DataArray
38{
39public:
40  DataArray(){numDim=0; numPixels=0;};
41  DataArray(short int nDim){numDim=nDim; numPixels=0;};
42  DataArray(short int nDim, long size);
43  DataArray(short int nDim, long *dimensions);
44  virtual ~DataArray();
45  // Size and Dimension related
46  long                getDimX(){if(numDim>0) return axisDim[0];else return 0;};
47  long                getDimY(){if(numDim>1) return axisDim[1];else return 1;};
48  long                getDimZ(){if(numDim>2) return axisDim[2];else return 1;};
49  void                getDim(long &x, long &y, long &z);
50  long                getSize(){return numPixels;};
51  short int           getNumDim(){return numDim;};
52  // Related to the various arrays
53  void                   getDimArray(long *output);
54  void                   getArray(float *output);
55  virtual void           saveArray(float *input, long size);
56  float                  getPixValue(long pos){return array[pos];};
57  void                   setPixValue(long pos, float f){array[pos] = f;};
58  // Related to the object lists
59  Detection              getObject(long number){return objectList[number];};
60  void                   addObject(Detection object);   
61                  // adds a single detection to the object list
62  vector <Detection>     getObjectList(){return objectList;};
63  void                   addObjectList(vector <Detection> newlist); 
64                  // adds all objects in a detection list to the object list
65  void                   addObjectOffsets();
66  long                   getNumObj(){return objectList.size();};
67  void                   clearDetectionList(){this->objectList.clear();};
68  // Parameter list related.
69  int                    readParam(string paramfile){
70    return par.readParams(paramfile);};
71  void                   showParam(std::ostream &stream){stream << par;};
72  Param                  getParam(){return par;};
73  void                   saveParam(Param newpar){par = newpar;};
74  Param&                 pars(){Param &rpar = par; return rpar;};
75  bool                   isBlank(int vox){return par.isBlank(array[vox]);};
76  // Statistics
77  StatsContainer<float> getStats(){return Stats;};
78  StatsContainer<float>& stats(){
79    StatsContainer<float> &rstats = Stats;
80    return rstats;
81  };
82  void saveStats(StatsContainer<float> newStats){
83    Stats = newStats;
84  };
85
86  bool isDetection(float value){
87    if(par.isBlank(value)) return false;
88    else return Stats.isDetection(value);
89  }; 
90// bool isDetection(long voxel)
91// {
92//   if(isBlank(voxel)) return false;
93//   else return Stats.isDetection(this->array[voxel]);
94// }
95
96  friend std::ostream& operator<< ( std::ostream& theStream, DataArray &array);
97
98protected:
99  short int               numDim;     // number of dimensions.
100  long                   *axisDim;    // array of dimensions of cube
101                                      //     (ie. how large in each direction).
102  long                    numPixels;  // total number of pixels in cube
103  float                  *array;      // array of data
104  vector <Detection>      objectList; // the list of detected objects
105  Param                   par;        // a parameter list.
106  StatsContainer<float>   Stats;      // The statistics for the dataArray
107};
108
109
110/****************************************************************/
111/////////////////////////////////////////////////////////////
112//// Definition of an image object (2D):
113////     a DataArray object
114////     arrays for: probability values (for FDR)
115////                 mask image to indicate location of objects
116////                 detected objects
117////     statistics information
118/////////////////////////////////////////////////////////////
119
120class Cube;
121class Image : public DataArray
122{
123public:
124  Image(){
125    numPixels=0;
126    numDim=2;};
127  Image(long nPix);
128  Image(long *dimensions);
129  virtual ~Image();
130
131  // Defining the array
132  void      saveArray(float *input, long size);
133  void      extractSpectrum(float *Array, long *dim, long pixel);
134  void      extractImage(float *Array, long *dim, long channel);
135  void      extractSpectrum(Cube &cube, long pixel);
136  void      extractImage(Cube &cube, long channel);
137  // Accessing the data.
138  float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
139  float     getPixValue(long pos){return array[pos];};
140  // the next few should have checks against array overflow...
141  void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
142  void      setPixValue(long pos, float f){array[pos] = f;};
143  bool      isBlank(int vox){return par.isBlank(array[vox]);};
144  bool      isBlank(long x,long y){return par.isBlank(array[y*axisDim[0]+x]);};
145
146  // Detection-related
147  void      lutz_detect();            // in Detection/lutz_detect.cc
148  void      spectrumDetect();         // in Detection/spectrumDetect.cc
149  int       getMinSize(){return minSize;};
150  void      setMinSize(int i){minSize=i;};
151  // the rest are in Detection/thresholding_functions.cc
152  bool      isDetection(long x, long y){
153    long voxel = y*axisDim[0] + x;
154    if(isBlank(x,y)) return false;
155    else return Stats.isDetection(array[voxel]);
156  }; 
157//     return DataArray::isDetection(array[voxel]);
158//   };
159
160  void      removeMW();
161 
162private:
163  int        minSize;    // the minimum number of pixels for a detection
164                         //  to be accepted.
165};
166
167/****************************************************************/
168/////////////////////////////////////////////////////////////
169//// Definition of an data-cube object (3D):
170////     a DataArray object limited to dim=3
171/////////////////////////////////////////////////////////////
172
173class Cube : public DataArray
174{
175public:
176  Cube(){numPixels=0; numDim=3; reconExists = false;};
177  Cube(long nPix);
178  Cube(long *dimensions);
179  virtual ~Cube();
180
181  // additional accessor functions
182  //       -- in Cubes/cubes.cc unless otherwise specified.
183
184  int     getCube(string fname);
185  int     getCube(){ 
186    // a front-end to the getCube function, that does subsection checks
187    // assumes the Param is setup properly
188    string fname = par.getImageFile();
189    if(par.getFlagSubsection()) fname+=par.getSubsection();
190    return getCube(fname);
191  };
192  int     getFITSdata(string fname);         // in FitsIO/dataIO.cc
193  void    initialiseCube(long *dimensions);  // in cubes.cc
194  int     getopts(int argc, char ** argv);   // in cubes.cc
195  void    saveReconstructedCube();
196  int     readReconCube();
197
198  bool    isBlank(int vox){return par.isBlank(array[vox]);};
199  bool    isBlank(long x, long y, long z){
200    return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]);};
201  float   getPixValue(long pos){return array[pos];};
202  float   getPixValue(long x, long y, long z){
203    return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
204  short   getDetectMapValue(long pos){return detectMap[pos];};
205  short   getDetectMapValue(long x, long y){return detectMap[y*axisDim[0]+x];};
206  bool    isRecon(){return reconExists;};
207  float   getReconValue(long pos){return recon[pos];};
208  float   getReconValue(long x, long y, long z){
209    return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
210  float   getBaselineValue(long pos){return baseline[pos];};
211  float   getBaselineValue(long x, long y, long z){
212    return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
213  // these should have checks against array overflow...
214  void    setPixValue(long pos, float f){array[pos] = f;};
215  void    setPixValue(long x, long y, long z, float f){
216    array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
217  void    setDetectMapValue(long pos, short f){detectMap[pos] = f;};
218  void    setDetectMapValue(long x, long y, short f){
219    detectMap[y*axisDim[0] + x] = f;};
220  void    setReconValue(long pos, float f){recon[pos] = f;};
221  void    setReconValue(long x, long y, long z, float f){
222    recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
223  void    setReconFlag(bool f){reconExists = f;};
224  void    saveArray(float *input, long size);
225  void    saveRecon(float *input, long size);
226  void    getRecon(float *output);
227
228  vector<Col>  getLogCols(){return logCols;};
229  void         setLogCols(vector<Col> C){logCols=C;};
230  vector<Col>  getFullCols(){return fullCols;};
231  void         setFullCols(vector<Col> C){fullCols=C;};
232
233  // Statistics for cube
234  void    setCubeStats();    // in Cubes/cubes.cc
235  int     setupFDR();
236  bool    isDetection(long x, long y, long z){
237    long voxel = z*axisDim[0]*axisDim[1] + y*axisDim[0] + x;
238    return DataArray::isDetection(array[voxel]);
239  };
240
241  // Functions that act on the cube
242  void    removeMW();        // in Cubes/cubes.cc
243  void    trimCube();        // in Cubes/trimImage.cc
244  void    unTrimCube();      // in Cubes/trimImage.cc
245  void    removeBaseline();  // in ATrous/baselineSubtract.cc
246  void    replaceBaseline(); // in ATrous/baselineSubtract.cc
247  void    invert();          // in Cubes/invertCube.cc
248  void    reInvert();        // in Cubes/invertCube.cc
249
250  // Reconstruction and Searching functions
251  void    ReconSearch();     // in ATrous/ReconSearch.cc
252  void    ReconCube();       // in ATrous/ReconSearch.cc
253  void    ReconCube1D();     // in ATrous/ReconSearch.cc
254  void    ReconCube2D();     // in ATrous/ReconSearch.cc
255  void    ReconCube3D();     // in ATrous/ReconSearch.cc
256  void    CubicSearch();     // in Cubes/CubicSearch.cc
257
258  // Dealing with the WCS
259  FitsHeader getHead(){return head;};
260  void       setHead(FitsHeader F){head=F;};
261  FitsHeader& header(){FitsHeader &h = head; return h;};
262  int        wcsToPix(const double *world, double *pix){
263    return this->head.wcsToPix(world,pix);}
264  int        wcsToPix(const double *world, double *pix, const int npts){
265    return this->head.wcsToPix(world,pix,npts);}
266  int        pixToWCS(const double *pix, double *world){
267    return this->head.pixToWCS(pix,world);}
268  int        pixToWCS(const double *pix, double *world, const int npts){
269    return this->head.pixToWCS(pix,world,npts);}
270 
271  // Dealing with the detections
272  void    ObjectMerger();          // in Cubes/Merger.cc
273  void    calcObjectWCSparams();
274  void    sortDetections();
275  void    updateDetectMap();
276  void    updateDetectMap(Detection obj);
277  void    setObjectFlags();
278  float   enclosedFlux(Detection obj);
279  bool    objAtSpatialEdge(Detection obj);
280  bool    objAtSpectralEdge(Detection obj);
281 
282  // Text outputting of detected objects.
283  //    the next five in Cubes/detectionIO.cc
284  void    outputDetectionsKarma(std::ostream &stream);     
285  void    outputDetectionsVOTable(std::ostream &stream);   
286  void    outputDetectionList();                           
287  void    logDetectionList();                             
288  void    logDetection(Detection obj, int counter);       
289  void    setupColumns(); // in Cubes/cubes.cc
290
291  // Graphical plotting of the cube and the detections.
292  void    plotBlankEdges();  // in Cubes/cubes.cc
293  //    the next three in Cubes/plotting.cc
294  void    plotDetectionMap(string pgDestination);         
295  void    plotMomentMap(string pgDestination);             
296  void    plotWCSaxes();                                   
297  //    the next two in Cubes/outputSpectra.cc
298  void    outputSpectra();
299  void    plotSpectrum(Detection obj,Plot::SpectralPlot &plot);
300  //    the next three in Cubes/drawMomentCutout.cc
301  void    drawMomentCutout(Detection &object);
302  void    drawScale(float xstart,float ystart,float channel);
303  void    drawFieldEdge();
304
305private:
306  float  *recon;           // reconstructed array -- used when doing a trous
307                           //   reconstruction.
308  bool    reconExists;     // flag saying whether there is a reconstruction
309  short  *detectMap;       // "moment map" -- x,y locations of detected pixels
310  float  *baseline;        // array of spectral baseline values.
311       
312  FitsHeader head;         // the WCS and other header information.
313  vector<Col> fullCols;    // the list of all columns as printed in the
314                           //  results file
315  vector<Col> logCols;     // the list of columns as printed in the log file
316
317};
318
319/****************************************************************/
320//////////////////////////////////////////////////////
321// Prototypes for functions that use above classes
322//////////////////////////////////////////////////////
323
324DataArray getImage(string fname, short int maxdim);
325Image getImage(string fname);
326
327void findSources(Image &image);
328void findSources(Image &image, float mean, float sigma);
329
330vector <Detection> searchReconArray(long *dim, float *originalArray,
331                                    float *reconArray, Param &par,
332                                    StatsContainer<float> &stats);
333vector <Detection> search3DArray(long *dim, float *Array, Param &par,
334                                 StatsContainer<float> &stats);
335
336void growObject(Detection &object, Cube &cube);
337
338#endif
Note: See TracBrowser for help on using the repository browser.