source: trunk/src/Cubes/cubes.hh @ 144

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

Made changes to the way the columns are dealt with. Now much more resilient
towards low values (eg of flux -- if much below 1 it will change the width
and precision so that enough significant figures are shown).
These changes are also propagated through to the information in the spectral
plots.
The ColSet? class was removed and replaced with a more simple vector<Col>.

File size: 14.6 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  void                 addObjectOffsets();
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 Cube;
96class Image : public DataArray
97{
98public:
99  Image(){
100    numPixels=0;
101    numDim=2;};
102  Image(long nPix);
103  Image(long *dimensions);
104  virtual ~Image();
105
106  // Defining the array
107  void      saveArray(float *input, long size);
108  void      extractSpectrum(float *Array, long *dim, long pixel);
109  void      extractImage(float *Array, long *dim, long channel);
110  void      extractSpectrum(Cube &cube, long pixel);
111  void      extractImage(Cube &cube, long channel);
112  // Accessing the data.
113  float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
114  float     getPixValue(long pos){return array[pos];};
115  float     getPValue(long pos){return pValue[pos];};
116  float     getPValue(long x, long y){return pValue[y*axisDim[0] + x];};
117  short int getMaskValue(long pos){return mask[pos];};
118  short int getMaskValue(long x, long y){return mask[y*axisDim[0] + x];};
119  // the next few should have checks against array overflow...
120  void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
121  void      setPixValue(long pos, float f){array[pos] = f;};
122  void      setPValue(long pos, float p){pValue[pos] = p;};
123  void      setPValue(long x, long y, float p){pValue[y*axisDim[0] + x] = p;};
124  void      setMaskValue(long pos, short int m){mask[pos] = m;};
125  void      setMaskValue(long x, long y, short int m){mask[y*axisDim[0] + x] = m;};
126  bool      isBlank(int vox){return par.isBlank(array[vox]);};
127  bool      isBlank(long x, long y){return par.isBlank(array[y*axisDim[0] + x]);};
128  // Stats-related
129  void      setStats(float m, float s, float c){mean=m; sigma=s; cutLevel=c;};
130  void      findStats(int code);
131  float     getMean(){return mean;};
132  void      setMean(float m){mean=m;};
133  float     getSigma(){return sigma;};
134  void      setSigma(float s){sigma=s;};
135  float     getCut(){return cutLevel;};
136  void      setCut(float c){cutLevel=c;};
137  float     getPCut(){return pCutLevel;};
138  void      setPCut(float p){pCutLevel = p;};
139  float     getAlpha(){return alpha;};
140  void      setAlpha(float a){alpha = a;};
141  int       getMinSize(){return minSize;};
142  void      setMinSize(int s){minSize = s;};
143
144  void      maskObject(Detection &object);
145
146  // Detection-related
147  void      lutz_detect();                  // in Detection/lutz_detect.cc
148  void      spectrumDetect();               // in Detection/spectrumDetect.cc
149  int       setupFDR();                     // in Detection/thresholding_functions.cc
150  bool      isDetection(float value);       // in Detection/thresholding_functions.cc
151  bool      isDetection(long x, long y);    // in Detection/thresholding_functions.cc
152  bool      isDetectionFDR(float pvalue);   // in Detection/thresholding_functions.cc
153
154  void      removeMW();
155 
156private:
157  float     *pValue;     // the array of p-values for each pixel
158                         //                  --> used by FDR method
159  short int *mask;       // a mask image indicating where objects are
160                         
161  float      mean;       // the mean background level of the image
162  float      sigma;      // the standard deviation of the background in the image
163  float      cutLevel;   // the limiting value (in sigmas above the mean) for
164                         //     a pixel to be called a detection.
165  float      alpha;      // used by FDR routine -- significance level
166  float      pCutLevel;  // the limiting P-value for the FDR analysis
167  int        minSize;    // the minimum number of pixels for a detection to be accepted.
168};
169
170/****************************************************************/
171/////////////////////////////////////////////////////////////
172//// Definition of an data-cube object (3D):
173////     a DataArray object limited to dim=3
174/////////////////////////////////////////////////////////////
175
176class Cube : public DataArray
177{
178public:
179  Cube(){numPixels=0; numDim=3; // flagWCS=false;
180  };
181  Cube(long nPix);
182  Cube(long *dimensions);
183  virtual ~Cube();            // destructor
184
185  // additional accessor functions -- in Cubes/cubes.cc unless otherwise specified.
186
187  int     getCube(string fname);
188  int     getCube(){ 
189    // a front-end to the getCube function, that does subsection checks
190    // assumes the Param is setup properly
191    string fname = par.getImageFile();
192    if(par.getFlagSubsection()){
193      par.parseSubsection();
194      fname+=par.getSubsection();
195    }
196    return getCube(fname);
197  };
198  void    initialiseCube(long *dimensions);  // in cubes.cc
199  int     getopts(int argc, char ** argv);   // in cubes.cc
200  void    saveReconstructedCube();
201  int     readReconCube();
202
203  bool    isBlank(int vox){return par.isBlank(array[vox]);};
204  bool    isBlank(long x, long y, long z){
205    return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]);};
206  float   getPixValue(long pos){return array[pos];};
207  float   getPixValue(long x, long y, long z){
208    return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
209  short   getDetectMapValue(long pos){return detectMap[pos];};
210  short   getDetectMapValue(long x, long y){return detectMap[y*axisDim[0] + x];};
211  bool    isRecon(){return reconExists;};
212  float   getReconValue(long pos){return recon[pos];};
213  float   getReconValue(long x, long y, long z){
214    return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
215  float   getBaselineValue(long pos){return baseline[pos];};
216  float   getBaselineValue(long x, long y, long z){
217    return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
218  // these should have checks against array overflow...
219  void    setPixValue(long pos, float f){array[pos] = f;};
220  void    setPixValue(long x, long y, long z, float f){
221    array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
222  void    setDetectMapValue(long pos, short f){detectMap[pos] = f;};
223  void    setDetectMapValue(long x, long y, short f){
224    detectMap[y*axisDim[0] + x] = f;};
225  void    setReconValue(long pos, float f){recon[pos] = f;};
226  void    setReconValue(long x, long y, long z, float f){
227    recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
228  void    setReconFlag(bool f){reconExists = f;};
229  void    saveArray(float *input, long size);
230  void    saveRecon(float *input, long size);
231  void    getRecon(float *output);
232
233  vector<Col>  getLogCols(){return logCols;};
234  void         setLogCols(vector<Col> C){logCols=C;};
235  vector<Col>  getFullCols(){return fullCols;};
236  void         setFullCols(vector<Col> C){fullCols=C;};
237
238
239  // Statistics for cube
240  float   getSpecMean(int pixel){return specMean[pixel];};
241  float   getSpecSigma(int pixel){return specSigma[pixel];};
242  float   getChanMean(int channel){return chanMean[channel];};
243  float   getChanSigma(int channel){return chanSigma[channel];};
244  void    setCubeStats();    // in Cubes/cubes.cc
245
246  // Functions that act on the cube
247  void    removeMW();        // in Cubes/cubes.cc
248  void    trimCube();        // in Cubes/trimImage.cc
249  void    unTrimCube();      // in Cubes/trimImage.cc
250  void    removeBaseline();  // in ATrous/baselineSubtract.cc
251  void    replaceBaseline(); // in ATrous/baselineSubtract.cc
252  void    invert();          // in Cubes/invertCube.cc
253  void    reInvert();        // in Cubes/invertCube.cc
254
255  // Reconstruction and Searching functions
256  void    ReconSearch();     // in ATrous/ReconSearch.cc
257  void    ReconSearch1D();   // in ATrous/ReconSearch.cc
258  void    ReconSearch2D();   // in ATrous/ReconSearch.cc
259  void    ReconSearch3D();   // in ATrous/ReconSearch.cc
260  void    CubicSearch();     // in Cubes/CubicSearch.cc
261
262  // Dealing with the WCS
263  FitsHeader getHead(){return head;};
264  void       setHead(FitsHeader F){head=F;};
265  FitsHeader& header(){FitsHeader &h = head; return h;};
266  int        wcsToPix(const double *world, double *pix){
267    return this->head.wcsToPix(world,pix);}
268  int        wcsToPix(const double *world, double *pix, const int npts){
269    return this->head.wcsToPix(world,pix,npts);}
270  int        pixToWCS(const double *pix, double *world){
271    return this->head.pixToWCS(pix,world);}
272  int        pixToWCS(const double *pix, double *world, const int npts){
273    return this->head.pixToWCS(pix,world,npts);}
274 
275  // Dealing with the detections
276  void    ObjectMerger();          // in Cubes/Merger.cc
277  void    calcObjectWCSparams();
278  void    sortDetections();
279  void    updateDetectMap();
280  void    updateDetectMap(Detection obj);
281  void    setObjectFlags();
282  float   enclosedFlux(Detection obj);
283  bool    objAtEdge(Detection obj);
284 
285  // Text outputting of detected objects.
286  //    the next five in Cubes/detectionIO.cc
287  void    outputDetectionsKarma(std::ostream &stream);     
288  void    outputDetectionsVOTable(std::ostream &stream);   
289  void    outputDetectionList();                           
290  void    logDetectionList();                             
291  void    logDetection(Detection obj, int counter);       
292  void    setupColumns(); // in Cubes/cubes.cc
293
294  // Graphical plotting of the cube and the detections.
295  void    plotBlankEdges();  // in Cubes/cubes.cc
296  //    the next three in Cubes/plotting.cc
297  void    plotDetectionMap(string pgDestination);         
298  void    plotMomentMap(string pgDestination);             
299  void    plotWCSaxes();                                   
300  //    the next two in Cubes/outputSpectra.cc
301  void    outputSpectra();                                     
302  void    plotSpectrum(Detection obj,Plot::SpectralPlot &plot);
303  //    the next three in Cubes/drawMomentCutout.cc
304  void    drawMomentCutout(Detection &object);
305//void    drawScale(float xstart,float ystart,float channel,float scaleLength);
306  void    drawScale(float xstart,float ystart,float channel);
307  void    drawFieldEdge();
308
309private:
310  float  *recon;           // reconstructed array -- used when doing a trous reconstruction.
311  bool    reconExists;     // flag saying whether there is a reconstruction
312  short  *detectMap;       // "moment map" -- x,y locations of detected pixels
313  float  *baseline;        // array of spectral baseline values.
314                       
315  float  *specMean;        // array of means  for each spectrum in cube
316  float  *specSigma;       // array of sigmas for each spectrum in cube
317  float  *chanMean;        // array of means  for each channel map in cube
318  float  *chanSigma;       // array of sigmas for each channel map in cube
319       
320  FitsHeader head;         // the WCS and other header information.
321  vector<Col> fullCols;    // the list of all columns as printed in the results file
322  vector<Col> logCols;     // the list of columns as printed in the log file
323
324};
325
326/****************************************************************/
327//////////////////////////////////////////////////////
328// Prototypes for functions that use above classes
329//////////////////////////////////////////////////////
330
331DataArray getImage(string fname, short int maxdim);
332Image getImage(string fname);
333
334void findSources(Image &image);
335void findSources(Image &image, float mean, float sigma);
336
337vector <Detection> searchReconArray(long *dim,float *originalArray,float *reconArray, Param &par);
338vector <Detection> search3DArray(long *dim, float *Array, Param &par);
339
340void growObject(Detection &object, Image &image);
341void growObject(Detection &object, Cube &cube);
342
343#endif
Note: See TracBrowser for help on using the repository browser.