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

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

Changed source tree structure: added a src/ directory that contains all the
code. Makefile.in and configure.ac changed to match.

File size: 14.3 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
21using std::string;
22using std::vector;
23using namespace Column;
24
25/****************************************************************/
26/////////////////////////////////////////////////////////////
27//// Definition of an n-dimensional data array:
28////     array of pixel values, size & dimensions
29////     array of Detection objects
30/////////////////////////////////////////////////////////////
31
32
33class DataArray
34{
35public:
36  DataArray(){numDim=0; numPixels=0;};
37  DataArray(short int nDim){numDim=nDim; numPixels=0;};
38  DataArray(short int nDim, long size);
39  DataArray(short int nDim, long *dimensions);
40  virtual ~DataArray(){};
41  // Size and Dimension related
42  long                 getDimX(){if(numDim>0) return axisDim[0]; else return 0;};
43  long                 getDimY(){if(numDim>1) return axisDim[1]; else return 1;};
44  long                 getDimZ(){if(numDim>2) return axisDim[2]; else return 1;};
45  void                 getDim(long &x, long &y, long &z);
46  long                 getSize(){return numPixels;};
47  short int            getNumDim(){return numDim;};
48  // Related to the various arrays
49  void                 getDimArray(long *output);
50  void                 getArray(float *output);
51  virtual void         saveArray(float *input, long size);
52  float                getPixValue(long pos){return array[pos];};
53  void                 setPixValue(long pos, float f){array[pos] = f;};
54  // Related to the object lists
55  Detection            getObject(long number){return objectList[number];};
56  void                 addObject(Detection object);   // adds a single detection to the object list
57  vector <Detection>   getObjectList(){return objectList;};
58  void                 addObjectList(vector <Detection> newlist); 
59                                     // adds all objects in a detection list to the object list
60  long                 getNumObj(){return objectList.size();};
61  void                 clearDetectionList(){this->objectList.clear();};
62  // Parameter list related.
63  void                 readParam(string paramfile){par.readParams(paramfile);};
64  void                 showParam(std::ostream &stream){stream << par;};
65  Param                getParam(){return par;};
66  void                 saveParam(Param newpar){par = newpar;};
67  Param&               pars(){Param &rpar = par; return rpar;};
68  bool                 isBlank(int vox){return par.isBlank(array[vox]);};
69
70  friend std::ostream& operator<< ( std::ostream& theStream, DataArray &array);
71
72
73protected:
74  short int            numDim;     // number of dimensions.
75  long                *axisDim;    // array of dimensions of cube
76                                   //     (ie. how large in each direction).
77  long                 numPixels;  // total number of pixels in cube
78  float               *array;      // array of data
79  vector <Detection>   objectList; // the list of detected objects in the image
80  Param                par;        // a parameter list.
81};
82
83
84/****************************************************************/
85/////////////////////////////////////////////////////////////
86//// Definition of an image object (2D):
87////     a DataArray object
88////     arrays for: probability values (for FDR)
89////                 mask image to indicate location of objects
90////                 detected objects
91////     statistics information
92/////////////////////////////////////////////////////////////
93
94class Image : public DataArray
95{
96public:
97  Image(){
98    numPixels=0;
99    numDim=2;};
100  Image(long nPix);
101  Image(long *dimensions);
102  virtual ~Image(){};
103
104  // Defining the array
105  void      saveArray(float *input, long size);
106  void      extractSpectrum(float *Array, long *dim, long pixel);
107  void      extractImage(float *Array, long *dim, long channel);
108  // Accessing the data.
109  float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
110  float     getPixValue(long pos){return array[pos];};
111  float     getPValue(long pos){return pValue[pos];};
112  float     getPValue(long x, long y){return pValue[y*axisDim[0] + x];};
113  short int getMaskValue(long pos){return mask[pos];};
114  short int getMaskValue(long x, long y){return mask[y*axisDim[0] + x];};
115  // the next few should have checks against array overflow...
116  void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
117  void      setPixValue(long pos, float f){array[pos] = f;};
118  void      setPValue(long pos, float p){pValue[pos] = p;};
119  void      setPValue(long x, long y, float p){pValue[y*axisDim[0] + x] = p;};
120  void      setMaskValue(long pos, short int m){mask[pos] = m;};
121  void      setMaskValue(long x, long y, short int m){mask[y*axisDim[0] + x] = m;};
122  bool      isBlank(int vox){return par.isBlank(array[vox]);};
123  bool      isBlank(long x, long y){return par.isBlank(array[y*axisDim[0] + x]);};
124  // Stats-related
125  void      setStats(float m, float s, float c){mean=m; sigma=s; cutLevel=c;};
126  void      findStats(int code);
127  float     getMean(){return mean;};
128  void      setMean(float m){mean=m;};
129  float     getSigma(){return sigma;};
130  void      setSigma(float s){sigma=s;};
131  float     getCut(){return cutLevel;};
132  void      setCut(float c){cutLevel=c;};
133  float     getPCut(){return pCutLevel;};
134  void      setPCut(float p){pCutLevel = p;};
135  float     getAlpha(){return alpha;};
136  void      setAlpha(float a){alpha = a;};
137  int       getMinSize(){return minSize;};
138  void      setMinSize(int s){minSize = s;};
139
140  void      maskObject(Detection &object);
141
142  // Detection-related
143  void      lutz_detect();                  // in Detection/lutz_detect.cc
144  void      spectrumDetect();               // in Detection/spectrumDetect.cc
145  int       setupFDR();                     // in Detection/thresholding_functions.cc
146  bool      isDetection(float value);       // in Detection/thresholding_functions.cc
147  bool      isDetection(long x, long y);    // in Detection/thresholding_functions.cc
148  bool      isDetectionFDR(float pvalue);   // in Detection/thresholding_functions.cc
149
150  void      removeMW();
151 
152private:
153  float     *pValue;     // the array of p-values for each pixel
154                         //                  --> used by FDR method
155  short int *mask;       // a mask image indicating where objects are
156                         
157  float      mean;       // the mean background level of the image
158  float      sigma;      // the standard deviation of the background in the image
159  float      cutLevel;   // the limiting value (in sigmas above the mean) for
160                         //     a pixel to be called a detection.
161  float      alpha;      // used by FDR routine -- significance level
162  float      pCutLevel;  // the limiting P-value for the FDR analysis
163  int        minSize;    // the minimum number of pixels for a detection to be accepted.
164};
165
166/****************************************************************/
167/////////////////////////////////////////////////////////////
168//// Definition of an data-cube object (3D):
169////     a DataArray object limited to dim=3
170/////////////////////////////////////////////////////////////
171
172class Cube : public DataArray
173{
174public:
175  Cube(){numPixels=0; numDim=3; // flagWCS=false;
176  };
177  Cube(long nPix);
178  Cube(long *dimensions);
179  virtual ~Cube(){};            // destructor
180
181  // additional accessor functions -- in Cubes/cubes.cc unless otherwise specified.
182
183  int     getCube(string fname);
184  int     getCube(){ 
185    // a front-end to the getCube function, that does subsection checks
186    // assumes the Param is setup properly
187    string fname = this->par.getImageFile();
188    if(this->par.getFlagSubsection()){
189      this->par.parseSubsection();
190      fname+=this->par.getSubsection();
191    }
192    return this->getCube(fname);
193  };
194  void    initialiseCube(long *dimensions);
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  // Statistics for cube
229  float   getSpecMean(int pixel){return specMean[pixel];};
230  float   getSpecSigma(int pixel){return specSigma[pixel];};
231  float   getChanMean(int channel){return chanMean[channel];};
232  float   getChanSigma(int channel){return chanSigma[channel];};
233  void    setCubeStats();    // in Cubes/cubes.cc
234
235  // Functions that act on the cube
236  void    removeMW();        // in Cubes/cubes.cc
237  void    trimCube();        // in Cubes/trimImage.cc
238  void    unTrimCube();      // in Cubes/trimImage.cc
239  void    removeBaseline();  // in ATrous/baselineSubtract.cc
240  void    replaceBaseline(); // in ATrous/baselineSubtract.cc
241  void    invert();          // in Cubes/invertCube.cc
242  void    reInvert();        // in Cubes/invertCube.cc
243
244  // Reconstruction and Searching functions
245  void    ReconSearch();     // in ATrous/ReconSearch.cc
246  void    ReconSearch1D();   // in ATrous/ReconSearch.cc
247  void    ReconSearch2D();   // in ATrous/ReconSearch.cc
248  void    ReconSearch3D();   // in ATrous/ReconSearch.cc
249  void    CubicSearch();     // in Cubes/CubicSearch.cc
250
251  // Dealing with the WCS
252  FitsHeader getHead(){return head;};
253  void       setHead(FitsHeader F){head=F;};
254  FitsHeader& header(){FitsHeader &h = head; return h;};
255  int        wcsToPix(const double *world, double *pix){
256    return this->head.wcsToPix(world,pix);}
257  int        wcsToPix(const double *world, double *pix, const int npts){
258    return this->head.wcsToPix(world,pix,npts);}
259  int        pixToWCS(const double *pix, double *world){
260    return this->head.pixToWCS(pix,world);}
261  int        pixToWCS(const double *pix, double *world, const int npts){
262    return this->head.pixToWCS(pix,world,npts);}
263 
264  // Dealing with the detections
265  void    ObjectMerger();          // in Cubes/Merger.cc
266  void    calcObjectWCSparams();
267  void    sortDetections();
268  void    updateDetectMap();
269  void    updateDetectMap(Detection obj);
270  void    setObjectFlags();
271  float   enclosedFlux(Detection obj);
272  bool    objAtEdge(Detection obj);
273 
274  // Text outputting of detected objects.
275  void    outputDetectionsKarma(std::ostream &stream);     // in Cubes/detectionIO.cc
276  void    outputDetectionsVOTable(std::ostream &stream);   // in Cubes/detectionIO.cc
277  void    outputDetectionList();                           // in Cubes/detectionIO.cc
278  void    logDetectionList();                              // in Cubes/detectionIO.cc
279  void    logDetection(Detection obj, int counter);        // in Cubes/detectionIO.cc
280  void    setupColumns();                                  // in Detection/columns.cc
281
282  // Graphical plotting of detections.
283  void    plotDetectionMap(string pgDestination);          // in Cubes/plotting.cc
284  void    plotMomentMap(string pgDestination);             // in Cubes/plotting.cc
285  void    plotWCSaxes();                                   // in Cubes/plotting.cc
286  void    outputSpectra();                                 // in Cubes/outputSpectra.cc
287  void    plotSpectrum(Detection obj,Plot::SpectralPlot &plot); // in Cubes/outputSpectra.cc
288  void    drawMomentCutout(Detection &object);             // in Cubes/drawMomentCutout.cc
289  void    drawScale(float xstart, float ystart, float channel, float scaleLength);
290                                                           // in Cubes/drawMomentCutout.cc
291
292private:
293  float  *recon;           // reconstructed array -- used when doing a trous reconstruction.
294  bool    reconExists;     // flag saying whether there is a reconstruction
295  short  *detectMap;       // "moment map" -- x,y locations of detected pixels
296  float  *baseline;        // array of spectral baseline values.
297                       
298  float  *specMean;        // array of means  for each spectrum in cube
299  float  *specSigma;       // array of sigmas for each spectrum in cube
300  float  *chanMean;        // array of means  for each channel map in cube
301  float  *chanSigma;       // array of sigmas for each channel map in cube
302       
303  FitsHeader head;         // the WCS and other header information.
304  ColSet fullColSet;       // the list of all columns as printed in the results file
305  ColSet logColSet;        // the list of columns as printed in the log file
306
307};
308
309/****************************************************************/
310//////////////////////////////////////////////////////
311// Prototypes for functions that use above classes
312//////////////////////////////////////////////////////
313
314DataArray getImage(string fname, short int maxdim);
315Image getImage(string fname);
316
317void findSources(Image &image);
318void findSources(Image &image, float mean, float sigma);
319
320vector <Detection> searchReconArray(long *dim,float *originalArray,float *reconArray, Param &par);
321vector <Detection> search3DArray(long *dim, float *Array, Param &par);
322
323void growObject(Detection &object, Image &image);
324void growObject(Detection &object, Cube &cube);
325
326#endif
Note: See TracBrowser for help on using the repository browser.