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

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

Ticket #195 - moving plotWCSaxes to Utils and renaming wcsAxes. Removing Cubes/plots.{cc,hh}.

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