[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 | |
---|
[459] | 35 | #include <duchamp/duchamp.hh> |
---|
[393] | 36 | #include <duchamp/param.hh> |
---|
| 37 | #include <duchamp/fitsHeader.hh> |
---|
| 38 | #include <duchamp/Detection/detection.hh> |
---|
[1061] | 39 | #include <duchamp/Outputs/columns.hh> |
---|
[1064] | 40 | #include <duchamp/Outputs/CatalogueSpecification.hh> |
---|
[1242] | 41 | // #include <duchamp/Cubes/plots.hh> |
---|
| 42 | #include <duchamp/Plotting/SpectralPlot.hh> |
---|
| 43 | #include <duchamp/Plotting/CutoutPlot.hh> |
---|
[393] | 44 | #include <duchamp/Utils/Statistics.hh> |
---|
| 45 | #include <duchamp/PixelMap/Scan.hh> |
---|
| 46 | #include <duchamp/PixelMap/Object2D.hh> |
---|
[3] | 47 | |
---|
| 48 | |
---|
[378] | 49 | namespace duchamp |
---|
| 50 | { |
---|
[290] | 51 | |
---|
| 52 | |
---|
[528] | 53 | /// @brief Search a reconstructed array for significant detections. |
---|
[884] | 54 | std::vector <Detection> searchReconArray(size_t *dim, float *originalArray, float *reconArray, |
---|
[686] | 55 | Param &par, Statistics::StatsContainer<float> &stats); |
---|
[884] | 56 | std::vector <Detection> searchReconArraySpectral(size_t *dim, float *originalArray, float *reconArray, |
---|
[686] | 57 | Param &par, Statistics::StatsContainer<float> &stats); |
---|
[884] | 58 | std::vector <Detection> searchReconArraySpatial(size_t *dim, float *originalArray, float *reconArray, |
---|
[686] | 59 | Param &par, Statistics::StatsContainer<float> &stats); |
---|
[3] | 60 | |
---|
[528] | 61 | /// @brief Search a 3-dimensional array for significant detections. |
---|
[884] | 62 | std::vector <Detection> search3DArray(size_t *dim, float *Array, Param &par, |
---|
[686] | 63 | Statistics::StatsContainer<float> &stats); |
---|
[884] | 64 | std::vector <Detection> search3DArraySpectral(size_t *dim, float *Array, Param &par, |
---|
[686] | 65 | Statistics::StatsContainer<float> &stats); |
---|
[884] | 66 | std::vector <Detection> search3DArraySpatial(size_t *dim, float *Array, Param &par, |
---|
[686] | 67 | Statistics::StatsContainer<float> &stats); |
---|
[220] | 68 | |
---|
[1242] | 69 | void plotWCSaxes(struct wcsprm *wcs, size_t *axes, int textColour=DUCHAMP_ID_TEXT_COLOUR, int axisColour=DUCHAMP_WCS_AXIS_COLOUR); |
---|
| 70 | |
---|
| 71 | |
---|
[528] | 72 | //========================================================================= |
---|
[220] | 73 | |
---|
[899] | 74 | /// An enumeration allowing us to refer to a particular array within functions |
---|
| 75 | enum ARRAYREF {ARRAY=0, RECON, BASELINE}; |
---|
| 76 | |
---|
| 77 | |
---|
[528] | 78 | /// @brief Base class for the image container. |
---|
| 79 | /// |
---|
| 80 | /// @details Definition of an n-dimensional data array: array of |
---|
| 81 | /// pixel values, size & dimensions array of Detection objects |
---|
| 82 | |
---|
[378] | 83 | class DataArray |
---|
| 84 | { |
---|
| 85 | public: |
---|
| 86 | DataArray(); ///< Basic DataArray constructor |
---|
| 87 | DataArray(short int nDim); ///< Basic nDim-dimensional DataArray constructor |
---|
[884] | 88 | DataArray(short int nDim, size_t size);///< Basic nDim-dimensional DataArray constructor, specifying size. |
---|
| 89 | DataArray(short int nDim, size_t *dimensions); ///< Basic nDim-dimensional DataArray constructor, specifying size of dimensions. |
---|
[378] | 90 | virtual ~DataArray(); ///< Basic DataArray constructor |
---|
[736] | 91 | DataArray(const DataArray &d); |
---|
| 92 | DataArray& operator=(const DataArray &d); |
---|
[222] | 93 | |
---|
[378] | 94 | //----------------------------------------- |
---|
| 95 | // Obvious inline accessor functions. |
---|
| 96 | // |
---|
[884] | 97 | size_t getDimX(){if(numDim>0) return axisDim[0];else return 0;}; |
---|
| 98 | size_t getDimY(){if(numDim>1) return axisDim[1];else return 1;}; |
---|
| 99 | size_t getDimZ(){if(numDim>2) return axisDim[2];else return 1;}; |
---|
| 100 | size_t getSize(){ return numPixels; }; |
---|
[1120] | 101 | size_t getSpatialSize(){if(numDim>1) return axisDim[0]*axisDim[1]; else if(numDim>0) return axisDim[0]; else return 0;}; |
---|
[378] | 102 | short int getNumDim(){ return numDim; }; |
---|
[884] | 103 | virtual float getPixValue(size_t pos){ return array[pos]; }; |
---|
| 104 | virtual void setPixValue(size_t pos, float f){array[pos] = f;}; |
---|
| 105 | Detection getObject(size_t number){ return objectList->at(number); }; |
---|
| 106 | Detection * pObject(size_t number){ return &(objectList->at(number));}; |
---|
[378] | 107 | std::vector <Detection> getObjectList(){ return *objectList; }; |
---|
[387] | 108 | std::vector <Detection> *pObjectList(){ return objectList; }; |
---|
| 109 | std::vector <Detection> &ObjectList(){ std::vector<Detection> &rlist = *objectList; return rlist; }; |
---|
[884] | 110 | size_t getNumObj(){ return objectList->size(); }; |
---|
[222] | 111 | |
---|
[528] | 112 | /// @brief Delete all objects from the list of detections. |
---|
[378] | 113 | void clearDetectionList(){ |
---|
| 114 | //objectList->clear(); |
---|
| 115 | delete objectList; |
---|
| 116 | objectList = new std::vector<Detection>; |
---|
| 117 | }; |
---|
[220] | 118 | |
---|
[528] | 119 | /// @brief Read a parameter set from file. |
---|
[700] | 120 | OUTCOME readParam(std::string paramfile){ |
---|
[528] | 121 | /// @brief |
---|
[531] | 122 | /// Uses Param::readParams() to read parameters from a file. |
---|
| 123 | /// \param paramfile The file to be read. |
---|
[528] | 124 | |
---|
[378] | 125 | return par.readParams(paramfile); |
---|
| 126 | }; |
---|
[222] | 127 | |
---|
[378] | 128 | //----------------------------------------- |
---|
| 129 | // Related to the various arrays |
---|
| 130 | // |
---|
[528] | 131 | /// @brief Return first three dimensional axes. |
---|
[884] | 132 | void getDim(size_t &x, size_t &y, size_t &z); |
---|
[528] | 133 | /// @brief Return array of dimensional sizes. |
---|
[884] | 134 | void getDimArray(size_t *output); |
---|
| 135 | size_t * getDimArray(){return axisDim;}; |
---|
[222] | 136 | |
---|
[528] | 137 | /// @brief Return pixel value array. |
---|
[378] | 138 | void getArray(float *output); |
---|
| 139 | float * getArray(){return array;}; |
---|
[220] | 140 | |
---|
[528] | 141 | /// @brief Save pixel value array. |
---|
[884] | 142 | virtual void saveArray(float *input, size_t size); |
---|
[258] | 143 | |
---|
[378] | 144 | //----------------------------------------- |
---|
| 145 | // Related to the object lists |
---|
| 146 | // |
---|
[528] | 147 | /// @brief Adds a single detection to the object list. |
---|
[378] | 148 | void addObject(Detection object); |
---|
[222] | 149 | |
---|
[528] | 150 | /// @brief Adds all objects in a detection list to the object list. |
---|
[378] | 151 | void addObjectList(std::vector <Detection> newlist); |
---|
[220] | 152 | |
---|
[528] | 153 | /// @brief Add pixel offsets to object coordinates. |
---|
[378] | 154 | void addObjectOffsets(); |
---|
[3] | 155 | |
---|
[378] | 156 | //----------------------------------------- |
---|
| 157 | // Parameter list related. |
---|
| 158 | // |
---|
[528] | 159 | /// @brief Output the Param set. |
---|
[378] | 160 | void showParam(std::ostream &stream){ stream << par; }; |
---|
[528] | 161 | /// @brief Return the Param set. |
---|
[378] | 162 | Param getParam(){ return par; }; |
---|
[528] | 163 | /// @brief Save a Param set to the Cube. |
---|
[378] | 164 | void saveParam(Param &newpar){par = newpar;}; |
---|
[528] | 165 | /// @brief Provides a reference to the Param set. |
---|
[378] | 166 | Param& pars(){ Param &rpar = par; return rpar; }; |
---|
[528] | 167 | /// @brief Is the voxel number given by vox a BLANK value? |
---|
[741] | 168 | bool isBlank(int vox){return par.isBlank(array[vox]);}; |
---|
[378] | 169 | |
---|
| 170 | // -------------------------------------------- |
---|
| 171 | // Statistics |
---|
| 172 | // |
---|
[528] | 173 | /// @brief Returns the StatsContainer. |
---|
[378] | 174 | Statistics::StatsContainer<float> getStats(){ return Stats; }; |
---|
| 175 | |
---|
[528] | 176 | /// @brief Provides a reference to the StatsContainer. |
---|
[378] | 177 | Statistics::StatsContainer<float>& stats(){ |
---|
| 178 | Statistics::StatsContainer<float> &rstats = Stats; return rstats; |
---|
| 179 | }; |
---|
[258] | 180 | |
---|
[528] | 181 | /// @brief Save a StatsContainer to the Cube. |
---|
[378] | 182 | void saveStats(Statistics::StatsContainer<float> newStats){ Stats = newStats;}; |
---|
[190] | 183 | |
---|
[528] | 184 | /// @brief A detection test for value. |
---|
[378] | 185 | bool isDetection(float value); |
---|
[222] | 186 | |
---|
[528] | 187 | /// @brief A detection test for pixel. |
---|
[884] | 188 | bool isDetection(size_t voxel); |
---|
[222] | 189 | |
---|
| 190 | |
---|
[528] | 191 | /// @brief Output operator for DataArray. |
---|
[378] | 192 | friend std::ostream& operator<< (std::ostream& theStream, DataArray &array); |
---|
[222] | 193 | |
---|
[3] | 194 | |
---|
[378] | 195 | protected: |
---|
| 196 | short int numDim; ///< Number of dimensions. |
---|
[884] | 197 | size_t *axisDim; ///< Array of axis dimensions of cube |
---|
[443] | 198 | bool axisDimAllocated; ///< has axisDim been allocated? |
---|
[884] | 199 | size_t numPixels; ///< Total number of pixels in cube. |
---|
[378] | 200 | float *array; ///< Array of data. |
---|
[444] | 201 | bool arrayAllocated; ///< has the array been allocated? |
---|
[378] | 202 | std::vector <Detection> *objectList; ///< The list of detected objects. |
---|
| 203 | Param par; ///< A parameter list. |
---|
| 204 | Statistics::StatsContainer<float> Stats; ///< The statistics for the DataArray. |
---|
| 205 | }; |
---|
[3] | 206 | |
---|
[220] | 207 | |
---|
| 208 | |
---|
[378] | 209 | //========================================================================= |
---|
[220] | 210 | |
---|
[528] | 211 | /// @brief Definition of an data-cube object (3D): |
---|
| 212 | /// a DataArray object limited to dim=3 |
---|
[3] | 213 | |
---|
[378] | 214 | class Cube : public DataArray |
---|
| 215 | { |
---|
| 216 | public: |
---|
| 217 | Cube(); ///< Basic Cube constructor. |
---|
[884] | 218 | Cube(size_t nPix); ///< Alternative Cube constructor. |
---|
| 219 | Cube(size_t *dimensions); ///< Alternative Cube constructor. |
---|
[378] | 220 | virtual ~Cube(); ///< Basic Cube destructor. |
---|
[736] | 221 | Cube(const Cube &c); ///< Copy constructor |
---|
| 222 | Cube& operator=(const Cube &c); ///< Copy operator |
---|
[3] | 223 | |
---|
[877] | 224 | /// @brief Return a Cube holding only a subsection of the original |
---|
[878] | 225 | Cube* slice(Section subsection); |
---|
[877] | 226 | |
---|
| 227 | |
---|
[977] | 228 | short int nondegDim(){return numNondegDim;}; |
---|
[513] | 229 | bool is2D(); |
---|
| 230 | void checkDim(){head.set2D(is2D());}; |
---|
[758] | 231 | void reportMemorySize(std::ostream &theStream, bool allocateArrays); |
---|
[513] | 232 | |
---|
[378] | 233 | // INLINE functions -- definitions included after class declaration. |
---|
[528] | 234 | /// @brief Is the voxel number given by vox a BLANK value? |
---|
[884] | 235 | bool isBlank(size_t vox){ return par.isBlank(array[vox]); }; |
---|
[3] | 236 | |
---|
[528] | 237 | /// @brief Is the voxel at (x,y,z) a BLANK value? |
---|
[884] | 238 | bool isBlank(size_t x, size_t y, size_t z){ |
---|
[378] | 239 | return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]); }; |
---|
[222] | 240 | |
---|
[528] | 241 | /// @brief Return a bool array masking blank pixels: 1=good, 0=blank |
---|
[463] | 242 | bool * makeBlankMask(){return par.makeBlankMask(array, numPixels);}; |
---|
| 243 | |
---|
[528] | 244 | /// @brief Does the Cube::recon array exist? |
---|
[378] | 245 | bool isRecon(){ return reconExists; }; |
---|
[222] | 246 | |
---|
[884] | 247 | float getPixValue(size_t pos){ return array[pos]; }; |
---|
| 248 | float getPixValue(size_t x, size_t y, size_t z){ |
---|
[378] | 249 | return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; }; |
---|
[884] | 250 | short getDetectMapValue(size_t pos){ return detectMap[pos]; }; |
---|
| 251 | short getDetectMapValue(size_t x, size_t y){ return detectMap[y*axisDim[0]+x]; }; |
---|
| 252 | float getReconValue(size_t pos){ return recon[pos]; }; |
---|
| 253 | float getReconValue(size_t x, size_t y, size_t z){ |
---|
[378] | 254 | return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];}; |
---|
[884] | 255 | float getBaselineValue(size_t pos){ return baseline[pos]; }; |
---|
| 256 | float getBaselineValue(size_t x, size_t y, size_t z){ |
---|
[378] | 257 | return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; }; |
---|
[884] | 258 | void setPixValue(size_t pos, float f){array[pos] = f;}; |
---|
| 259 | void setPixValue(size_t x, size_t y, size_t z, float f){ |
---|
[378] | 260 | array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;}; |
---|
[884] | 261 | void setDetectMapValue(size_t pos, short f){ detectMap[pos] = f;}; |
---|
| 262 | void setDetectMapValue(size_t x, size_t y, short f){ detectMap[y*axisDim[0] + x] = f;}; |
---|
| 263 | void incrementDetectMap(size_t x, size_t y){detectMap[y*axisDim[0]+x]++;}; |
---|
| 264 | void incrementDetectMap(size_t pos){detectMap[pos]++;}; |
---|
| 265 | void setReconValue(size_t pos, float f){recon[pos] = f;}; |
---|
| 266 | void setReconValue(size_t x, size_t y, size_t z, float f){ |
---|
[378] | 267 | recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f; }; |
---|
| 268 | void setReconFlag(bool f){reconExists = f;}; |
---|
[222] | 269 | |
---|
[1064] | 270 | Catalogues::CatalogueSpecification getFullCols(){return fullCols;}; |
---|
| 271 | Catalogues::CatalogueSpecification *pFullCols(){return &fullCols;}; |
---|
| 272 | void setFullCols(Catalogues::CatalogueSpecification C){fullCols=C;}; |
---|
[222] | 273 | |
---|
[378] | 274 | // additional functions -- in Cubes/cubes.cc |
---|
[528] | 275 | /// @brief Allocate memory correctly, with WCS defining the correct axes. |
---|
[884] | 276 | OUTCOME initialiseCube(size_t *dimensions, bool allocateArrays=true); |
---|
[679] | 277 | OUTCOME initialiseCube(long *dimensions, bool allocateArrays=true); |
---|
[222] | 278 | |
---|
[528] | 279 | /// @brief Read in a FITS file, with subsection correction. |
---|
[698] | 280 | OUTCOME getCube(); |
---|
[528] | 281 | /// @brief Read in a FITS file, with subsection correction. |
---|
[698] | 282 | OUTCOME getMetadata(); |
---|
[222] | 283 | |
---|
[528] | 284 | /// @brief Read in command-line options. |
---|
[378] | 285 | // int getopts(int argc, char ** argv); |
---|
[474] | 286 | int getopts(int argc, char ** argv, std::string progname="Duchamp"){return par.getopts(argc,argv,progname);}; |
---|
[222] | 287 | |
---|
[528] | 288 | /// @brief Read in reconstructed & smoothed arrays from FITS files on disk. |
---|
[378] | 289 | void readSavedArrays(); |
---|
[222] | 290 | |
---|
[528] | 291 | /// @brief Save an external array to the Cube's pixel array |
---|
[884] | 292 | void saveArray(float *input, size_t size); |
---|
[222] | 293 | |
---|
[528] | 294 | /// @brief Save an external array to the Cube's pixel array |
---|
[491] | 295 | void saveArray(std::vector<float> &input); |
---|
| 296 | |
---|
[528] | 297 | /// @brief Save an external array to the Cube's reconstructed array. |
---|
[884] | 298 | void saveRecon(float *input, size_t size); |
---|
[222] | 299 | |
---|
[528] | 300 | /// @brief Save reconstructed array to an external array. |
---|
[378] | 301 | void getRecon(float *output); |
---|
[1120] | 302 | /// @brief Return the pointer to the reconstructed array. |
---|
[387] | 303 | float * getRecon(){return recon; }; |
---|
[222] | 304 | |
---|
[1120] | 305 | /// @brief Save baseline array to an external array. |
---|
| 306 | void getBaseline(float *output); |
---|
| 307 | /// @brief Return the pointer to the baseline array. |
---|
| 308 | float * getBaseline(){return baseline; }; |
---|
| 309 | |
---|
[378] | 310 | //------------------------ |
---|
| 311 | // Statistics for cube |
---|
| 312 | // |
---|
[222] | 313 | |
---|
[528] | 314 | /// @brief Calculate the statistics for the Cube (older version). |
---|
[378] | 315 | void setCubeStatsOld(); |
---|
[222] | 316 | |
---|
[528] | 317 | /// @brief Calculate the statistics for the Cube. |
---|
[378] | 318 | void setCubeStats(); |
---|
[222] | 319 | |
---|
[528] | 320 | /// @brief Set up thresholds for the False Discovery Rate routine. |
---|
[378] | 321 | void setupFDR(); |
---|
[531] | 322 | /// @brief Set up thresholds for the False Discovery Rate routine using a particular array. |
---|
[378] | 323 | void setupFDR(float *input); |
---|
[222] | 324 | |
---|
[528] | 325 | /// @brief A detection test for a given voxel. |
---|
[884] | 326 | bool isDetection(size_t x, size_t y, size_t z); |
---|
[222] | 327 | |
---|
[378] | 328 | //----------------------------- |
---|
| 329 | // Dealing with the detections |
---|
| 330 | // |
---|
[659] | 331 | |
---|
| 332 | /// @brief Get the set of voxels pertaining to the detected objects. |
---|
| 333 | std::vector< std::vector<PixelInfo::Voxel> > getObjVoxList(); |
---|
[222] | 334 | |
---|
[528] | 335 | /// @brief Calculate the object fluxes |
---|
[420] | 336 | void calcObjectFluxes(); |
---|
| 337 | |
---|
[528] | 338 | /// @brief Calculate the WCS parameters for each Cube Detection. |
---|
[378] | 339 | void calcObjectWCSparams(); |
---|
[528] | 340 | /// @brief Calculate the WCS parameters for each Cube Detection, using flux information in Voxels. |
---|
[418] | 341 | void calcObjectWCSparams(std::vector< std::vector<PixelInfo::Voxel> > bigVoxList); |
---|
[863] | 342 | void calcObjectWCSparams(std::map<PixelInfo::Voxel,float> &voxelMap); |
---|
| 343 | |
---|
[528] | 344 | /// @brief Sort the list of detections. |
---|
[378] | 345 | void sortDetections(); |
---|
[222] | 346 | |
---|
[1051] | 347 | short *getDetectMap(){return detectMap;}; |
---|
| 348 | |
---|
[528] | 349 | /// @brief Update the map of detected pixels. |
---|
[378] | 350 | void updateDetectMap(); |
---|
[222] | 351 | |
---|
[528] | 352 | /// @brief Update the map of detected pixels for a given Detection. |
---|
[378] | 353 | void updateDetectMap(Detection obj); |
---|
[222] | 354 | |
---|
[528] | 355 | /// @brief Clear the map of detected pixels. |
---|
[378] | 356 | void clearDetectMap(){ |
---|
[884] | 357 | for(size_t i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0; |
---|
[378] | 358 | }; |
---|
[290] | 359 | |
---|
[528] | 360 | /// @brief Find the flux enclosed by a Detection. |
---|
[378] | 361 | float enclosedFlux(Detection obj); |
---|
[222] | 362 | |
---|
[531] | 363 | /// @brief Set up the output column definitions for the Cube and its Detection list. |
---|
[378] | 364 | void setupColumns(); |
---|
[222] | 365 | |
---|
[528] | 366 | /// @brief Is the object at the edge of the image? |
---|
[378] | 367 | bool objAtSpatialEdge(Detection obj); |
---|
[222] | 368 | |
---|
[528] | 369 | /// @brief Is the object at an end of the spectrum? |
---|
[378] | 370 | bool objAtSpectralEdge(Detection obj); |
---|
[222] | 371 | |
---|
[1242] | 372 | /// @brief Is the object next to or enclosing flagged channels? |
---|
| 373 | bool objNextToFlaggedChan(Detection &obj); |
---|
| 374 | |
---|
[528] | 375 | /// @brief Set warning flags for the detections. |
---|
[378] | 376 | void setObjectFlags(); |
---|
[222] | 377 | |
---|
[378] | 378 | // ---------------------------- |
---|
| 379 | // Dealing with the WCS |
---|
| 380 | // |
---|
[528] | 381 | /// @brief Return the FitsHeader object. |
---|
[378] | 382 | FitsHeader getHead(){ return head; }; |
---|
[528] | 383 | /// @brief Define the FitsHeader object. |
---|
[378] | 384 | void setHead(FitsHeader F){head = F;}; |
---|
[528] | 385 | /// @brief Provide a reference to the FitsHeader object. |
---|
[378] | 386 | FitsHeader& header(){ FitsHeader &h = head; return h; }; |
---|
[1156] | 387 | /// @brief Provide a pointer to the FitsHeader object |
---|
| 388 | FitsHeader *pHeader(){return &head;}; |
---|
[3] | 389 | |
---|
[378] | 390 | //------------------------------------------- |
---|
| 391 | // FITS-I/O related functions -- not in cubes.cc |
---|
| 392 | // |
---|
[528] | 393 | /// @brief Function to read in FITS file. |
---|
[698] | 394 | OUTCOME getMetadata(std::string fname); // in Cubes/getImage.cc |
---|
| 395 | OUTCOME getCube(std::string fname); // in Cubes/getImage.cc |
---|
[3] | 396 | |
---|
[528] | 397 | /// @brief Convert the flux units to something user-specified. |
---|
[899] | 398 | void convertFluxUnits(std::string oldUnit, std::string newUnit, ARRAYREF whichArray=ARRAY); // in Cubes/getImage.cc |
---|
[434] | 399 | |
---|
[528] | 400 | /// @brief Function to retrieve FITS data array |
---|
[698] | 401 | OUTCOME getFITSdata(std::string fname); // in FitsIO/dataIO.cc |
---|
[971] | 402 | OUTCOME getFITSdata(); // in FitsIO/dataIO.cc |
---|
| 403 | OUTCOME getFITSdata(fitsfile *fptr); // in FitsIO/dataIO.cc |
---|
[222] | 404 | |
---|
[902] | 405 | OUTCOME writeBasicHeader(fitsfile *fptr, int bitpix, bool is2D=false); |
---|
[900] | 406 | |
---|
[1120] | 407 | /// @brief Handle all the writing to FITS files. |
---|
| 408 | void writeToFITS(); |
---|
| 409 | |
---|
[1179] | 410 | /// @brief Save the moment map to a FITS file |
---|
| 411 | OUTCOME saveMomentMapImage(); |
---|
| 412 | |
---|
| 413 | /// @brief Save the moment map mask to a FITS file |
---|
| 414 | OUTCOME saveMomentMask(); |
---|
| 415 | |
---|
| 416 | /// @brief Save a mask array to disk. |
---|
| 417 | OUTCOME saveMaskCube(); |
---|
| 418 | |
---|
| 419 | /// @brief Save Smoothed array to disk. |
---|
| 420 | OUTCOME saveSmoothedCube(); |
---|
| 421 | |
---|
| 422 | /// @brief Save Reconstructed array to disk. |
---|
| 423 | OUTCOME saveReconstructedCube(); |
---|
| 424 | |
---|
| 425 | /// @brief Save baseline array to disk. |
---|
| 426 | OUTCOME saveBaselineCube(); |
---|
| 427 | |
---|
| 428 | //------------------------------------- |
---|
[378] | 429 | // Functions that act on the cube |
---|
| 430 | // |
---|
[3] | 431 | |
---|
[528] | 432 | /// @brief Remove excess BLANK pixels from spatial edge of cube. |
---|
[378] | 433 | void trimCube(); // in Cubes/trimImage.cc |
---|
[222] | 434 | |
---|
[528] | 435 | /// @brief Replace BLANK pixels to spatial edge of cube. |
---|
[378] | 436 | void unTrimCube(); // in Cubes/trimImage.cc |
---|
[222] | 437 | |
---|
[528] | 438 | /// @brief Removes the baselines from the spectra, and stores in Cube::baseline |
---|
[378] | 439 | void removeBaseline(); // in Cubes/baseline.cc |
---|
[222] | 440 | |
---|
[528] | 441 | /// @brief Replace the baselines stored in Cube::baseline |
---|
[378] | 442 | void replaceBaseline(); // in Cubes/baseline.cc |
---|
[222] | 443 | |
---|
[528] | 444 | /// @brief Multiply all pixel values by -1. |
---|
[378] | 445 | void invert(); // in Cubes/invertCube.cc |
---|
[222] | 446 | |
---|
[528] | 447 | /// @brief Undo the inversion, and invert fluxes of all detected objects. |
---|
[378] | 448 | void reInvert(); // in Cubes/invertCube.cc |
---|
[222] | 449 | |
---|
[378] | 450 | //------------------------------------- |
---|
| 451 | // Reconstruction, Searching and Merging functions |
---|
| 452 | // |
---|
[729] | 453 | // in cubes.cc |
---|
| 454 | /// @brief A front-end to all the searching functions |
---|
[834] | 455 | void Search(); |
---|
[729] | 456 | |
---|
[378] | 457 | // in ATrous/ReconSearch.cc |
---|
[528] | 458 | /// @brief Front-end to reconstruction & searching functions. |
---|
[378] | 459 | void ReconSearch(); |
---|
[528] | 460 | /// @brief Switcher to reconstruction functions |
---|
[378] | 461 | void ReconCube(); |
---|
[528] | 462 | /// @brief Performs 1-dimensional a trous reconstruction on the Cube. |
---|
[378] | 463 | void ReconCube1D(); |
---|
[528] | 464 | /// @brief Performs 2-dimensional a trous reconstruction on the Cube. |
---|
[378] | 465 | void ReconCube2D(); |
---|
[528] | 466 | /// @brief Performs 3-dimensional a trous reconstruction on the Cube. |
---|
[378] | 467 | void ReconCube3D(); |
---|
[222] | 468 | |
---|
[378] | 469 | // in Cubes/CubicSearch.cc |
---|
[528] | 470 | /// @brief Front-end to the cubic searching routine. |
---|
[378] | 471 | void CubicSearch(); |
---|
[222] | 472 | |
---|
[378] | 473 | // in Cubes/smoothCube.cc |
---|
[528] | 474 | /// @brief Smooth the cube with the requested method. |
---|
[378] | 475 | void SmoothCube(); |
---|
[528] | 476 | /// @brief Front-end to the smoothing and searching functions. |
---|
[378] | 477 | void SmoothSearch(); |
---|
[528] | 478 | /// @brief A function to spatially smooth the cube and search the result. |
---|
[378] | 479 | void SpatialSmoothNSearch(); |
---|
[528] | 480 | /// @brief A function to Hanning-smooth the cube. |
---|
[378] | 481 | void SpectralSmooth(); |
---|
[528] | 482 | /// @brief A function to spatially-smooth the cube. |
---|
[378] | 483 | void SpatialSmooth(); |
---|
[222] | 484 | |
---|
[378] | 485 | void Simple3DSearch(){ |
---|
[528] | 486 | /// @brief Basic front-end to the simple 3d searching function -- does |
---|
| 487 | /// nothing more. |
---|
| 488 | /// |
---|
| 489 | /// @details This function just runs the search3DArraySimple function, |
---|
| 490 | /// storing the results in the Cube::objectList vector. No stats |
---|
| 491 | /// are calculated beforehand, and no logging or detection map |
---|
| 492 | /// updating is done. |
---|
[686] | 493 | *objectList = search3DArray(axisDim,array,par,Stats); |
---|
[378] | 494 | }; |
---|
[290] | 495 | |
---|
[378] | 496 | void Simple3DSearchRecon(){ |
---|
[528] | 497 | /// @brief Basic front-end to the 3d searching function used in the |
---|
| 498 | /// reconstruction case -- does nothing more. |
---|
| 499 | /// |
---|
| 500 | /// @details This function just runs the searchReconArraySimple |
---|
| 501 | /// function, storing the results in the Cube::objectList |
---|
| 502 | /// vector. No stats are calculated beforehand, and no logging |
---|
| 503 | /// or detection map updating is done. The recon array is |
---|
| 504 | /// assumed to have been defined already. |
---|
| 505 | |
---|
[686] | 506 | *objectList = searchReconArray(axisDim,array,recon,par,Stats); |
---|
[378] | 507 | }; |
---|
[290] | 508 | |
---|
[378] | 509 | void Simple3DSearchSmooth(){ |
---|
[528] | 510 | /// @brief Basic front-end to the simple 3d searching function |
---|
| 511 | /// run on the smoothed array -- does nothing more. |
---|
| 512 | /// |
---|
| 513 | /// @details This function just runs the search3DArraySimple |
---|
| 514 | /// function on the recon array (which contains the smoothed |
---|
| 515 | /// array), storing the results in the Cube::objectList |
---|
| 516 | /// vector. No stats are calculated beforehand, and no logging |
---|
| 517 | /// or detection map updating is done. The recon array is |
---|
| 518 | /// assumed to have been defined already. |
---|
| 519 | |
---|
[686] | 520 | *objectList = search3DArray(axisDim,recon,par,Stats); |
---|
[378] | 521 | }; |
---|
[290] | 522 | |
---|
[378] | 523 | // in Cubes/Merger.cc |
---|
[531] | 524 | /// @brief Merge all objects in the detection list so that only distinct ones are left. |
---|
[378] | 525 | void ObjectMerger(); |
---|
[1056] | 526 | /// @brief Grow the sources out to the secondary threshold |
---|
| 527 | void growSources(std::vector <Detection> ¤tList); |
---|
| 528 | |
---|
[475] | 529 | // in Cubes/existingDetections.cc |
---|
[528] | 530 | /// @brief Read a previously-created log file to get the detections without searching |
---|
[698] | 531 | OUTCOME getExistingDetections(); |
---|
[475] | 532 | |
---|
[378] | 533 | //------------------------------------- |
---|
| 534 | // Text outputting of detected objects. |
---|
| 535 | // in Cubes/detectionIO.cc |
---|
| 536 | // |
---|
[1049] | 537 | |
---|
| 538 | void outputCatalogue(); |
---|
| 539 | |
---|
[528] | 540 | /// @brief Set up the output file with parameters and stats. |
---|
[378] | 541 | void prepareOutputFile(); |
---|
[3] | 542 | |
---|
[528] | 543 | /// @brief Write the statistical information to the output file. |
---|
[378] | 544 | void outputStats(); |
---|
[222] | 545 | |
---|
[528] | 546 | /// @brief Prepare the log file for output. |
---|
[418] | 547 | void prepareLogFile(int argc, char *argv[]); |
---|
| 548 | |
---|
[528] | 549 | /// @brief Output detections to the log file. |
---|
[659] | 550 | void logDetectionList(bool calcFluxes=true); |
---|
[222] | 551 | |
---|
[1049] | 552 | void logSummary(); |
---|
| 553 | |
---|
[1146] | 554 | /// @brief Write set of detections and metadata to a binary catalogue |
---|
| 555 | void writeBinaryCatalogue(); |
---|
| 556 | OUTCOME readBinaryCatalogue(); |
---|
| 557 | |
---|
| 558 | |
---|
[528] | 559 | /// @brief Output detections to a Karma annotation file. |
---|
[1074] | 560 | void outputDetectionsKarma(); |
---|
[222] | 561 | |
---|
[1077] | 562 | /// @brief Output detections to a DS9 annotation file. |
---|
| 563 | void outputDetectionsDS9(); |
---|
| 564 | |
---|
[1126] | 565 | /// @brief Output detections to a CASA region file. |
---|
| 566 | void outputDetectionsCasa(); |
---|
| 567 | |
---|
[1077] | 568 | /// @brief Write annotation files |
---|
| 569 | void outputAnnotations(); |
---|
| 570 | |
---|
[528] | 571 | /// @brief Output detections to a VOTable. |
---|
[1048] | 572 | void outputDetectionsVOTable(); |
---|
[275] | 573 | |
---|
[668] | 574 | |
---|
[378] | 575 | // ---------------------------------- |
---|
[668] | 576 | // Calculation of overall moment maps |
---|
| 577 | |
---|
| 578 | /// @brief Return a moment-0 map plus a map of where the object pixels are |
---|
[946] | 579 | std::vector<bool> getMomentMap(float *momentMap); |
---|
[668] | 580 | /// @brief Return a moment-0 map formatted for logarithmic greyscale plotting, with greyscale limits |
---|
[693] | 581 | void getMomentMapForPlot(float *momentMap, float &z1, float &z2); |
---|
[668] | 582 | |
---|
| 583 | // ---------------------------------- |
---|
[378] | 584 | // Graphical plotting of the cube and the detections. |
---|
| 585 | // |
---|
| 586 | // in Cubes/plotting.cc |
---|
[531] | 587 | /// @brief Plot a spatial map of detections based on number of detected channels. |
---|
[378] | 588 | void plotDetectionMap(std::string pgDestination); |
---|
[3] | 589 | |
---|
[531] | 590 | /// @brief Plot a spatial map of detections based on 0th moment map of each object. |
---|
[378] | 591 | void plotMomentMap(std::string pgDestination); |
---|
[222] | 592 | |
---|
[531] | 593 | /// @brief Plot a spatial map of detections based on 0th moment map of each object to a number of PGPLOT devices. |
---|
[378] | 594 | void plotMomentMap(std::vector<std::string> pgDestination); |
---|
[222] | 595 | |
---|
[528] | 596 | /// @brief Draw WCS axes over a PGPLOT map. |
---|
[581] | 597 | void plotWCSaxes(){duchamp::plotWCSaxes(head.getWCS(),axisDim);}; |
---|
[222] | 598 | |
---|
[378] | 599 | // in Cubes/outputSpectra.cc |
---|
[528] | 600 | /// @brief Print spectra of each detected object. |
---|
[378] | 601 | void outputSpectra(); |
---|
[222] | 602 | |
---|
[528] | 603 | /// @brief Write out text file of all spectra. |
---|
[424] | 604 | void writeSpectralData(); |
---|
| 605 | |
---|
[528] | 606 | /// @brief Print spectrum of a single object |
---|
[424] | 607 | void plotSpectrum(int objNum, Plot::SpectralPlot &plot); |
---|
[528] | 608 | /// @brief Plot the image cutout for a single object |
---|
[378] | 609 | void plotSource(Detection obj, Plot::CutoutPlot &plot); |
---|
[1242] | 610 | /// @brief Mark channels that have been flagged by the user. |
---|
| 611 | void drawFlaggedChannels(Plot::SpectralPlot &plot, double xval, double yval); |
---|
[222] | 612 | |
---|
[1242] | 613 | |
---|
[528] | 614 | /// @brief Get the spectral arrays |
---|
[424] | 615 | void getSpectralArrays(int objNumber, float *specx, float *specy, float *specRecon, float *specBase); |
---|
| 616 | |
---|
[378] | 617 | // in Cubes/drawMomentCutout.cc |
---|
[528] | 618 | /// @brief Draw the 0th moment map for a single object. |
---|
[378] | 619 | void drawMomentCutout(Detection &object); |
---|
[220] | 620 | |
---|
[528] | 621 | /// @brief Draw a scale bar indicating angular size of the cutout. |
---|
[378] | 622 | void drawScale(float xstart,float ystart,float channel); |
---|
[222] | 623 | |
---|
[531] | 624 | /// @brief Draw a yellow line around the edge of the spatial extent of pixels. |
---|
[378] | 625 | void drawFieldEdge(); |
---|
[222] | 626 | |
---|
[378] | 627 | private: |
---|
[977] | 628 | short int numNondegDim; ///< Number of non-degenerate dimensions (ie. with size>1) |
---|
[528] | 629 | float *recon; ///< reconstructed array - used when doing a trous reconstruction. |
---|
| 630 | bool reconExists; ///< flag saying whether there is a reconstruction |
---|
| 631 | short *detectMap; ///< "moment map" - x,y locations of detected pixels |
---|
| 632 | float *baseline; ///< array of spectral baseline values. |
---|
[219] | 633 | |
---|
[528] | 634 | bool reconAllocated; ///< have we allocated memory for the recon array? |
---|
| 635 | bool baselineAllocated;///< have we allocated memory for the baseline array? |
---|
| 636 | FitsHeader head; ///< the WCS and other header information. |
---|
[1064] | 637 | Catalogues::CatalogueSpecification fullCols; ///< the list of all columns as printed in the results file |
---|
[378] | 638 | }; |
---|
[103] | 639 | |
---|
[220] | 640 | |
---|
[378] | 641 | //============================================================================ |
---|
[220] | 642 | |
---|
[528] | 643 | /// @brief A DataArray object limited to two dimensions, and with some additional |
---|
| 644 | /// special functions. |
---|
| 645 | /// |
---|
| 646 | /// @details It is used primarily for searching a 1- or 2-D array with |
---|
| 647 | /// lutz_detect() and spectrumDetect(). |
---|
[219] | 648 | |
---|
[378] | 649 | class Image : public DataArray |
---|
| 650 | { |
---|
| 651 | public: |
---|
[732] | 652 | Image(){numPixels=0; numDim=2; minSize=2;}; |
---|
[884] | 653 | Image(size_t nPix); |
---|
| 654 | Image(size_t *dimensions); |
---|
[378] | 655 | virtual ~Image(){}; |
---|
[736] | 656 | Image(const Image &i); |
---|
| 657 | Image& operator=(const Image &i); |
---|
[219] | 658 | |
---|
[378] | 659 | //-------------------- |
---|
| 660 | // Defining the array |
---|
| 661 | // |
---|
[528] | 662 | /// @brief Save an external array to the Cube's pixel array |
---|
[884] | 663 | void saveArray(float *input, size_t size); |
---|
[222] | 664 | |
---|
[528] | 665 | /// @brief Extract a spectrum from an array and save to the local pixel array. |
---|
[884] | 666 | void extractSpectrum(float *Array, size_t *dim, size_t pixel); |
---|
[222] | 667 | |
---|
[528] | 668 | /// @brief Extract an image from an array and save to the local pixel array. |
---|
[884] | 669 | void extractImage(float *Array, size_t *dim, size_t channel); |
---|
[222] | 670 | |
---|
[528] | 671 | /// @brief Extract a spectrum from a cube and save to the local pixel array. |
---|
[884] | 672 | void extractSpectrum(Cube &cube, size_t pixel); |
---|
[222] | 673 | |
---|
[528] | 674 | /// @brief Extract an image from a cube and save to the local pixel array. |
---|
[884] | 675 | void extractImage(Cube &cube, size_t channel); |
---|
[222] | 676 | |
---|
[378] | 677 | //-------------------- |
---|
| 678 | // Accessing the data. |
---|
| 679 | // |
---|
[884] | 680 | float getPixValue(size_t pos){ return array[pos]; }; |
---|
| 681 | float getPixValue(size_t x, size_t y){return array[y*axisDim[0] + x];}; |
---|
[378] | 682 | // the next few should have checks against array overflow... |
---|
[884] | 683 | void setPixValue(size_t pos, float f){array[pos] = f;}; |
---|
| 684 | void setPixValue(size_t x, size_t y, float f){array[y*axisDim[0] + x] = f;}; |
---|
[378] | 685 | bool isBlank(int vox){return par.isBlank(array[vox]);}; |
---|
[884] | 686 | bool isBlank(size_t x,size_t y){return par.isBlank(array[y*axisDim[0]+x]);}; |
---|
[219] | 687 | |
---|
[378] | 688 | //----------------------- |
---|
| 689 | // Detection-related |
---|
| 690 | // |
---|
[528] | 691 | /// @brief Detect objects in a 2-D image |
---|
[582] | 692 | std::vector<PixelInfo::Object2D> findSources2D(); |
---|
[222] | 693 | |
---|
[528] | 694 | /// @brief Detect objects in a 1-D spectrum |
---|
[582] | 695 | std::vector<PixelInfo::Scan> findSources1D(); |
---|
[222] | 696 | |
---|
[577] | 697 | unsigned int getMinSize(){return minSize;}; |
---|
| 698 | void setMinSize(int i){minSize=i;}; |
---|
[222] | 699 | |
---|
[528] | 700 | /// @brief A detection test for a pixel location. |
---|
[884] | 701 | bool isDetection(size_t x, size_t y){ |
---|
[528] | 702 | /// @details Test whether a pixel (x,y) is a statistically |
---|
| 703 | /// significant detection, according to the set of statistics in |
---|
| 704 | /// the local StatsContainer object. |
---|
| 705 | |
---|
[884] | 706 | size_t voxel = y*axisDim[0] + x; |
---|
[378] | 707 | if(isBlank(x,y)) return false; |
---|
| 708 | else return Stats.isDetection(array[voxel]); |
---|
| 709 | }; |
---|
[219] | 710 | |
---|
[1242] | 711 | /// @brief Blank out a set of channels marked as flagged |
---|
| 712 | void removeFlaggedChannels(); |
---|
[258] | 713 | |
---|
[378] | 714 | private: |
---|
[577] | 715 | unsigned int minSize; ///< the minimum number of pixels for a detection to be accepted. |
---|
[378] | 716 | }; |
---|
[3] | 717 | |
---|
[219] | 718 | |
---|
[378] | 719 | } |
---|
| 720 | |
---|
[3] | 721 | #endif |
---|