[299] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // cubes.hh: Definitions of the DataArray, Cube and Image classes. |
---|
| 3 | // ----------------------------------------------------------------------- |
---|
| 4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 5 | // |
---|
| 6 | // This program is free software; you can redistribute it and/or modify it |
---|
| 7 | // under the terms of the GNU General Public License as published by the |
---|
| 8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 9 | // option) any later version. |
---|
| 10 | // |
---|
| 11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 14 | // for more details. |
---|
| 15 | // |
---|
| 16 | // You should have received a copy of the GNU General Public License |
---|
| 17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 19 | // |
---|
| 20 | // Correspondence concerning Duchamp may be directed to: |
---|
| 21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 22 | // Postal address: Dr. Matthew Whiting |
---|
| 23 | // Australia Telescope National Facility, CSIRO |
---|
| 24 | // PO Box 76 |
---|
| 25 | // Epping NSW 1710 |
---|
| 26 | // AUSTRALIA |
---|
| 27 | // ----------------------------------------------------------------------- |
---|
[3] | 28 | #ifndef CUBES_H |
---|
| 29 | #define CUBES_H |
---|
| 30 | |
---|
| 31 | #include <iostream> |
---|
| 32 | #include <string> |
---|
| 33 | #include <vector> |
---|
| 34 | |
---|
[393] | 35 | #include <duchamp/param.hh> |
---|
| 36 | #include <duchamp/fitsHeader.hh> |
---|
| 37 | #include <duchamp/Detection/detection.hh> |
---|
| 38 | #include <duchamp/Detection/columns.hh> |
---|
| 39 | #include <duchamp/Cubes/plots.hh> |
---|
| 40 | #include <duchamp/Utils/Statistics.hh> |
---|
| 41 | #include <duchamp/PixelMap/Scan.hh> |
---|
| 42 | #include <duchamp/PixelMap/Object2D.hh> |
---|
[3] | 43 | |
---|
| 44 | |
---|
[378] | 45 | namespace duchamp |
---|
| 46 | { |
---|
[290] | 47 | |
---|
| 48 | |
---|
[378] | 49 | /** Search a reconstructed array for significant detections. */ |
---|
| 50 | std::vector <Detection> |
---|
| 51 | searchReconArray(long *dim, float *originalArray, float *reconArray, |
---|
| 52 | Param &par, Statistics::StatsContainer<float> &stats); |
---|
| 53 | std::vector <Detection> |
---|
| 54 | searchReconArraySimple(long *dim, float *originalArray, float *reconArray, |
---|
| 55 | Param &par, Statistics::StatsContainer<float> &stats); |
---|
[3] | 56 | |
---|
[378] | 57 | /** Search a 3-dimensional array for significant detections. */ |
---|
| 58 | std::vector <Detection> |
---|
| 59 | search3DArray(long *dim, float *Array, Param &par, |
---|
| 60 | Statistics::StatsContainer<float> &stats); |
---|
| 61 | std::vector <Detection> |
---|
| 62 | search3DArraySimple(long *dim, float *Array, Param &par, |
---|
| 63 | Statistics::StatsContainer<float> &stats); |
---|
[220] | 64 | |
---|
[378] | 65 | /** |
---|
| 66 | * Base class for the image container. |
---|
| 67 | * |
---|
| 68 | * Definition of an n-dimensional data array: |
---|
| 69 | * array of pixel values, size & dimensions |
---|
| 70 | * array of Detection objects |
---|
| 71 | */ |
---|
[220] | 72 | |
---|
[378] | 73 | class DataArray |
---|
| 74 | { |
---|
| 75 | public: |
---|
| 76 | DataArray(); ///< Basic DataArray constructor |
---|
| 77 | DataArray(short int nDim); ///< Basic nDim-dimensional DataArray constructor |
---|
| 78 | DataArray(short int nDim, long size);///< Basic nDim-dimensional DataArray constructor, specifying size. |
---|
| 79 | DataArray(short int nDim, long *dimensions); ///< Basic nDim-dimensional DataArray constructor, specifying size of dimensions. |
---|
| 80 | virtual ~DataArray(); ///< Basic DataArray constructor |
---|
[222] | 81 | |
---|
[378] | 82 | //----------------------------------------- |
---|
| 83 | // Obvious inline accessor functions. |
---|
| 84 | // |
---|
| 85 | long getDimX(){if(numDim>0) return axisDim[0];else return 0;}; |
---|
| 86 | long getDimY(){if(numDim>1) return axisDim[1];else return 1;}; |
---|
| 87 | long getDimZ(){if(numDim>2) return axisDim[2];else return 1;}; |
---|
| 88 | long getSize(){ return numPixels; }; |
---|
| 89 | short int getNumDim(){ return numDim; }; |
---|
| 90 | virtual float getPixValue(long pos){ return array[pos]; }; |
---|
| 91 | virtual void setPixValue(long pos, float f){array[pos] = f;}; |
---|
| 92 | Detection getObject(long number){ return objectList->at(number); }; |
---|
| 93 | std::vector <Detection> getObjectList(){ return *objectList; }; |
---|
[387] | 94 | std::vector <Detection> *pObjectList(){ return objectList; }; |
---|
| 95 | std::vector <Detection> &ObjectList(){ std::vector<Detection> &rlist = *objectList; return rlist; }; |
---|
[378] | 96 | long getNumObj(){ return objectList->size(); }; |
---|
[222] | 97 | |
---|
[378] | 98 | /** Delete all objects from the list of detections. */ |
---|
| 99 | void clearDetectionList(){ |
---|
| 100 | //objectList->clear(); |
---|
| 101 | delete objectList; |
---|
| 102 | objectList = new std::vector<Detection>; |
---|
| 103 | }; |
---|
[220] | 104 | |
---|
[378] | 105 | /** Read a parameter set from file. */ |
---|
| 106 | int readParam(std::string paramfile){ |
---|
| 107 | /** |
---|
| 108 | * Uses Param::readParams() to read parameters from a file. |
---|
| 109 | * \param paramfile The file to be read. |
---|
| 110 | */ |
---|
| 111 | return par.readParams(paramfile); |
---|
| 112 | }; |
---|
[222] | 113 | |
---|
[378] | 114 | //----------------------------------------- |
---|
| 115 | // Related to the various arrays |
---|
| 116 | // |
---|
| 117 | /** Return first three dimensional axes. */ |
---|
| 118 | void getDim(long &x, long &y, long &z); |
---|
| 119 | /** Return array of dimensional sizes.*/ |
---|
| 120 | void getDimArray(long *output); |
---|
| 121 | long * getDimArray(){return axisDim;}; |
---|
[222] | 122 | |
---|
[378] | 123 | /** Return pixel value array. */ |
---|
| 124 | void getArray(float *output); |
---|
| 125 | float * getArray(){return array;}; |
---|
[220] | 126 | |
---|
[378] | 127 | /** Save pixel value array. */ |
---|
| 128 | virtual void saveArray(float *input, long size); |
---|
[258] | 129 | |
---|
[378] | 130 | //----------------------------------------- |
---|
| 131 | // Related to the object lists |
---|
| 132 | // |
---|
| 133 | /** Adds a single detection to the object list.*/ |
---|
| 134 | void addObject(Detection object); |
---|
[222] | 135 | |
---|
[378] | 136 | /** Adds all objects in a detection list to the object list. */ |
---|
| 137 | void addObjectList(std::vector <Detection> newlist); |
---|
[220] | 138 | |
---|
[378] | 139 | /** Add pixel offsets to object coordinates. */ |
---|
| 140 | void addObjectOffsets(); |
---|
[3] | 141 | |
---|
[378] | 142 | //----------------------------------------- |
---|
| 143 | // Parameter list related. |
---|
| 144 | // |
---|
| 145 | /** Output the Param set.*/ |
---|
| 146 | void showParam(std::ostream &stream){ stream << par; }; |
---|
| 147 | /** Return the Param set.*/ |
---|
| 148 | Param getParam(){ return par; }; |
---|
| 149 | /** Save a Param set to the Cube.*/ |
---|
| 150 | void saveParam(Param &newpar){par = newpar;}; |
---|
| 151 | /** Provides a reference to the Param set.*/ |
---|
| 152 | Param& pars(){ Param &rpar = par; return rpar; }; |
---|
| 153 | /** Is the voxel number given by vox a BLANK value?*/ |
---|
| 154 | bool isBlank(int vox); |
---|
| 155 | |
---|
| 156 | // -------------------------------------------- |
---|
| 157 | // Statistics |
---|
| 158 | // |
---|
| 159 | /** Returns the StatsContainer. */ |
---|
| 160 | Statistics::StatsContainer<float> getStats(){ return Stats; }; |
---|
| 161 | |
---|
| 162 | /** Provides a reference to the StatsContainer. */ |
---|
| 163 | Statistics::StatsContainer<float>& stats(){ |
---|
| 164 | Statistics::StatsContainer<float> &rstats = Stats; return rstats; |
---|
| 165 | }; |
---|
[258] | 166 | |
---|
[378] | 167 | /** Save a StatsContainer to the Cube. */ |
---|
| 168 | void saveStats(Statistics::StatsContainer<float> newStats){ Stats = newStats;}; |
---|
[190] | 169 | |
---|
[378] | 170 | /** A detection test for value. */ |
---|
| 171 | bool isDetection(float value); |
---|
[222] | 172 | |
---|
[378] | 173 | /** A detection test for pixel. */ |
---|
| 174 | bool isDetection(long voxel); |
---|
[222] | 175 | |
---|
| 176 | |
---|
[378] | 177 | /** Output operator for DataArray.*/ |
---|
| 178 | friend std::ostream& operator<< (std::ostream& theStream, DataArray &array); |
---|
[222] | 179 | |
---|
[3] | 180 | |
---|
[378] | 181 | protected: |
---|
| 182 | short int numDim; ///< Number of dimensions. |
---|
| 183 | long *axisDim; ///< Array of dimensions of cube |
---|
| 184 | /// (ie. how large in each |
---|
| 185 | /// direction). |
---|
| 186 | long numPixels; ///< Total number of pixels in cube. |
---|
| 187 | float *array; ///< Array of data. |
---|
| 188 | std::vector <Detection> *objectList; ///< The list of detected objects. |
---|
| 189 | Param par; ///< A parameter list. |
---|
| 190 | Statistics::StatsContainer<float> Stats; ///< The statistics for the DataArray. |
---|
| 191 | }; |
---|
[3] | 192 | |
---|
[220] | 193 | |
---|
| 194 | |
---|
[378] | 195 | //========================================================================= |
---|
[220] | 196 | |
---|
[378] | 197 | /** |
---|
| 198 | * Definition of an data-cube object (3D): |
---|
| 199 | * a DataArray object limited to dim=3 |
---|
| 200 | */ |
---|
[3] | 201 | |
---|
[378] | 202 | class Cube : public DataArray |
---|
| 203 | { |
---|
| 204 | public: |
---|
| 205 | Cube(); ///< Basic Cube constructor. |
---|
| 206 | Cube(long nPix); ///< Alternative Cube constructor. |
---|
| 207 | Cube(long *dimensions); ///< Alternative Cube constructor. |
---|
| 208 | virtual ~Cube(); ///< Basic Cube destructor. |
---|
[3] | 209 | |
---|
[378] | 210 | // INLINE functions -- definitions included after class declaration. |
---|
| 211 | /** Is the voxel number given by vox a BLANK value? */ |
---|
| 212 | bool isBlank(int vox){ return par.isBlank(array[vox]); }; |
---|
[3] | 213 | |
---|
[378] | 214 | /** Is the voxel at (x,y,z) a BLANK value? */ |
---|
| 215 | bool isBlank(long x, long y, long z){ |
---|
| 216 | return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]); }; |
---|
[222] | 217 | |
---|
[378] | 218 | /** Does the Cube::recon array exist? */ |
---|
| 219 | bool isRecon(){ return reconExists; }; |
---|
[222] | 220 | |
---|
[378] | 221 | float getPixValue(long pos){ return array[pos]; }; |
---|
| 222 | float getPixValue(long x, long y, long z){ |
---|
| 223 | return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; }; |
---|
| 224 | short getDetectMapValue(long pos){ return detectMap[pos]; }; |
---|
| 225 | short getDetectMapValue(long x, long y){ return detectMap[y*axisDim[0]+x]; }; |
---|
| 226 | float getReconValue(long pos){ return recon[pos]; }; |
---|
| 227 | float getReconValue(long x, long y, long z){ |
---|
| 228 | return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];}; |
---|
| 229 | float getBaselineValue(long pos){ return baseline[pos]; }; |
---|
| 230 | float getBaselineValue(long x, long y, long z){ |
---|
| 231 | return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; }; |
---|
| 232 | void setPixValue(long pos, float f){array[pos] = f;};; |
---|
| 233 | void setPixValue(long x, long y, long z, float f){ |
---|
| 234 | array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;}; |
---|
| 235 | void setDetectMapValue(long pos, short f){ detectMap[pos] = f;}; |
---|
| 236 | void setDetectMapValue(long x, long y, short f){ detectMap[y*axisDim[0] + x] = f;}; |
---|
| 237 | void setReconValue(long pos, float f){recon[pos] = f;}; |
---|
| 238 | void setReconValue(long x, long y, long z, float f){ |
---|
| 239 | recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f; }; |
---|
| 240 | void setReconFlag(bool f){reconExists = f;}; |
---|
[222] | 241 | |
---|
[378] | 242 | std::vector<Column::Col> getLogCols(){return logCols;}; |
---|
| 243 | void setLogCols(std::vector<Column::Col> C){logCols=C;}; |
---|
| 244 | std::vector<Column::Col> getFullCols(){return fullCols;}; |
---|
| 245 | void setFullCols(std::vector<Column::Col> C){fullCols=C;}; |
---|
[222] | 246 | |
---|
[378] | 247 | // additional functions -- in Cubes/cubes.cc |
---|
| 248 | /** Allocate memory correctly, with WCS defining the correct axes. */ |
---|
| 249 | void initialiseCube(long *dimensions); |
---|
[222] | 250 | |
---|
[378] | 251 | /** Read in a FITS file, with subsection correction. */ |
---|
| 252 | int getCube(); |
---|
[222] | 253 | |
---|
[378] | 254 | /** Read in command-line options. */ |
---|
| 255 | // int getopts(int argc, char ** argv); |
---|
| 256 | int getopts(int argc, char ** argv){return par.getopts(argc,argv);}; |
---|
[222] | 257 | |
---|
[378] | 258 | /** Read in reconstructed & smoothed arrays from FITS files on disk. */ |
---|
| 259 | void readSavedArrays(); |
---|
[222] | 260 | |
---|
[378] | 261 | /** Save an external array to the Cube's pixel array */ |
---|
| 262 | void saveArray(float *input, long size); |
---|
[222] | 263 | |
---|
[378] | 264 | /** Save an external array to the Cube's reconstructed array. */ |
---|
| 265 | void saveRecon(float *input, long size); |
---|
[222] | 266 | |
---|
[378] | 267 | /** Save reconstructed array to an external array. */ |
---|
| 268 | void getRecon(float *output); |
---|
[387] | 269 | float * getRecon(){return recon; }; |
---|
[222] | 270 | |
---|
[378] | 271 | /** Set Milky Way channels to zero. */ |
---|
| 272 | void removeMW(); |
---|
[222] | 273 | |
---|
[378] | 274 | //------------------------ |
---|
| 275 | // Statistics for cube |
---|
| 276 | // |
---|
[222] | 277 | |
---|
[378] | 278 | /** Calculate the statistics for the Cube (older version). */ |
---|
| 279 | void setCubeStatsOld(); |
---|
[222] | 280 | |
---|
[378] | 281 | /** Calculate the statistics for the Cube. */ |
---|
| 282 | void setCubeStats(); |
---|
[222] | 283 | |
---|
[378] | 284 | /** Set up thresholds for the False Discovery Rate routine. */ |
---|
| 285 | void setupFDR(); |
---|
| 286 | /** Set up thresholds for the False Discovery Rate routine using a |
---|
| 287 | particular array. */ |
---|
| 288 | void setupFDR(float *input); |
---|
[222] | 289 | |
---|
[378] | 290 | /** A detection test for a given voxel. */ |
---|
| 291 | bool isDetection(long x, long y, long z); |
---|
[222] | 292 | |
---|
[378] | 293 | //----------------------------- |
---|
| 294 | // Dealing with the detections |
---|
| 295 | // |
---|
[222] | 296 | |
---|
[378] | 297 | /** Calculate the WCS parameters for each Cube Detection. */ |
---|
| 298 | void calcObjectWCSparams(); |
---|
[222] | 299 | |
---|
[378] | 300 | /** Sort the list of detections. */ |
---|
| 301 | void sortDetections(); |
---|
[222] | 302 | |
---|
[378] | 303 | /** Update the map of detected pixels. */ |
---|
| 304 | void updateDetectMap(); |
---|
[222] | 305 | |
---|
[378] | 306 | /** Update the map of detected pixels for a given Detection. */ |
---|
| 307 | void updateDetectMap(Detection obj); |
---|
[222] | 308 | |
---|
[378] | 309 | /** Clear the map of detected pixels. */ |
---|
| 310 | void clearDetectMap(){ |
---|
| 311 | for(int i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0; |
---|
| 312 | }; |
---|
[290] | 313 | |
---|
[378] | 314 | /** Find the flux enclosed by a Detection. */ |
---|
| 315 | float enclosedFlux(Detection obj); |
---|
[222] | 316 | |
---|
[378] | 317 | /** Set up the output column definitions for the Cube and its |
---|
| 318 | Detection list. */ |
---|
| 319 | void setupColumns(); |
---|
[222] | 320 | |
---|
[378] | 321 | /** Is the object at the edge of the image? */ |
---|
| 322 | bool objAtSpatialEdge(Detection obj); |
---|
[222] | 323 | |
---|
[378] | 324 | /** Is the object at an end of the spectrum? */ |
---|
| 325 | bool objAtSpectralEdge(Detection obj); |
---|
[222] | 326 | |
---|
[378] | 327 | /** Set warning flags for the detections. */ |
---|
| 328 | void setObjectFlags(); |
---|
[222] | 329 | |
---|
[378] | 330 | // ---------------------------- |
---|
| 331 | // Dealing with the WCS |
---|
| 332 | // |
---|
| 333 | /** Return the FitsHeader object. */ |
---|
| 334 | FitsHeader getHead(){ return head; }; |
---|
| 335 | /** Define the FitsHeader object. */ |
---|
| 336 | void setHead(FitsHeader F){head = F;}; |
---|
| 337 | /** Provide a reference to the FitsHeader object.*/ |
---|
| 338 | FitsHeader& header(){ FitsHeader &h = head; return h; }; |
---|
[3] | 339 | |
---|
[378] | 340 | /** Convert a point from WCS to Pixel coords. */ |
---|
| 341 | int wcsToPix(const double *world, double *pix); |
---|
[222] | 342 | |
---|
[378] | 343 | /** Convert a set of points from WCS to Pixel coords. */ |
---|
| 344 | int wcsToPix(const double *world, double *pix, const int npts); |
---|
[222] | 345 | |
---|
[378] | 346 | /** Convert a point from Pixel to WCS coords. */ |
---|
| 347 | int pixToWCS(const double *pix, double *world); |
---|
[222] | 348 | |
---|
[378] | 349 | /** Convert a set of points from Pixel to WCS coords. */ |
---|
| 350 | int pixToWCS(const double *pix, double *world, const int npts); |
---|
[222] | 351 | |
---|
[378] | 352 | //------------------------------------------- |
---|
| 353 | // FITS-I/O related functions -- not in cubes.cc |
---|
| 354 | // |
---|
| 355 | /** Function to read in FITS file.*/ |
---|
| 356 | int getCube(std::string fname); // in Cubes/getImage.cc |
---|
[3] | 357 | |
---|
[378] | 358 | /** Function to retrieve FITS data array */ |
---|
| 359 | int getFITSdata(std::string fname); // in FitsIO/dataIO.cc |
---|
[222] | 360 | |
---|
[379] | 361 | /** Save a mask array to disk.*/ |
---|
| 362 | void saveMaskCube(); // in Cubes/saveImage.cc |
---|
| 363 | |
---|
| 364 | /** Save Smoothed array to disk.*/ |
---|
[378] | 365 | void saveSmoothedCube(); // in Cubes/saveImage.cc |
---|
[258] | 366 | |
---|
[378] | 367 | /** Save Reconstructed array to disk. */ |
---|
| 368 | void saveReconstructedCube(); // in Cubes/saveImage.cc |
---|
[222] | 369 | |
---|
[378] | 370 | /** Read in reconstructed array from FITS file. */ |
---|
| 371 | int readReconCube(); // in Cubes/readRecon.cc |
---|
[222] | 372 | |
---|
[378] | 373 | /** Read in Hanning-smoothed array from FITS file. */ |
---|
| 374 | int readSmoothCube(); // in Cubes/readSmooth.cc |
---|
[222] | 375 | |
---|
[378] | 376 | //------------------------------------- |
---|
| 377 | // Functions that act on the cube |
---|
| 378 | // |
---|
[3] | 379 | |
---|
[378] | 380 | /** Remove excess BLANK pixels from spatial edge of cube. */ |
---|
| 381 | void trimCube(); // in Cubes/trimImage.cc |
---|
[222] | 382 | |
---|
[378] | 383 | /** Replace BLANK pixels to spatial edge of cube. */ |
---|
| 384 | void unTrimCube(); // in Cubes/trimImage.cc |
---|
[222] | 385 | |
---|
[378] | 386 | /** Removes the baselines from the spectra, and stores in Cube::baseline */ |
---|
| 387 | void removeBaseline(); // in Cubes/baseline.cc |
---|
[222] | 388 | |
---|
[378] | 389 | /** Replace the baselines stored in Cube::baseline */ |
---|
| 390 | void replaceBaseline(); // in Cubes/baseline.cc |
---|
[222] | 391 | |
---|
[378] | 392 | /** Multiply all pixel values by -1. */ |
---|
| 393 | void invert(); // in Cubes/invertCube.cc |
---|
[222] | 394 | |
---|
[378] | 395 | /** Undo the inversion, and invert fluxes of all detected objects. */ |
---|
| 396 | void reInvert(); // in Cubes/invertCube.cc |
---|
[222] | 397 | |
---|
[378] | 398 | //------------------------------------- |
---|
| 399 | // Reconstruction, Searching and Merging functions |
---|
| 400 | // |
---|
| 401 | // in ATrous/ReconSearch.cc |
---|
| 402 | /** Front-end to reconstruction & searching functions.*/ |
---|
| 403 | void ReconSearch(); |
---|
| 404 | /** Switcher to reconstruction functions */ |
---|
| 405 | void ReconCube(); |
---|
| 406 | /** Performs 1-dimensional a trous reconstruction on the Cube. */ |
---|
| 407 | void ReconCube1D(); |
---|
| 408 | /** Performs 2-dimensional a trous reconstruction on the Cube. */ |
---|
| 409 | void ReconCube2D(); |
---|
| 410 | /** Performs 3-dimensional a trous reconstruction on the Cube. */ |
---|
| 411 | void ReconCube3D(); |
---|
[222] | 412 | |
---|
[378] | 413 | // in Cubes/CubicSearch.cc |
---|
| 414 | /** Front-end to the cubic searching routine. */ |
---|
| 415 | void CubicSearch(); |
---|
[222] | 416 | |
---|
[378] | 417 | // in Cubes/smoothCube.cc |
---|
| 418 | /** Smooth the cube with the requested method.*/ |
---|
| 419 | void SmoothCube(); |
---|
| 420 | /** Front-end to the smoothing and searching functions. */ |
---|
| 421 | void SmoothSearch(); |
---|
| 422 | /** A function to spatially smooth the cube and search the result. */ |
---|
| 423 | void SpatialSmoothNSearch(); |
---|
| 424 | /** A function to Hanning-smooth the cube. */ |
---|
| 425 | void SpectralSmooth(); |
---|
| 426 | /** A function to spatially-smooth the cube. */ |
---|
| 427 | void SpatialSmooth(); |
---|
[222] | 428 | |
---|
[378] | 429 | void Simple3DSearch(){ |
---|
| 430 | /** |
---|
| 431 | * Basic front-end to the simple 3d searching function -- does |
---|
| 432 | * nothing more. |
---|
| 433 | * |
---|
| 434 | * This function just runs the search3DArraySimple function, |
---|
| 435 | * storing the results in the Cube::objectList vector. No stats |
---|
| 436 | * are calculated beforehand, and no logging or detection map |
---|
| 437 | * updating is done. |
---|
| 438 | */ |
---|
| 439 | *objectList = search3DArraySimple(axisDim,array,par,Stats); |
---|
| 440 | }; |
---|
[290] | 441 | |
---|
[378] | 442 | void Simple3DSearchRecon(){ |
---|
| 443 | /** |
---|
| 444 | * Basic front-end to the 3d searching function used in the |
---|
| 445 | * reconstruction case -- does nothing more. |
---|
| 446 | * |
---|
| 447 | * This function just runs the searchReconArraySimple function, |
---|
| 448 | * storing the results in the Cube::objectList vector. No stats |
---|
| 449 | * are calculated beforehand, and no logging or detection map |
---|
| 450 | * updating is done. The recon array is assumed to have been |
---|
| 451 | * defined already. |
---|
| 452 | */ |
---|
| 453 | *objectList = searchReconArraySimple(axisDim,array,recon,par,Stats); |
---|
| 454 | }; |
---|
[290] | 455 | |
---|
[378] | 456 | void Simple3DSearchSmooth(){ |
---|
| 457 | /** |
---|
| 458 | * Basic front-end to the simple 3d searching function run on the |
---|
| 459 | * smoothed array -- does nothing more. |
---|
| 460 | * |
---|
| 461 | * This function just runs the search3DArraySimple function on the |
---|
| 462 | * recon array (which contains the smoothed array), storing the |
---|
| 463 | * results in the Cube::objectList vector. No stats are calculated |
---|
| 464 | * beforehand, and no logging or detection map updating is |
---|
| 465 | * done. The recon array is assumed to have been defined already. |
---|
| 466 | */ |
---|
| 467 | *objectList = search3DArraySimple(axisDim,recon,par,Stats); |
---|
| 468 | }; |
---|
[290] | 469 | |
---|
[378] | 470 | // in Cubes/Merger.cc |
---|
| 471 | /** Merge all objects in the detection list so that only distinct |
---|
| 472 | ones are left. */ |
---|
| 473 | void ObjectMerger(); |
---|
[103] | 474 | |
---|
[378] | 475 | //------------------------------------- |
---|
| 476 | // Text outputting of detected objects. |
---|
| 477 | // in Cubes/detectionIO.cc |
---|
| 478 | // |
---|
| 479 | /** Set up the output file with parameters and stats. */ |
---|
| 480 | void prepareOutputFile(); |
---|
[3] | 481 | |
---|
[378] | 482 | /** Write the statistical information to the output file. */ |
---|
| 483 | void outputStats(); |
---|
[222] | 484 | |
---|
[378] | 485 | /** Output detections to the output file and standard output. */ |
---|
| 486 | void outputDetectionList(); |
---|
[222] | 487 | |
---|
[378] | 488 | /** Output detections to the log file. */ |
---|
| 489 | void logDetectionList(); |
---|
[222] | 490 | |
---|
[378] | 491 | /** Output a single detection to the log file. */ |
---|
| 492 | void logDetection(Detection obj, int counter); |
---|
[222] | 493 | |
---|
[378] | 494 | /** Output detections to a Karma annotation file. */ |
---|
| 495 | void outputDetectionsKarma(std::ostream &stream); |
---|
[222] | 496 | |
---|
[378] | 497 | /** Output detections to a VOTable. */ |
---|
| 498 | void outputDetectionsVOTable(std::ostream &stream); |
---|
[275] | 499 | |
---|
[378] | 500 | // ---------------------------------- |
---|
| 501 | // Graphical plotting of the cube and the detections. |
---|
| 502 | // |
---|
| 503 | // in Cubes/plotting.cc |
---|
| 504 | /** Plot a spatial map of detections based on number of detected |
---|
| 505 | channels. */ |
---|
| 506 | void plotDetectionMap(std::string pgDestination); |
---|
[3] | 507 | |
---|
[378] | 508 | /** Plot a spatial map of detections based on 0th moment map of each |
---|
| 509 | object. */ |
---|
| 510 | void plotMomentMap(std::string pgDestination); |
---|
[222] | 511 | |
---|
[378] | 512 | /** Plot a spatial map of detections based on 0th moment map of each |
---|
| 513 | object to a number of PGPLOT devices. */ |
---|
| 514 | void plotMomentMap(std::vector<std::string> pgDestination); |
---|
[222] | 515 | |
---|
[378] | 516 | /** Draw WCS axes over a PGPLOT map. */ |
---|
| 517 | void plotWCSaxes(); |
---|
[222] | 518 | |
---|
[378] | 519 | // in Cubes/outputSpectra.cc |
---|
| 520 | /** Print spectra of each detected object. */ |
---|
| 521 | void outputSpectra(); |
---|
[222] | 522 | |
---|
[378] | 523 | /** Print spectrum of a single object */ |
---|
| 524 | void plotSpectrum(Detection obj,Plot::SpectralPlot &plot); |
---|
| 525 | /** Plot the image cutout for a single object */ |
---|
| 526 | void plotSource(Detection obj, Plot::CutoutPlot &plot); |
---|
[222] | 527 | |
---|
[378] | 528 | // in Cubes/drawMomentCutout.cc |
---|
| 529 | /** Draw the 0th moment map for a single object. */ |
---|
| 530 | void drawMomentCutout(Detection &object); |
---|
[220] | 531 | |
---|
[378] | 532 | /** Draw a scale bar indicating angular size of the cutout. */ |
---|
| 533 | void drawScale(float xstart,float ystart,float channel); |
---|
[222] | 534 | |
---|
[378] | 535 | /** Draw a yellow line around the edge of the spatial extent of |
---|
| 536 | pixels. */ |
---|
| 537 | void drawFieldEdge(); |
---|
[222] | 538 | |
---|
[378] | 539 | private: |
---|
| 540 | float *recon; ///< reconstructed array - used when |
---|
| 541 | /// doing a trous reconstruction. |
---|
| 542 | bool reconExists; ///< flag saying whether there is a |
---|
| 543 | /// reconstruction |
---|
| 544 | short *detectMap; ///< "moment map" - x,y locations of |
---|
| 545 | /// detected pixels |
---|
| 546 | float *baseline; ///< array of spectral baseline |
---|
| 547 | /// values. |
---|
[219] | 548 | |
---|
[378] | 549 | bool reconAllocated; ///< have we allocated memory for the |
---|
| 550 | /// recon array? |
---|
| 551 | bool baselineAllocated;///< have we allocated memory for the |
---|
| 552 | /// baseline array? |
---|
| 553 | FitsHeader head; ///< the WCS and other header |
---|
| 554 | /// information. |
---|
| 555 | std::vector<Column::Col> fullCols; ///< the list of all columns as |
---|
| 556 | /// printed in the results file |
---|
| 557 | std::vector<Column::Col> logCols; ///< the list of columns as printed in |
---|
| 558 | /// the log file |
---|
[205] | 559 | |
---|
[378] | 560 | }; |
---|
[103] | 561 | |
---|
[378] | 562 | //////////// |
---|
| 563 | //// Cube inline function definitions |
---|
| 564 | //////////// |
---|
[220] | 565 | |
---|
[378] | 566 | inline int Cube::wcsToPix(const double *world, double *pix) |
---|
| 567 | { |
---|
| 568 | /** |
---|
| 569 | * Use the WCS in the FitsHeader to convert from WCS to pixel coords for |
---|
| 570 | * a single point. |
---|
| 571 | * \param world The world coordinates. |
---|
| 572 | * \param pix The returned pixel coordinates. |
---|
| 573 | */ |
---|
| 574 | return this->head.wcsToPix(world,pix); |
---|
| 575 | } |
---|
| 576 | inline int Cube::wcsToPix(const double *world, double *pix, const int npts) |
---|
| 577 | { |
---|
| 578 | /** |
---|
| 579 | * Use the WCS in the FitsHeader to convert from WCS to pixel coords for |
---|
| 580 | * a set of points. |
---|
| 581 | * \param world The world coordinates. |
---|
| 582 | * \param pix The returned pixel coordinates. |
---|
| 583 | * \param npts The number of points being converted. |
---|
| 584 | */ |
---|
| 585 | return this->head.wcsToPix(world,pix,npts); |
---|
| 586 | } |
---|
| 587 | inline int Cube::pixToWCS(const double *pix, double *world) |
---|
| 588 | { |
---|
| 589 | /** |
---|
| 590 | * Use the WCS in the FitsHeader to convert from pixel to WCS coords for |
---|
| 591 | * a single point. |
---|
| 592 | * \param pix The pixel coordinates. |
---|
| 593 | * \param world The returned world coordinates. |
---|
| 594 | */ |
---|
| 595 | return this->head.pixToWCS(pix,world); |
---|
| 596 | } |
---|
| 597 | inline int Cube::pixToWCS(const double *pix, double *world, const int npts) |
---|
| 598 | { |
---|
| 599 | /** |
---|
| 600 | * Use the WCS in the FitsHeader to convert from pixel to WCS coords for |
---|
| 601 | * a set of points. |
---|
| 602 | * \param pix The pixel coordinates. |
---|
| 603 | * \param world The returned world coordinates. |
---|
| 604 | * \param npts The number of points being converted. |
---|
| 605 | */ |
---|
| 606 | return this->head.pixToWCS(pix,world,npts); |
---|
| 607 | } |
---|
[220] | 608 | |
---|
| 609 | |
---|
[378] | 610 | //============================================================================ |
---|
[220] | 611 | |
---|
[378] | 612 | /** |
---|
| 613 | * A DataArray object limited to two dimensions, and with some additional |
---|
| 614 | * special functions. |
---|
| 615 | * |
---|
| 616 | * It is used primarily for searching a 1- or 2-D array with |
---|
| 617 | * lutz_detect() and spectrumDetect(). |
---|
| 618 | */ |
---|
[219] | 619 | |
---|
[378] | 620 | class Image : public DataArray |
---|
| 621 | { |
---|
| 622 | public: |
---|
| 623 | Image(){numPixels=0; numDim=2;}; |
---|
| 624 | Image(long nPix); |
---|
| 625 | Image(long *dimensions); |
---|
| 626 | virtual ~Image(){}; |
---|
[219] | 627 | |
---|
[378] | 628 | //-------------------- |
---|
| 629 | // Defining the array |
---|
| 630 | // |
---|
| 631 | /** Save an external array to the Cube's pixel array */ |
---|
| 632 | void saveArray(float *input, long size); |
---|
[222] | 633 | |
---|
[378] | 634 | /** Extract a spectrum from an array and save to the local pixel array. */ |
---|
| 635 | void extractSpectrum(float *Array, long *dim, long pixel); |
---|
[222] | 636 | |
---|
[378] | 637 | /** Extract an image from an array and save to the local pixel array. */ |
---|
| 638 | void extractImage(float *Array, long *dim, long channel); |
---|
[222] | 639 | |
---|
[378] | 640 | /** Extract a spectrum from a cube and save to the local pixel array. */ |
---|
| 641 | void extractSpectrum(Cube &cube, long pixel); |
---|
[222] | 642 | |
---|
[378] | 643 | /** Extract an image from a cube and save to the local pixel array. */ |
---|
| 644 | void extractImage(Cube &cube, long channel); |
---|
[222] | 645 | |
---|
[378] | 646 | //-------------------- |
---|
| 647 | // Accessing the data. |
---|
| 648 | // |
---|
| 649 | float getPixValue(long pos){ return array[pos]; }; |
---|
| 650 | float getPixValue(long x, long y){return array[y*axisDim[0] + x];}; |
---|
| 651 | // the next few should have checks against array overflow... |
---|
| 652 | void setPixValue(long pos, float f){array[pos] = f;};; |
---|
| 653 | void setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;}; |
---|
| 654 | bool isBlank(int vox){return par.isBlank(array[vox]);}; |
---|
| 655 | bool isBlank(long x,long y){return par.isBlank(array[y*axisDim[0]+x]);}; |
---|
[219] | 656 | |
---|
[378] | 657 | //----------------------- |
---|
| 658 | // Detection-related |
---|
| 659 | // |
---|
| 660 | // in Detection/lutz_detect.cc: |
---|
| 661 | /** Detect objects in a 2-D image */ |
---|
| 662 | std::vector<PixelInfo::Object2D> lutz_detect(); |
---|
[222] | 663 | |
---|
[378] | 664 | // in Detection/spectrumDetect.cc: |
---|
| 665 | /** Detect objects in a 1-D spectrum */ |
---|
| 666 | std::vector<PixelInfo::Scan> spectrumDetect(); |
---|
[222] | 667 | |
---|
[378] | 668 | int getMinSize(){return minSize;}; |
---|
| 669 | void setMinSize(int i){minSize=i;}; |
---|
[222] | 670 | |
---|
[378] | 671 | /** A detection test for a pixel location. */ |
---|
| 672 | bool isDetection(long x, long y){ |
---|
| 673 | /** |
---|
| 674 | * Test whether a pixel (x,y) is a statistically significant detection, |
---|
| 675 | * according to the set of statistics in the local StatsContainer object. |
---|
| 676 | */ |
---|
| 677 | long voxel = y*axisDim[0] + x; |
---|
| 678 | if(isBlank(x,y)) return false; |
---|
| 679 | else return Stats.isDetection(array[voxel]); |
---|
| 680 | }; |
---|
[219] | 681 | |
---|
[378] | 682 | /** Blank out a set of channels marked as being Milky Way channels */ |
---|
| 683 | void removeMW(); |
---|
[258] | 684 | |
---|
[378] | 685 | private: |
---|
| 686 | int minSize; ///< the minimum number of pixels for a |
---|
| 687 | /// detection to be accepted. |
---|
| 688 | }; |
---|
[3] | 689 | |
---|
[219] | 690 | |
---|
[378] | 691 | /****************************************************************/ |
---|
| 692 | ////////////////////////////////////////////////////// |
---|
| 693 | // Prototypes for functions that use above classes |
---|
| 694 | ////////////////////////////////////////////////////// |
---|
[3] | 695 | |
---|
[378] | 696 | /** Grow an object to a lower threshold */ |
---|
| 697 | void growObject(Detection &object, Cube &cube); |
---|
[3] | 698 | |
---|
[378] | 699 | /** Draw the edge of the BLANK region on a map.*/ |
---|
| 700 | void drawBlankEdges(float *dataArray, int xdim, int ydim, Param &par); |
---|
[222] | 701 | |
---|
[378] | 702 | } |
---|
| 703 | |
---|
[3] | 704 | #endif |
---|