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

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

A bunch of changes aimed at improving the use of OUTCOME to report SUCCESS/FAILURE. When such a value is returned by a function, the returned type is duchamp::OUTCOME.

Also improved the error reporting in saveImage

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