source: branches/fitshead-branch/Cubes/cubes.hh @ 1441

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

Forgot to change the prototypes for the new search algorithms within
the Cube class.

File size: 14.8 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);
57                       // adds a single detection to the object list
58  vector <Detection>   getObjectList(){return objectList;};
59  void                 addObjectList(vector <Detection> newlist);
60                       // adds all objects in a detection list to the object list
61  long                 getNumObj(){return objectList.size();};
62  void                 clearDetectionList(){this->objectList.clear();};
63  // Parameter list related.
64  void                 readParam(string &paramfile){par.readParams(paramfile);};
65  void                 showParam(std::ostream &stream){stream << par;};
66  Param                getParam(){return par;};
67  void                 saveParam(Param newpar){par = newpar;};
68  Param&               pars(){Param &rpar = par; return rpar;};
69  bool                 isBlank(int vox){return par.isBlank(array[vox]);};
70
71  friend std::ostream& operator<< ( std::ostream& theStream, DataArray &array);
72
73
74protected:
75  short int            numDim;     // number of dimensions.
76  long                *axisDim;    // array of dimensions of cube
77                                   //     (ie. how large in each direction).
78  long                 numPixels;  // total number of pixels in cube
79  float               *array;      // array of data
80  vector <Detection>   objectList; // the list of detected objects in the image
81  Param                par;        // a parameter list.
82};
83
84
85/****************************************************************/
86/////////////////////////////////////////////////////////////
87//// Definition of an image object (2D):
88////     a DataArray object
89////     arrays for: probability values (for FDR)
90////                 mask image to indicate location of objects
91////                 detected objects
92////     statistics information
93/////////////////////////////////////////////////////////////
94
95class Image : public DataArray
96{
97public:
98  Image(){
99    numPixels=0;
100    numDim=2;};
101  Image(long nPix);
102  Image(long *dimensions);
103  virtual ~Image(){};
104
105  // Defining the array
106  void      saveArray(float *input, long size);
107  void      extractSpectrum(float *Array, long *dim, long pixel);
108  void      extractImage(float *Array, long *dim, long channel);
109    // Accessing the data.
110  float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
111  float     getPixValue(long pos){return array[pos];};
112  float     getPValue(long pos){return pValue[pos];};
113  float     getPValue(long x, long y){return pValue[y*axisDim[0] + x];};
114  short int getMaskValue(long pos){return mask[pos];};
115  short int getMaskValue(long x, long y){return mask[y*axisDim[0] + x];};
116  // the next few should have checks against array overflow...
117  void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
118  void      setPixValue(long pos, float f){array[pos] = f;};
119  void      setPValue(long pos, float p){pValue[pos] = p;};
120  void      setPValue(long x, long y, float p){pValue[y*axisDim[0] + x] = p;};
121  void      setMaskValue(long pos, short int m){mask[pos] = m;};
122  void      setMaskValue(long x, long y, short int m){mask[y*axisDim[0] + x] = m;};
123  bool      isBlank(int vox){return par.isBlank(array[vox]);};
124  bool      isBlank(long x, long y){return par.isBlank(array[y*axisDim[0] + x]);};
125  // Stats-related
126  void      setStats(float m, float s, float c){mean=m; sigma=s; cutLevel=c;};
127  void      findStats(int code);
128  float     getMean(){return mean;};
129  void      setMean(float m){mean=m;};
130  float     getSigma(){return sigma;};
131  void      setSigma(float s){sigma=s;};
132  float     getCut(){return cutLevel;};
133  void      setCut(float c){cutLevel=c;};
134  float     getPCut(){return pCutLevel;};
135  void      setPCut(float p){pCutLevel = p;};
136  float     getAlpha(){return alpha;};
137  void      setAlpha(float a){alpha = a;};
138  int       getMinSize(){return minSize;};
139  void      setMinSize(int s){minSize = s;};
140
141  void      maskObject(Detection &object);
142
143  // Detection-related
144  void      lutz_detect();                  // in Detection/lutz_detect.cc
145  void      spectrumDetect();               // in Detection/spectrumDetect.cc
146  int       setupFDR();                     // in Detection/thresholding_functions.cc
147  bool      isDetection(float value);       // in Detection/thresholding_functions.cc
148  bool      isDetection(long x, long y);    // in Detection/thresholding_functions.cc
149  bool      isDetectionFDR(float pvalue);   // in Detection/thresholding_functions.cc
150
151  void      removeMW();
152 
153private:
154  float     *pValue;     // the array of p-values for each pixel
155                         //                  --> used by FDR method
156  short int *mask;       // a mask image indicating where objects are
157                         
158  float      mean;       // the mean background level of the image
159  float      sigma;      // the standard deviation of the background in the image
160  float      cutLevel;   // the limiting value (in sigmas above the mean) for
161                         //     a pixel to be called a detection.
162  float      alpha;      // used by FDR routine -- significance level
163  float      pCutLevel;  // the limiting P-value for the FDR analysis
164  int        minSize;    // the minimum number of pixels for a detection 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; // flagWCS=false;
177  };
178  Cube(long nPix);
179  Cube(long *dimensions);
180  virtual ~Cube(){};            // destructor
181
182  // additional accessor functions -- in Cubes/cubes.cc unless otherwise specified.
183
184  int     getCube(string fname);
185  int     getCube(){this->getCube(this->par.getImageFile());};
186  void    initialiseCube(long *dimensions);
187  void    saveReconstructedCube();
188  int     readReconCube();
189
190  bool    isBlank(int vox){return par.isBlank(array[vox]);};
191  bool    isBlank(long x, long y, long z){
192    return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]);};
193  float   getPixValue(long pos){return array[pos];};
194  float   getPixValue(long x, long y, long z){
195    return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
196  short   getDetectMapValue(long pos){return detectMap[pos];};
197  short   getDetectMapValue(long x, long y){return detectMap[y*axisDim[0] + x];};
198  bool    isRecon(){return reconExists;};
199  float   getReconValue(long pos){return recon[pos];};
200  float   getReconValue(long x, long y, long z){
201    return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
202  float   getBaselineValue(long pos){return baseline[pos];};
203  float   getBaselineValue(long x, long y, long z){
204    return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
205  // these should have checks against array overflow...
206  void    setPixValue(long pos, float f){array[pos] = f;};
207  void    setPixValue(long x, long y, long z, float f){
208    array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
209  void    setDetectMapValue(long pos, short f){detectMap[pos] = f;};
210  void    setDetectMapValue(long x, long y, short f){
211    detectMap[y*axisDim[0] + x] = f;};
212  void    setReconValue(long pos, float f){recon[pos] = f;};
213  void    setReconValue(long x, long y, long z, float f){
214    recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
215  void    setReconFlag(bool f){reconExists = f;};
216  void    saveArray(float *input, long size);
217  void    saveRecon(float *input, long size);
218  void    getRecon(float *output);
219
220  // Statistics for cube
221  float   getSpecMean(int pixel){return specMean[pixel];};
222  float   getSpecSigma(int pixel){return specSigma[pixel];};
223  float   getChanMean(int channel){return chanMean[channel];};
224  float   getChanSigma(int channel){return chanSigma[channel];};
225  void    setCubeStats();    // in Cubes/cubes.cc
226
227  // Functions that act on the cube
228  void    removeMW();        // in Cubes/cubes.cc
229  void    trimCube();        // in Cubes/trimImage.cc
230  void    unTrimCube();      // in Cubes/trimImage.cc
231  void    removeBaseline();  // in ATrous/baselineSubtract.cc
232  void    replaceBaseline(); // in ATrous/baselineSubtract.cc
233  void    invert();          // in Cubes/invertCube.cc
234  void    reInvert();        // in Cubes/invertCube.cc
235
236  // Reconstruction and Searching functions
237  void    ReconSearch();     // in ATrous/ReconSearch.cc
238  void    ReconSearch1D();   // in ATrous/ReconSearch.cc
239  void    ReconSearch2D();   // in ATrous/ReconSearch.cc
240  void    ReconSearch3D();   // in ATrous/ReconSearch.cc
241  void    CubicSearch();     // in Cubes/CubicSearch.cc
242
243  // Dealing with the WCS
244  FitsHeader getHead(){return head;};
245  void       setHead(FitsHeader F){head=F;};
246  FitsHeader& header(){FitsHeader &h = head; return h;};
247  int        wcsToPix(const double *world, double *pix){
248    return this->head.wcsToPix(world,pix);}
249  int        wcsToPix(const double *world, double *pix, const int npts){
250    return this->head.wcsToPix(world,pix,npts);}
251  int        pixToWCS(const double *pix, double *world){
252    return this->head.pixToWCS(pix,world);}
253  int        pixToWCS(const double *pix, double *world, const int npts){
254    return this->head.pixToWCS(pix,world,npts);}
255 
256//  bool    isWCS(){return flagWCS;};
257//  void    setWCS(wcsprm *w);
258//  wcsprm *getWCS();
259//  void    setNWCS(int n){nwcs = n;};
260//  int     getNWCS(){return nwcs;};
261//  void    setBUnit(char *s){bunit = s;};
262//  string  getBUnit(){return bunit;};
263//  void    setVelUnit(char *s){velunit = s;};
264//  string  getVelUnit(){return velunit;};
265         
266  // Dealing with the detections
267  void    ObjectMerger();          // in Cubes/Merger.cc
268  void    calcObjectWCSparams();
269  void    sortDetections();
270  void    updateDetectMap();
271  void    updateDetectMap(Detection obj);
272  void    setObjectFlags();
273  float   enclosedFlux(Detection obj);
274  bool    objAtEdge(Detection obj);
275 
276  // Text outputting of detected objects.
277  void    outputDetectionsKarma(std::ostream &stream);     // in Cubes/detectionIO.cc
278  void    outputDetectionsVOTable(std::ostream &stream);   // in Cubes/detectionIO.cc
279  void    outputDetectionList();                           // in Cubes/detectionIO.cc
280  void    logDetectionList();                              // in Cubes/detectionIO.cc
281  void    logDetection(Detection obj, int counter);        // in Cubes/detectionIO.cc
282  void    setupColumns();                                  // in Detection/columns.cc
283
284  // Graphical plotting of detections.
285  void    plotDetectionMap(string pgDestination);          // in Cubes/plotting.cc
286  void    plotMomentMap(string pgDestination);             // in Cubes/plotting.cc
287  void    plotWCSaxes();                                   // in Cubes/plotting.cc
288  void    outputSpectra();                                 // in Cubes/outputSpectra.cc
289  void    plotSpectrum(Detection obj,Plot::SpectralPlot &plot); // in Cubes/outputSpectra.cc
290  void    drawMomentCutout(Detection &object);             // in Cubes/drawMomentCutout.cc
291  void    drawScale(float xstart, float ystart, float channel, float scaleLength);
292                                                           // in Cubes/drawMomentCutout.cc
293
294private:
295  float  *recon;           // reconstructed array -- used when doing a trous reconstruction.
296  bool    reconExists;     // flag saying whether there is a reconstruction
297  short  *detectMap;       // "moment map" -- x,y locations of detected pixels
298  float  *baseline;        // array of spectral baseline values.
299                       
300  float  *specMean;        // array of means  for each spectrum in cube
301  float  *specSigma;       // array of sigmas for each spectrum in cube
302  float  *chanMean;        // array of means  for each channel map in cube
303  float  *chanSigma;       // array of sigmas for each channel map in cube
304       
305  FitsHeader head;         // the WCS and other header information.
306  ColSet fullColSet;       // the list of all columns as printed in the results file
307  ColSet logColSet;        // the list of columns as printed in the log file
308
309  //  bool    flagWCS;         // a flag indicating whether there is a valid WCS present.
310  //  wcsprm *wcs;             // the WCS parameters for the cube -- a struct from wcslib
311  //  int     nwcs;            // number of WCS parameters
312  //  string  bunit;           // The header keyword BUNIT -- the units of brightness in the FITS file.
313  //  string  velunit;         // The header keyword CUNIT3 -- the units of the spectral dimension.
314};
315
316/****************************************************************/
317//////////////////////////////////////////////////////
318// Prototypes for functions that use above classes
319//////////////////////////////////////////////////////
320
321DataArray getImage(string fname, short int maxdim);
322Image getImage(string fname);
323
324void findSources(Image &image);
325void findSources(Image &image, float mean, float sigma);
326
327vector <Detection> searchReconArray(long *dim,float *originalArray,float *reconArray, Param &par);
328vector <Detection> search3DArray(long *dim, float *Array, Param &par);
329
330void growObject(Detection &object, Image &image);
331void growObject(Detection &object, Cube &cube);
332
333#endif
Note: See TracBrowser for help on using the repository browser.