source: tags/release-0.9/Cubes/cubes.hh @ 813

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

Added a function to write a Karma annotation file. Needed new parameters and
function declaration, and added comments in the Guide as well.
Guide also had VOTable and results examples updated.

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