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

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

Fixing #525, where we need to define xloc & yloc for both strands of
the if clause. This stops us having a WCS error.

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/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 Merge an object into the list
152      void             mergeIntoList(Detection &object);
153
154
155    /// @brief Add pixel offsets to object coordinates.
156    void               addObjectOffsets();
157
158    //-----------------------------------------
159    // Parameter list related.
160    //
161    /// @brief Output the Param set.
162    void               showParam(std::ostream &stream){ stream << par; };
163    /// @brief Return the Param set.
164    Param              getParam(){ return par; };
165    /// @brief Save a Param set to the Cube.
166    void               saveParam(Param &newpar){par = newpar;};
167    /// @brief Provides a reference to the Param set.
168    Param&             pars(){ Param &rpar = par; return rpar; };
169    /// @brief Is the voxel number given by vox a BLANK value?
170    bool               isBlank(int vox){return par.isBlank(array[vox]);};
171
172    // --------------------------------------------
173    // Statistics
174    //
175    /// @brief  Returns the StatsContainer.
176    Statistics::StatsContainer<float> getStats(){ return Stats; };
177
178    /// @brief Provides a reference to the StatsContainer.
179    Statistics::StatsContainer<float>& stats(){
180      Statistics::StatsContainer<float> &rstats = Stats;  return rstats;
181    };
182 
183    /// @brief Save a StatsContainer to the Cube.
184    void saveStats(Statistics::StatsContainer<float> newStats){ Stats = newStats;};
185
186    /// @brief A detection test for value.
187    bool isDetection(float value);
188
189    /// @brief  A detection test for pixel. 
190    bool isDetection(size_t voxel);
191
192
193    /// @brief Output operator for DataArray.
194    friend std::ostream& operator<< (std::ostream& theStream, DataArray &array);
195 
196
197  protected:
198    short int                numDim;     ///< Number of dimensions.
199    size_t                  *axisDim;    ///< Array of axis dimensions of cube
200    bool                     axisDimAllocated; ///< has axisDim been allocated?
201    size_t                   numPixels;  ///< Total number of pixels in cube.
202    float                   *array;      ///< Array of data.
203    bool                     arrayAllocated; ///< has the array been allocated?
204    std::vector <Detection> *objectList; ///< The list of detected objects.
205    Param                    par;        ///< A parameter list.
206    Statistics::StatsContainer<float> Stats; ///< The statistics for the DataArray.
207  };
208
209
210
211  //=========================================================================
212
213  /// @brief Definition of an data-cube object (3D):
214  ///     a DataArray object limited to dim=3
215
216  class Cube : public DataArray
217  {
218  public:
219    Cube();                 ///< Basic Cube constructor.
220    Cube(size_t nPix);        ///< Alternative Cube constructor.
221    Cube(size_t *dimensions); ///< Alternative Cube constructor.
222    virtual ~Cube();        ///< Basic Cube destructor.
223    Cube(const Cube &c);    ///< Copy constructor
224    Cube& operator=(const Cube &c); ///< Copy operator
225
226    /// @brief Return a Cube holding only a subsection of the original
227    Cube* slice(Section subsection);
228   
229
230    short int   nondegDim(){return numNondegDim;};
231    bool        is2D();
232    void        checkDim(){head.set2D(is2D());};
233    void        reportMemorySize(std::ostream &theStream, bool allocateArrays);
234
235    // INLINE functions -- definitions included after class declaration.
236    /// @brief Is the voxel number given by vox a BLANK value?
237    bool        isBlank(size_t vox){ return par.isBlank(array[vox]); };
238
239    /// @brief Is the voxel at (x,y,z) a BLANK value?
240    bool        isBlank(size_t x, size_t y, size_t z){
241      return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]); };
242
243    /// @brief Return a bool array masking blank pixels: 1=good, 0=blank
244    std::vector<bool> makeBlankMask(){return par.makeBlankMask(array, numPixels);};
245
246    /// @brief Does the Cube::recon array exist?
247    bool        isRecon(){ return reconExists; };
248
249    float       getPixValue(size_t pos){ return array[pos]; };
250    float       getPixValue(size_t x, size_t y, size_t z){
251      return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
252    short       getDetectMapValue(size_t pos){ return detectMap[pos]; };
253    short       getDetectMapValue(size_t x, size_t y){ return detectMap[y*axisDim[0]+x]; };
254    float       getReconValue(size_t pos){ return recon[pos]; };
255    float       getReconValue(size_t x, size_t y, size_t z){
256      return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
257    float       getBaselineValue(size_t pos){ return baseline[pos]; };
258    float       getBaselineValue(size_t x, size_t y, size_t z){
259      return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
260    void        setPixValue(size_t pos, float f){array[pos] = f;};
261    void        setPixValue(size_t x, size_t y, size_t z, float f){
262      array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
263    void        setDetectMapValue(size_t pos, short f){ detectMap[pos] = f;};
264    void        setDetectMapValue(size_t x, size_t y, short f){ detectMap[y*axisDim[0] + x] = f;};
265    void        incrementDetectMap(size_t x, size_t y){detectMap[y*axisDim[0]+x]++;};
266    void        incrementDetectMap(size_t pos){detectMap[pos]++;};
267    void        setReconValue(size_t pos, float f){recon[pos] = f;};
268    void        setReconValue(size_t x, size_t y, size_t z, float f){
269      recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f; };
270    void        setReconFlag(bool f){reconExists = f;};
271
272    Catalogues::CatalogueSpecification getFullCols(){return fullCols;};
273    Catalogues::CatalogueSpecification *pFullCols(){return &fullCols;};
274    void setFullCols(Catalogues::CatalogueSpecification C){fullCols=C;};
275
276    // additional functions -- in Cubes/cubes.cc
277    /// @brief Allocate memory correctly, with WCS defining the correct axes.
278    OUTCOME     initialiseCube(size_t *dimensions, bool allocateArrays=true);
279    OUTCOME     initialiseCube(long *dimensions, bool allocateArrays=true);
280
281    /// @brief Read in a FITS file, with subsection correction.
282    OUTCOME     getCube();
283    /// @brief Read in a FITS file, with subsection correction.
284    OUTCOME     getMetadata();
285
286    /// @brief Read in command-line options.
287    //   int         getopts(int argc, char ** argv);
288    int         getopts(int argc, char ** argv, std::string progname="Duchamp"){return par.getopts(argc,argv,progname);};
289
290    /// @brief Read in reconstructed & smoothed arrays from FITS files on disk.
291    void        readSavedArrays();
292
293    /// @brief Save an external array to the Cube's pixel array
294    void        saveArray(float *input, size_t size);
295
296    /// @brief Save an external array to the Cube's pixel array
297    void        saveArray(std::vector<float> &input);
298
299    /// @brief Save an external array to the Cube's reconstructed array.
300    void        saveRecon(float *input, size_t size);
301
302    /// @brief Save reconstructed array to an external array.
303    void        getRecon(float *output);
304    /// @brief Return the pointer to the reconstructed array.
305    float *     getRecon(){return recon; };
306
307    /// @brief Save baseline array to an external array.
308    void        getBaseline(float *output);
309    /// @brief Return the pointer to the baseline array.
310    float *     getBaseline(){return baseline; };
311
312    //------------------------
313    // Statistics for cube
314    //
315
316    /// @brief Calculate the statistics for the Cube (older version).
317    void        setCubeStatsOld();
318
319    /// @brief Calculate the statistics for the Cube.
320    void        setCubeStats();
321
322    /// @brief Set up thresholds for the False Discovery Rate routine.
323    void        setupFDR();
324    /// @brief Set up thresholds for the False Discovery Rate routine using a particular array.
325    void        setupFDR(float *input);
326
327    /// @brief A detection test for a given voxel.
328    bool        isDetection(size_t x, size_t y, size_t z);
329
330    //-----------------------------
331    // Dealing with the detections
332    //
333   
334    /// @brief Get the set of voxels pertaining to the detected objects.
335    std::vector< std::vector<PixelInfo::Voxel> > getObjVoxList();
336
337    /// @brief Calculate the object fluxes
338    void        calcObjectFluxes();
339
340    /// @brief Calculate the WCS parameters for each Cube Detection.
341    void        calcObjectWCSparams();
342    /// @brief Calculate the WCS parameters for each Cube Detection, using flux information in Voxels.
343    void        calcObjectWCSparams(std::vector< std::vector<PixelInfo::Voxel> > bigVoxList);
344    void        calcObjectWCSparams(std::map<PixelInfo::Voxel,float> &voxelMap);
345 
346    /// @brief Sort the list of detections.
347    void        sortDetections();
348
349    short      *getDetectMap(){return detectMap;};
350
351    /// @brief Update the map of detected pixels.
352    void        updateDetectMap();
353
354    /// @brief Update the map of detected pixels for a given Detection.
355    void        updateDetectMap(Detection obj);
356
357    /// @brief Clear the map of detected pixels.
358    void        clearDetectMap(){
359      for(size_t i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0;
360    };
361
362    /// @brief Find the flux enclosed by a Detection.
363    float       enclosedFlux(Detection obj);
364
365    /// @brief Set up the output column definitions for the Cube and its Detection list.
366    void        setupColumns();
367
368    /// @brief Is the object at the edge of the image?
369    bool        objAtSpatialEdge(Detection obj);
370
371    /// @brief Is the object at an end of the spectrum?
372    bool        objAtSpectralEdge(Detection obj);
373
374      /// @brief Is the object next to or enclosing flagged channels?
375      bool      objNextToFlaggedChan(Detection &obj);
376
377    /// @brief Set warning flags for the detections.
378    void        setObjectFlags();
379
380    // ----------------------------
381    // Dealing with the WCS
382    //
383    /// @brief Return the FitsHeader object.
384    FitsHeader  getHead(){ return head; };
385    /// @brief Define the FitsHeader object.
386    void        setHead(FitsHeader F){head = F;};
387    /// @brief Provide a reference to the FitsHeader object.
388    FitsHeader& header(){ FitsHeader &h = head; return h; };
389    /// @brief Provide a pointer to the FitsHeader object
390    FitsHeader *pHeader(){return &head;};
391
392    //-------------------------------------------
393    // FITS-I/O related functions -- not in cubes.cc
394    //
395    /// @brief Function to read in FITS file.
396    OUTCOME     getMetadata(std::string fname);  // in Cubes/getImage.cc
397    OUTCOME     getCube(std::string fname);  // in Cubes/getImage.cc
398
399    /// @brief Convert the flux units to something user-specified.
400    void        convertFluxUnits(std::string oldUnit, std::string newUnit, ARRAYREF whichArray=ARRAY); // in Cubes/getImage.cc
401
402    /// @brief Function to retrieve FITS data array
403    OUTCOME         getFITSdata(std::string fname);   // in FitsIO/dataIO.cc
404    OUTCOME         getFITSdata();   // in FitsIO/dataIO.cc
405    OUTCOME         getFITSdata(fitsfile *fptr);   // in FitsIO/dataIO.cc
406
407    OUTCOME         writeBasicHeader(fitsfile *fptr, int bitpix, bool is2D=false);
408
409    /// @brief Handle all the writing to FITS files.
410    void            writeToFITS();
411
412     /// @brief Save the moment map to a FITS file
413    OUTCOME        saveMomentMapImage();
414
415     /// @brief Save the moment map mask to a FITS file
416    OUTCOME        saveMomentMask();
417
418    /// @brief Save a mask array to disk.
419    OUTCOME        saveMaskCube();
420
421    /// @brief Save Smoothed array to disk.
422    OUTCOME        saveSmoothedCube();
423
424    /// @brief Save Reconstructed array to disk.
425    OUTCOME        saveReconstructedCube();
426
427    /// @brief Save baseline array to disk.
428    OUTCOME        saveBaselineCube();
429
430   //-------------------------------------
431    // Functions that act on the cube
432    //
433
434    /// @brief Remove excess BLANK pixels from spatial edge of cube.
435    void        trimCube();         // in Cubes/trimImage.cc
436
437    /// @brief Replace BLANK pixels to spatial edge of cube.
438    void        unTrimCube();       // in Cubes/trimImage.cc
439
440    /// @brief Removes the baselines from the spectra, and stores in Cube::baseline
441    void        removeBaseline();   // in Cubes/baseline.cc
442
443    /// @brief Replace the baselines stored in Cube::baseline
444    void        replaceBaseline(bool fixObjects=true);  // in Cubes/baseline.cc
445
446    /// @brief Multiply all pixel values by -1.
447    void        invert(bool doArrays=true, bool doObjects=true);           // 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.