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

Last change on this file since 1126 was 1126, checked in by MatthewWhiting, 12 years ago

Enabling the output of CASA region files. These include a box (acting as a region), plus annotation lines and text in the same manner as the other annotation files. Annotations are currently not supported by casaviewer (even the new v4.0.0!!!), but the region boxes will get picked up.

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