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

Last change on this file since 1246 was 1246, checked in by MatthewWhiting, 11 years ago

Ticket #193 - Removing all the MW-related code. Most of it was commented out, but Param now no longer has anything referring to MW. The flag array in ObjectGrower? has also changed to FLAG from MW.

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