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