source: trunk/src/Cubes/cubes.hh @ 1455

Last change on this file since 1455 was 1447, checked in by MatthewWhiting, 4 years ago

Changing a couple of cubes functions to use references rather than direct copies.
Also adding a mergeIntoList function to the DataArray? class

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