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

Last change on this file since 1441 was 1430, checked in by MatthewWhiting, 7 years ago

Undoing previous commit, as I didn't mean to commit everything :)

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