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

Last change on this file since 1441 was 1430, checked in by MatthewWhiting, 7 years ago

Undoing previous commit, as I didn't mean to commit everything :)

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