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

Last change on this file since 1121 was 1120, checked in by MatthewWhiting, 12 years ago

Ticket #170, #105 - The bulk of the work allowing this to happen. Have implemented different classes for each of the output types, including the baselines (which required new parameters etc.) Not yet implemented in mainDuchamp, so needs testing.

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