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

Last change on this file since 863 was 863, checked in by MatthewWhiting, 13 years ago

Adding in versions of the parametrisation functions that take std:maps of Voxels (suggested in #123).

File size: 29.3 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);
[863]323    void        calcObjectWCSparams(std::map<PixelInfo::Voxel,float> &voxelMap);
324 
[528]325    /// @brief Sort the list of detections.
[378]326    void        sortDetections();
[222]327
[528]328    /// @brief Update the map of detected pixels.
[378]329    void        updateDetectMap();
[222]330
[528]331    /// @brief Update the map of detected pixels for a given Detection.
[378]332    void        updateDetectMap(Detection obj);
[222]333
[528]334    /// @brief Clear the map of detected pixels.
[378]335    void        clearDetectMap(){
336      for(int i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0;
337    };
[290]338
[528]339    /// @brief Find the flux enclosed by a Detection.
[378]340    float       enclosedFlux(Detection obj);
[222]341
[531]342    /// @brief Set up the output column definitions for the Cube and its Detection list.
[378]343    void        setupColumns();
[222]344
[528]345    /// @brief Is the object at the edge of the image?
[378]346    bool        objAtSpatialEdge(Detection obj);
[222]347
[528]348    /// @brief Is the object at an end of the spectrum?
[378]349    bool        objAtSpectralEdge(Detection obj);
[222]350
[528]351    /// @brief Set warning flags for the detections.
[378]352    void        setObjectFlags();
[222]353
[378]354    // ----------------------------
355    // Dealing with the WCS
356    //
[528]357    /// @brief Return the FitsHeader object.
[378]358    FitsHeader  getHead(){ return head; };
[528]359    /// @brief Define the FitsHeader object.
[378]360    void        setHead(FitsHeader F){head = F;};
[528]361    /// @brief Provide a reference to the FitsHeader object.
[378]362    FitsHeader& header(){ FitsHeader &h = head; return h; };
[3]363
[528]364    /// @brief Convert a point from WCS to Pixel coords.
[378]365    int         wcsToPix(const double *world, double *pix);
[222]366
[528]367    /// @brief Convert a set of points from WCS to Pixel coords.
[378]368    int         wcsToPix(const double *world, double *pix, const int npts);
[222]369
[528]370    /// @brief Convert a point from Pixel to WCS coords.
[378]371    int         pixToWCS(const double *pix, double *world);
[222]372
[528]373    /// @brief Convert a set of points from Pixel to WCS coords.
[378]374    int         pixToWCS(const double *pix, double *world, const int npts);
[222]375
[378]376    //-------------------------------------------
377    // FITS-I/O related functions -- not in cubes.cc
378    //
[528]379    /// @brief Function to read in FITS file.
[698]380    OUTCOME     getMetadata(std::string fname);  // in Cubes/getImage.cc
381    OUTCOME     getCube(std::string fname);  // in Cubes/getImage.cc
[3]382
[528]383    /// @brief Convert the flux units to something user-specified.
[434]384    void        convertFluxUnits(); // in Cubes/getImage.cc
385
[528]386    /// @brief Function to retrieve FITS data array
[698]387    OUTCOME         getFITSdata(std::string fname);   // in FitsIO/dataIO.cc
[222]388
[670]389    /// @brief Save the moment map to a FITS file
[695]390    OUTCOME        saveMomentMapImage();
[670]391
[528]392    /// @brief Save a mask array to disk.
[695]393    OUTCOME        saveMaskCube();       // in Cubes/saveImage.cc
[379]394
[528]395    /// @brief Save Smoothed array to disk.
[695]396    OUTCOME        saveSmoothedCube();       // in Cubes/saveImage.cc
[258]397
[528]398    /// @brief Save Reconstructed array to disk.
[695]399    OUTCOME        saveReconstructedCube();  // in Cubes/saveImage.cc
[222]400
[528]401    /// @brief Read in reconstructed array from FITS file.
[698]402    OUTCOME        readReconCube();  // in Cubes/readRecon.cc
[222]403 
[528]404    /// @brief Read in Hanning-smoothed array from FITS file.
[698]405    OUTCOME        readSmoothCube();     // in Cubes/readSmooth.cc 
[222]406
[378]407    //-------------------------------------
408    // Functions that act on the cube
409    //
[3]410
[528]411    /// @brief Remove excess BLANK pixels from spatial edge of cube.
[378]412    void        trimCube();         // in Cubes/trimImage.cc
[222]413
[528]414    /// @brief Replace BLANK pixels to spatial edge of cube.
[378]415    void        unTrimCube();       // in Cubes/trimImage.cc
[222]416
[528]417    /// @brief Removes the baselines from the spectra, and stores in Cube::baseline
[378]418    void        removeBaseline();   // in Cubes/baseline.cc
[222]419
[528]420    /// @brief Replace the baselines stored in Cube::baseline
[378]421    void        replaceBaseline();  // in Cubes/baseline.cc
[222]422
[528]423    /// @brief Multiply all pixel values by -1.
[378]424    void        invert();           // in Cubes/invertCube.cc
[222]425
[528]426    /// @brief Undo the inversion, and invert fluxes of all detected objects.
[378]427    void        reInvert();         // in Cubes/invertCube.cc
[222]428
[378]429    //-------------------------------------
430    // Reconstruction, Searching and Merging functions
431    //
[729]432    // in cubes.cc
433    /// @brief A front-end to all the searching functions
[834]434    void        Search();
[729]435
[378]436    // in ATrous/ReconSearch.cc
[528]437    /// @brief Front-end to reconstruction & searching functions.
[378]438    void        ReconSearch();
[528]439    /// @brief Switcher to reconstruction functions
[378]440    void        ReconCube();
[528]441    /// @brief Performs 1-dimensional a trous reconstruction on the Cube.
[378]442    void        ReconCube1D();
[528]443    /// @brief Performs 2-dimensional a trous reconstruction on the Cube.
[378]444    void        ReconCube2D();
[528]445    /// @brief Performs 3-dimensional a trous reconstruction on the Cube.
[378]446    void        ReconCube3D();
[222]447
[378]448    // in Cubes/CubicSearch.cc
[528]449    /// @brief Front-end to the cubic searching routine.
[378]450    void        CubicSearch();
[222]451
[378]452    // in Cubes/smoothCube.cc
[528]453    /// @brief Smooth the cube with the requested method.
[378]454    void        SmoothCube();
[528]455    /// @brief Front-end to the smoothing and searching functions.
[378]456    void        SmoothSearch();
[528]457    /// @brief A function to spatially smooth the cube and search the result.
[378]458    void        SpatialSmoothNSearch();
[528]459    /// @brief A function to Hanning-smooth the cube.
[378]460    void        SpectralSmooth();
[528]461    /// @brief A function to spatially-smooth the cube.
[378]462    void        SpatialSmooth();
[222]463
[378]464    void        Simple3DSearch(){
[528]465      /// @brief Basic front-end to the simple 3d searching function -- does
466      /// nothing more.
467      ///
468      /// @details This function just runs the search3DArraySimple function,
469      /// storing the results in the Cube::objectList vector. No stats
470      /// are calculated beforehand, and no logging or detection map
471      /// updating is done.
[686]472      *objectList = search3DArray(axisDim,array,par,Stats);
[378]473    };
[290]474
[378]475    void        Simple3DSearchRecon(){
[528]476      /// @brief Basic front-end to the 3d searching function used in the
477      /// reconstruction case -- does nothing more.
478      ///
479      /// @details This function just runs the searchReconArraySimple
480      /// function, storing the results in the Cube::objectList
481      /// vector. No stats are calculated beforehand, and no logging
482      /// or detection map updating is done. The recon array is
483      /// assumed to have been defined already.
484
[686]485      *objectList = searchReconArray(axisDim,array,recon,par,Stats);
[378]486    };
[290]487
[378]488    void        Simple3DSearchSmooth(){
[528]489      /// @brief Basic front-end to the simple 3d searching function
490      /// run on the smoothed array -- does nothing more.
491      ///
492      /// @details This function just runs the search3DArraySimple
493      /// function on the recon array (which contains the smoothed
494      /// array), storing the results in the Cube::objectList
495      /// vector. No stats are calculated beforehand, and no logging
496      /// or detection map updating is done. The recon array is
497      /// assumed to have been defined already.
498
[686]499      *objectList = search3DArray(axisDim,recon,par,Stats);
[378]500    };
[290]501
[378]502    // in Cubes/Merger.cc
[531]503    /// @brief Merge all objects in the detection list so that only distinct ones are left.
[378]504    void        ObjectMerger();
[103]505 
[475]506    // in Cubes/existingDetections.cc
[528]507    /// @brief Read a previously-created log file to get the detections without searching
[698]508    OUTCOME     getExistingDetections();
[475]509
[378]510    //-------------------------------------
511    // Text outputting of detected objects.
512    //   in Cubes/detectionIO.cc
513    //
[528]514    /// @brief Set up the output file with parameters and stats.
[378]515    void        prepareOutputFile();
[3]516
[528]517    /// @brief Write the statistical information to the output file.
[378]518    void        outputStats();
[222]519
[528]520    /// @brief Output detections to the output file and standard output.
[378]521    void        outputDetectionList();
[222]522
[528]523    /// @brief Prepare the log file for output.
[418]524    void        prepareLogFile(int argc, char *argv[]);
525
[528]526    /// @brief Output detections to the log file.
[659]527    void        logDetectionList(bool calcFluxes=true);
[222]528
[528]529    /// @brief Output a single detection to the log file.
[378]530    void        logDetection(Detection obj, int counter);
[222]531
[528]532    /// @brief Output detections to a Karma annotation file.
[378]533    void        outputDetectionsKarma(std::ostream &stream);
[222]534
[528]535    /// @brief Output detections to a VOTable.
[378]536    void        outputDetectionsVOTable(std::ostream &stream);
[275]537
[668]538
[378]539    // ----------------------------------
[668]540    // Calculation of overall moment maps
541
542    /// @brief Return a moment-0 map plus a map of where the object pixels are
[693]543    void       getMomentMap(float *momentMap, std::vector<bool> &detectedPixels);
[668]544    /// @brief Return a moment-0 map formatted for logarithmic greyscale plotting, with greyscale limits
[693]545    void       getMomentMapForPlot(float *momentMap, float &z1, float &z2);
[668]546
547    // ----------------------------------
[378]548    // Graphical plotting of the cube and the detections.
549    //
550    //  in Cubes/plotting.cc
[531]551    /// @brief Plot a spatial map of detections based on number of detected channels.
[378]552    void        plotDetectionMap(std::string pgDestination);
[3]553
[531]554    /// @brief Plot a spatial map of detections based on 0th moment map of each object.
[378]555    void        plotMomentMap(std::string pgDestination);
[222]556
[531]557    /// @brief Plot a spatial map of detections based on 0th moment map of each object to a number of PGPLOT devices.
[378]558    void        plotMomentMap(std::vector<std::string> pgDestination);
[222]559
[528]560    /// @brief Draw WCS axes over a PGPLOT map.
[581]561    void        plotWCSaxes(){duchamp::plotWCSaxes(head.getWCS(),axisDim);};
[222]562
[378]563    //  in Cubes/outputSpectra.cc
[528]564    /// @brief Print spectra of each detected object.
[378]565    void        outputSpectra();
[222]566
[528]567    /// @brief Write out text file of all spectra.
[424]568    void        writeSpectralData();
569
[528]570    /// @brief Print spectrum of a single object
[424]571    void        plotSpectrum(int objNum, Plot::SpectralPlot &plot);
[528]572    /// @brief Plot the image cutout for a single object
[378]573    void        plotSource(Detection obj, Plot::CutoutPlot &plot);
[222]574
[528]575    /// @brief Get the spectral arrays
[424]576    void        getSpectralArrays(int objNumber, float *specx, float *specy, float *specRecon, float *specBase);
577
[378]578    //  in Cubes/drawMomentCutout.cc
[528]579    /// @brief Draw the 0th moment map for a single object.
[378]580    void        drawMomentCutout(Detection &object);
[220]581
[528]582    /// @brief Draw a scale bar indicating angular size of the cutout.
[378]583    void        drawScale(float xstart,float ystart,float channel);
[222]584
[531]585    /// @brief Draw a yellow line around the edge of the spatial extent of pixels.
[378]586    void        drawFieldEdge();
[222]587
[378]588  private:
[528]589    float      *recon;            ///< reconstructed array - used when doing a trous reconstruction.
590    bool        reconExists;      ///< flag saying whether there is a reconstruction
591    short      *detectMap;        ///< "moment map" - x,y locations of detected pixels
592    float      *baseline;         ///< array of spectral baseline values.
[219]593                             
[528]594    bool        reconAllocated;   ///< have we allocated memory for the recon array?
595    bool        baselineAllocated;///< have we allocated memory for the baseline array?
596    FitsHeader  head;             ///< the WCS and other header information.
597    std::vector<Column::Col> fullCols;    ///< the list of all columns as printed in the results file
598    std::vector<Column::Col> logCols;     ///< the list of columns as printed in the log file
[205]599
[378]600  };
[103]601
[378]602  ////////////
603  //// Cube inline function definitions
604  ////////////
[220]605
[378]606  inline int Cube::wcsToPix(const double *world, double *pix)
607  {
[528]608    ///  @brief Use the WCS in the FitsHeader to convert from WCS to pixel coords for
609    ///   a single point.
610    ///  \param world The world coordinates.
611    ///  \param pix The returned pixel coordinates.
612    ///
[378]613    return this->head.wcsToPix(world,pix);
614  }
615  inline int Cube::wcsToPix(const double *world, double *pix, const int npts)
616  {
[528]617    ///  @brief Use the WCS in the FitsHeader to convert from WCS to pixel coords for
618    ///   a set of points.
619    ///  \param world The world coordinates.
620    ///  \param pix The returned pixel coordinates.
621    ///  \param npts The number of points being converted.
622
[378]623    return this->head.wcsToPix(world,pix,npts);
624  }
625  inline int Cube::pixToWCS(const double *pix, double *world)
626  {
[528]627    ///  @brief Use the WCS in the FitsHeader to convert from pixel to WCS coords for
628    ///   a single point.
629    ///  \param pix The pixel coordinates.
630    ///  \param world The returned world coordinates.
631
[378]632    return this->head.pixToWCS(pix,world);
633  }
634  inline int Cube::pixToWCS(const double *pix, double *world, const int npts)
635  {
[528]636    ///  @brief Use the WCS in the FitsHeader to convert from pixel to WCS coords for
637    ///   a set of points.
638    ///  \param pix The pixel coordinates.
639    ///  \param world The returned world coordinates.
640    ///  \param npts The number of points being converted.
641
[378]642    return this->head.pixToWCS(pix,world,npts);
643  }
[220]644
645
[378]646  //============================================================================
[220]647
[528]648  ///  @brief A DataArray object limited to two dimensions, and with some additional
649  ///   special functions.
650  ///
651  ///  @details It is used primarily for searching a 1- or 2-D array with
652  ///   lutz_detect() and spectrumDetect().
[219]653
[378]654  class Image : public DataArray
655  {
656  public:
[732]657    Image(){numPixels=0; numDim=2; minSize=2;};
[378]658    Image(long nPix);
659    Image(long *dimensions);
660    virtual ~Image(){};
[736]661    Image(const Image &i);
662    Image& operator=(const Image &i);
[219]663
[378]664    //--------------------
665    // Defining the array
666    //
[528]667    /// @brief Save an external array to the Cube's pixel array
[378]668    void      saveArray(float *input, long size);
[222]669
[528]670    /// @brief Extract a spectrum from an array and save to the local pixel array.
[378]671    void      extractSpectrum(float *Array, long *dim, long pixel);
[222]672
[528]673    /// @brief Extract an image from an array and save to the local pixel array.
[378]674    void      extractImage(float *Array, long *dim, long channel);
[222]675
[528]676    /// @brief Extract a spectrum from a cube and save to the local pixel array.
[378]677    void      extractSpectrum(Cube &cube, long pixel);
[222]678
[528]679    /// @brief Extract an image from a cube and save to the local pixel array.
[378]680    void      extractImage(Cube &cube, long channel);
[222]681
[378]682    //--------------------
683    // Accessing the data.
684    //
685    float     getPixValue(long pos){ return array[pos]; };
686    float     getPixValue(long x, long y){return array[y*axisDim[0] + x];};
687    // the next few should have checks against array overflow...
[419]688    void      setPixValue(long pos, float f){array[pos] = f;};
[378]689    void      setPixValue(long x, long y, float f){array[y*axisDim[0] + x] = f;};
690    bool      isBlank(int vox){return par.isBlank(array[vox]);};
691    bool      isBlank(long x,long y){return par.isBlank(array[y*axisDim[0]+x]);};
[219]692
[378]693    //-----------------------
694    // Detection-related
695    //
[528]696    /// @brief Detect objects in a 2-D image
[582]697    std::vector<PixelInfo::Object2D> findSources2D();
[222]698
[528]699    /// @brief Detect objects in a 1-D spectrum
[582]700    std::vector<PixelInfo::Scan> findSources1D();
[222]701
[577]702    unsigned int getMinSize(){return minSize;};
703    void         setMinSize(int i){minSize=i;};
[222]704
[528]705    /// @brief  A detection test for a pixel location. 
[378]706    bool      isDetection(long x, long y){
[528]707      /// @details Test whether a pixel (x,y) is a statistically
708      /// significant detection, according to the set of statistics in
709      /// the local StatsContainer object.
710
[378]711      long voxel = y*axisDim[0] + x;
712      if(isBlank(x,y)) return false;
713      else return Stats.isDetection(array[voxel]);
714    }; 
[219]715
[528]716    /// @brief Blank out a set of channels marked as being Milky Way channels
[378]717    void      removeMW();
[258]718
[378]719  private:
[577]720    unsigned int minSize;    ///< the minimum number of pixels for a detection to be accepted.
[378]721  };
[3]722
[219]723
[378]724}
725
[3]726#endif
Note: See TracBrowser for help on using the repository browser.