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