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

Last change on this file since 758 was 758, checked in by MatthewWhiting, 14 years ago

Improving the way the memory allocation is reported (as described in #90), so that it is done at initialisation of the Cube and reports *all* allocations. Also a minor change in the setCubeStats function that uses the new getMADFM function.

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