source: tags/release-1.3/src/Cubes/cubes.hh @ 1391

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

Reinstating the saveMask() etc functions - just breaking out the functionality into individual functions that can be called easily from elsewhere. This keeps the interface from 1.2.2 to minimise disruption.

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    /// @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();  // in Cubes/baseline.cc
441
442    /// @brief Multiply all pixel values by -1.
443    void        invert();           // in Cubes/invertCube.cc
444
445    /// @brief Undo the inversion, and invert fluxes of all detected objects.
446    void        reInvert();         // in Cubes/invertCube.cc
447
448    //-------------------------------------
449    // Reconstruction, Searching and Merging functions
450    //
451    // in cubes.cc
452    /// @brief A front-end to all the searching functions
453    void        Search();
454
455    // in ATrous/ReconSearch.cc
456    /// @brief Front-end to reconstruction & searching functions.
457    void        ReconSearch();
458    /// @brief Switcher to reconstruction functions
459    void        ReconCube();
460    /// @brief Performs 1-dimensional a trous reconstruction on the Cube.
461    void        ReconCube1D();
462    /// @brief Performs 2-dimensional a trous reconstruction on the Cube.
463    void        ReconCube2D();
464    /// @brief Performs 3-dimensional a trous reconstruction on the Cube.
465    void        ReconCube3D();
466
467    // in Cubes/CubicSearch.cc
468    /// @brief Front-end to the cubic searching routine.
469    void        CubicSearch();
470
471    // in Cubes/smoothCube.cc
472    /// @brief Smooth the cube with the requested method.
473    void        SmoothCube();
474    /// @brief Front-end to the smoothing and searching functions.
475    void        SmoothSearch();
476    /// @brief A function to spatially smooth the cube and search the result.
477    void        SpatialSmoothNSearch();
478    /// @brief A function to Hanning-smooth the cube.
479    void        SpectralSmooth();
480    /// @brief A function to spatially-smooth the cube.
481    void        SpatialSmooth();
482
483    void        Simple3DSearch(){
484      /// @brief Basic front-end to the simple 3d searching function -- does
485      /// nothing more.
486      ///
487      /// @details This function just runs the search3DArraySimple function,
488      /// storing the results in the Cube::objectList vector. No stats
489      /// are calculated beforehand, and no logging or detection map
490      /// updating is done.
491      *objectList = search3DArray(axisDim,array,par,Stats);
492    };
493
494    void        Simple3DSearchRecon(){
495      /// @brief Basic front-end to the 3d searching function used in the
496      /// reconstruction case -- does nothing more.
497      ///
498      /// @details This function just runs the searchReconArraySimple
499      /// function, storing the results in the Cube::objectList
500      /// vector. No stats are calculated beforehand, and no logging
501      /// or detection map updating is done. The recon array is
502      /// assumed to have been defined already.
503
504      *objectList = searchReconArray(axisDim,array,recon,par,Stats);
505    };
506
507    void        Simple3DSearchSmooth(){
508      /// @brief Basic front-end to the simple 3d searching function
509      /// run on the smoothed array -- does nothing more.
510      ///
511      /// @details This function just runs the search3DArraySimple
512      /// function on the recon array (which contains the smoothed
513      /// array), storing the results in the Cube::objectList
514      /// vector. No stats are calculated beforehand, and no logging
515      /// or detection map updating is done. The recon array is
516      /// assumed to have been defined already.
517
518      *objectList = search3DArray(axisDim,recon,par,Stats);
519    };
520
521    // in Cubes/Merger.cc
522    /// @brief Merge all objects in the detection list so that only distinct ones are left.
523    void        ObjectMerger();
524    /// @brief Grow the sources out to the secondary threshold
525    void        growSources(std::vector <Detection> &currentList);
526
527    // in Cubes/existingDetections.cc
528    /// @brief Read a previously-created log file to get the detections without searching
529    OUTCOME     getExistingDetections();
530
531    //-------------------------------------
532    // Text outputting of detected objects.
533    //   in Cubes/detectionIO.cc
534    //
535
536    void        outputCatalogue();
537
538    /// @brief Set up the output file with parameters and stats.
539    void        prepareOutputFile();
540
541    /// @brief Write the statistical information to the output file.
542    void        outputStats();
543
544    /// @brief Prepare the log file for output.
545    void        prepareLogFile(int argc, char *argv[]);
546
547    /// @brief Output detections to the log file.
548    void        logDetectionList(bool calcFluxes=true);
549
550    void        logSummary();
551
552    /// @brief Write set of detections and metadata to a binary catalogue
553    void        writeBinaryCatalogue();
554    OUTCOME     readBinaryCatalogue();
555
556
557    /// @brief Output detections to a Karma annotation file.
558    void        outputDetectionsKarma();
559
560    /// @brief Output detections to a DS9 annotation file.
561    void        outputDetectionsDS9();
562
563    /// @brief Output detections to a CASA region file.
564    void        outputDetectionsCasa();
565
566    /// @brief Write annotation files
567    void        outputAnnotations();
568
569    /// @brief Output detections to a VOTable.
570    void        outputDetectionsVOTable();
571
572
573    // ----------------------------------
574    // Calculation of overall moment maps
575
576    /// @brief Return a moment-0 map plus a map of where the object pixels are
577    std::vector<bool> getMomentMap(float *momentMap);
578    /// @brief Return a moment-0 map formatted for logarithmic greyscale plotting, with greyscale limits
579    void       getMomentMapForPlot(float *momentMap, float &z1, float &z2);
580
581    // ----------------------------------
582    // Graphical plotting of the cube and the detections.
583    //
584    //  in Cubes/plotting.cc
585    /// @brief Plot a spatial map of detections based on number of detected channels.
586    void        plotDetectionMap(std::string pgDestination);
587
588    /// @brief Plot a spatial map of detections based on 0th moment map of each object.
589    void        plotMomentMap(std::string pgDestination);
590
591    /// @brief Plot a spatial map of detections based on 0th moment map of each object to a number of PGPLOT devices.
592    void        plotMomentMap(std::vector<std::string> pgDestination);
593
594    /// @brief Draw WCS axes over a PGPLOT map.
595    void        plotWCSaxes(){duchamp::plotWCSaxes(head.getWCS(),axisDim);};
596
597    //  in Cubes/outputSpectra.cc
598    /// @brief Print spectra of each detected object.
599    void        outputSpectra();
600
601    /// @brief Write out text file of all spectra.
602    void        writeSpectralData();
603
604    /// @brief Print spectrum of a single object
605    void        plotSpectrum(int objNum, Plot::SpectralPlot &plot);
606    /// @brief Plot the image cutout for a single object
607    void        plotSource(Detection obj, Plot::CutoutPlot &plot);
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 being Milky Way channels
707    void      removeMW();
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.