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