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

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

Added code to produce warning flags for detections: for either edge location
or negative enclosed flux. Summary of changes:
Cubes/cubes.cc -- three new routines
Cubes/cubes.hh -- prototypes for new routines. New isBlank functions.
Detection/outputDetection.cc -- output of warning flags.
mainDuchamp.cc -- calling of new routines. Other minor changes.
docs/Guide.tex -- explanation of new warning flags. Other minor changes.
docs/example_spectrum.pdf -- shows the new formatting.
docs/example_spectrum.ps -- ditto
InputComplete? -- all values are now the same as the default param values

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#include <wcs.h>
8
9#ifndef PARAM_H
10#include <param.hh>
11#endif
12#ifndef DETECTION_H
13#include <Detection/detection.hh>
14#endif
15
16using std::string;
17using std::vector;
18
19/****************************************************************/
20/////////////////////////////////////////////////////////////
21//// Definition of an n-dimensional data array:
22////     array of pixel values, size & dimensions
23////     array of Detection objects
24/////////////////////////////////////////////////////////////
25
26
27class DataArray
28{
29public:
30  DataArray(){numDim=0; numPixels=0;};
31  DataArray(short int nDim){numDim=nDim; numPixels=0;};
32  DataArray(short int nDim, long size);
33  DataArray(short int nDim, long *dimensions);
34  virtual ~DataArray(){};
35  // Size and Dimension related
36  long                 getDimX(){if(numDim>0) return axisDim[0]; else return 0;};
37  long                 getDimY(){if(numDim>1) return axisDim[1]; else return 1;};
38  long                 getDimZ(){if(numDim>2) return axisDim[2]; else return 1;};
39  void                 getDim(long &x, long &y, long &z);
40  long                 getSize(){return numPixels;};
41  short int            getNumDim(){return numDim;};
42  // Related to the various arrays
43  void                 getDimArray(long *output);
44  void                 getArray(float *output);
45  virtual void         saveArray(float *input, long size);
46  float                getPixValue(long pos){return array[pos];};
47  void                 setPixValue(long pos, float f){array[pos] = f;};
48  // Related to the object lists
49  Detection            getObject(long number){return objectList[number];};
50  void                 addObject(Detection object);
51                       // adds a single detection to the object list
52  vector <Detection>   getObjectList(){return objectList;};
53  void                 addObjectList(vector <Detection> newlist);
54                       // adds all objects in a detection list to the object list
55  long                 getNumObj(){return objectList.size();};
56  void                 clearDetectionList(){this->objectList.clear();};
57  // Parameter list related.
58  void                 readParam(string &paramfile){par.readParams(paramfile);};
59  void                 showParam(std::ostream &stream){stream << par;};
60  Param                getParam(){return par;};
61  void                 saveParam(Param newpar){par = newpar;};
62  Param&               pars(){Param &rpar = par; return rpar;};
63  bool                 isBlank(int vox){return par.isBlank(array[vox]);};
64
65  friend std::ostream& operator<< ( std::ostream& theStream, DataArray &array);
66
67
68protected:
69  short int            numDim;     // number of dimensions.
70  long                *axisDim;    // array of dimensions of cube
71                                   //     (ie. how large in each direction).
72  long                 numPixels;  // total number of pixels in cube
73  float               *array;      // array of data
74  vector <Detection>   objectList; // the list of detected objects in the image
75  Param                par;        // a parameter list.
76};
77
78
79/****************************************************************/
80/////////////////////////////////////////////////////////////
81//// Definition of an image object (2D):
82////     a DataArray object
83////     arrays for: probability values (for FDR)
84////                 mask image to indicate location of objects
85////                 detected objects
86////     statistics information
87/////////////////////////////////////////////////////////////
88
89class Image : public DataArray
90{
91public:
92  Image(){
93    numPixels=0;
94    numDim=2;};
95  Image(long nPix);
96  Image(long *dimensions);
97  virtual ~Image(){};
98
99  // Defining the array
100  void      saveArray(float *input, long size);
101  void      extractSpectrum(float *Array, long *dim, long pixel);
102  void      extractImage(float *Array, long *dim, long channel);
103    // Accessing the data.
104  float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
105  float     getPixValue(long pos){return array[pos];};
106  float     getPValue(long pos){return pValue[pos];};
107  float     getPValue(long x, long y){return pValue[y*axisDim[0] + x];};
108  short int getMaskValue(long pos){return mask[pos];};
109  short int getMaskValue(long x, long y){return mask[y*axisDim[0] + x];};
110  // the next few should have checks against array overflow...
111  void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
112  void      setPixValue(long pos, float f){array[pos] = f;};
113  void      setPValue(long pos, float p){pValue[pos] = p;};
114  void      setPValue(long x, long y, float p){pValue[y*axisDim[0] + x] = p;};
115  void      setMaskValue(long pos, short int m){mask[pos] = m;};
116  void      setMaskValue(long x, long y, short int m){mask[y*axisDim[0] + x] = m;};
117  // Stats-related
118  void      setStats(float m, float s, float c){mean=m; sigma=s; cutLevel=c;};
119  void      findStats(int code);
120  float     getMean(){return mean;};
121  void      setMean(float m){mean=m;};
122  float     getSigma(){return sigma;};
123  void      setSigma(float s){sigma=s;};
124  float     getCut(){return cutLevel;};
125  void      setCut(float c){cutLevel=c;};
126  float     getPCut(){return pCutLevel;};
127  void      setPCut(float p){pCutLevel = p;};
128  float     getAlpha(){return alpha;};
129  void      setAlpha(float a){alpha = a;};
130  int       getMinSize(){return minSize;};
131  void      setMinSize(int s){minSize = s;};
132
133  void      maskObject(Detection &object);
134
135  // Detection-related
136  void      lutz_detect();                  // in Detection/lutz_detect.cc
137  void      spectrumDetect();               // in Detection/spectrumDetect.cc
138  int       setupFDR();                     // in Detection/thresholding_functions.cc
139  bool      isDetection(float value);       // in Detection/thresholding_functions.cc
140  bool      isDetection(long x, long y);    // in Detection/thresholding_functions.cc
141  bool      isDetectionFDR(float pvalue);   // in Detection/thresholding_functions.cc
142
143 
144private:
145  float     *pValue;     // the array of p-values for each pixel
146                         //                  --> used by FDR method
147  short int *mask;       // a mask image indicating where objects are
148                         
149  float      mean;       // the mean background level of the image
150  float      sigma;      // the standard deviation of the background in the image
151  float      cutLevel;   // the limiting value (in sigmas above the mean) for
152                         //     a pixel to be called a detection.
153  float      alpha;      // used by FDR routine -- significance level
154  float      pCutLevel;  // the limiting P-value for the FDR analysis
155  int        minSize;    // the minimum number of pixels for a detection to be accepted.
156};
157
158/****************************************************************/
159/////////////////////////////////////////////////////////////
160//// Definition of an data-cube object (3D):
161////     a DataArray object limited to dim=3
162/////////////////////////////////////////////////////////////
163
164class Cube : public DataArray
165{
166public:
167  Cube(){numPixels=0; numDim=3; flagWCS=false;};
168  Cube(long nPix);
169  Cube(long *dimensions);
170  virtual ~Cube(){};            // destructor
171
172  // additional accessor functions -- in Cubes/cubes.cc unless otherwise specified.
173
174  int     getCube(string fname);
175  void    initialiseCube(long *dimensions);
176  void    saveReconstructedCube();
177  int     readReconCube();
178
179  bool    isBlank(int vox){return par.isBlank(array[vox]);};
180  bool    isBlank(long x, long y, long z){
181    return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]);};
182  float   getPixValue(long pos){return array[pos];};
183  float   getPixValue(long x, long y, long z){
184    return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
185  short   getDetectMapValue(long pos){return detectMap[pos];};
186  short   getDetectMapValue(long x, long y){return detectMap[y*axisDim[0] + x];};
187  bool    isRecon(){return reconExists;};
188  float   getReconValue(long pos){return recon[pos];};
189  float   getReconValue(long x, long y, long z){
190    return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
191  float   getBaselineValue(long pos){return baseline[pos];};
192  float   getBaselineValue(long x, long y, long z){
193    return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
194  // these should have checks against array overflow...
195  void    setPixValue(long pos, float f){array[pos] = f;};
196  void    setPixValue(long x, long y, long z, float f){
197    array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
198  void    setDetectMapValue(long pos, short f){detectMap[pos] = f;};
199  void    setDetectMapValue(long x, long y, short f){
200    detectMap[y*axisDim[0] + x] = f;};
201  void    setReconValue(long pos, float f){recon[pos] = f;};
202  void    setReconValue(long x, long y, long z, float f){
203    recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
204  void    setReconFlag(bool f){reconExists = f;};
205  void    saveArray(float *input, long size);
206  void    saveRecon(float *input, long size);
207  void    getRecon(float *output);
208
209  // Statistics for cube
210  float   getSpecMean(int pixel){return specMean[pixel];};
211  float   getSpecSigma(int pixel){return specSigma[pixel];};
212  float   getChanMean(int channel){return chanMean[channel];};
213  float   getChanSigma(int channel){return chanSigma[channel];};
214  void    setCubeStats();    // in Cubes/cubes.cc
215
216  // Functions that act on the cube
217  void    removeMW();        // in Cubes/cubes.cc
218  void    trimCube();        // in Cubes/trimImage.cc
219  void    unTrimCube();      // in Cubes/trimImage.cc
220  void    removeBaseline();  // in ATrous/baselineSubtract.cc
221  void    replaceBaseline(); // in ATrous/baselineSubtract.cc
222  void    invert();          // in Cubes/invertCube.cc
223  void    reInvert();        // in Cubes/invertCube.cc
224
225  // Reconstruction and Searching functions
226  void    ReconSearch1D();   // in ATrous/ReconSearch.cc
227  void    ReconSearch2D();   // in ATrous/ReconSearch.cc
228  void    ReconSearch3D();   // in ATrous/ReconSearch.cc
229  void    SimpleSearch3D();  // in Cubes/CubicSearch.cc
230
231  // Dealing with the WCS
232  bool    isWCS(){return flagWCS;};
233  void    setWCS(wcsprm *w);
234  wcsprm *getWCS();
235  void    setNWCS(int n){nwcs = n;};
236  int     getNWCS(){return nwcs;};
237  void    setBUnit(char *s){bunit = s;};
238  string  getBUnit(){return bunit;};
239         
240  // Dealing with the detections
241  void    ObjectMerger();          // in Cubes/Merger.cc
242  void    calcObjectWCSparams();
243  void    sortDetections();
244  void    updateDetectMap();
245  void    updateDetectMap(Detection obj);
246  void    setObjectFlags();
247  float   enclosedFlux(Detection obj);
248  bool    objAtEdge(Detection obj);
249 
250  // Text outputting of detected objects.
251  void    outputDetectionsKarma(std::ostream &stream);     // in Cubes/detectionIO.cc
252  void    outputDetectionsVOTable(std::ostream &stream);   // in Cubes/detectionIO.cc
253  void    outputDetectionList();                           // in Cubes/detectionIO.cc
254  void    logDetectionList();                              // in Cubes/detectionIO.cc
255  void    logDetection(Detection obj, int counter);        // in Cubes/detectionIO.cc
256
257  // Graphical plotting of detections.
258  void    plotDetectionMap(string pgDestination);     // in Cubes/plotting.cc
259  void    plotMomentMap(string pgDestination);        // in Cubes/plotting.cc
260  void    plotWCSaxes();                              // in Cubes/plotting.cc
261  void    outputSpectra();                            // in Cubes/outputSpectra.cc
262  void    drawScale(float xstart, float ystart, float channel, float scaleLength);
263                                                      // in Cubes/drawMomentCutout.cc
264
265
266private:
267  float  *recon;           // reconstructed array -- used when doing a trous reconstruction.
268  bool    reconExists;     // flag saying whether there is a reconstruction
269  short  *detectMap;       // "moment map" -- x,y locations of detected pixels
270  float  *baseline;        // array of spectral baseline values.
271                       
272  float  *specMean;        // array of means  for each spectrum in cube
273  float  *specSigma;       // array of sigmas for each spectrum in cube
274  float  *chanMean;        // array of means  for each channel map in cube
275  float  *chanSigma;       // array of sigmas for each channel map in cube
276                           
277  bool    flagWCS;         // a flag indicating whether there is a valid WCS present.
278  wcsprm *wcs;             // the WCS parameters for the cube -- a struct from wcslib
279  int     nwcs;            // number of WCS parameters
280  string  bunit;           // The header keyword BUNIT -- the units of brightness in the FITS file.
281};
282
283/****************************************************************/
284//////////////////////////////////////////////////////
285// Prototypes for functions that use above classes
286//////////////////////////////////////////////////////
287
288DataArray getImage(string fname, short int maxdim);
289Image getImage(string fname);
290
291void findSources(Image &image);
292void findSources(Image &image, float mean, float sigma);
293
294vector <Detection> reconSearch(long *dim,float *originalArray,float *reconArray, Param &par);
295vector <Detection> cubicSearch(long *dim, float *Array, Param &par);
296vector <Detection> cubicSearchNMerge(long *dim, float *Array, Param &par);
297
298void growObject(Detection &object, Image &image);
299void growObject(Detection &object, Cube &cube);
300
301void drawMomentCutout(Cube &cube, Detection &object);
302
303#endif
Note: See TracBrowser for help on using the repository browser.