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

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

Tidying up - removing declarations of functions that no longer exist and a few fixes to make the build quieter.

File size: 28.6 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    //-------------------------------------
409    // Functions that act on the cube
410    //
411
412    /// @brief Remove excess BLANK pixels from spatial edge of cube.
413    void        trimCube();         // in Cubes/trimImage.cc
414
415    /// @brief Replace BLANK pixels to spatial edge of cube.
416    void        unTrimCube();       // in Cubes/trimImage.cc
417
418    /// @brief Removes the baselines from the spectra, and stores in Cube::baseline
419    void        removeBaseline();   // in Cubes/baseline.cc
420
421    /// @brief Replace the baselines stored in Cube::baseline
422    void        replaceBaseline();  // in Cubes/baseline.cc
423
424    /// @brief Multiply all pixel values by -1.
425    void        invert();           // in Cubes/invertCube.cc
426
427    /// @brief Undo the inversion, and invert fluxes of all detected objects.
428    void        reInvert();         // in Cubes/invertCube.cc
429
430    //-------------------------------------
431    // Reconstruction, Searching and Merging functions
432    //
433    // in cubes.cc
434    /// @brief A front-end to all the searching functions
435    void        Search();
436
437    // in ATrous/ReconSearch.cc
438    /// @brief Front-end to reconstruction & searching functions.
439    void        ReconSearch();
440    /// @brief Switcher to reconstruction functions
441    void        ReconCube();
442    /// @brief Performs 1-dimensional a trous reconstruction on the Cube.
443    void        ReconCube1D();
444    /// @brief Performs 2-dimensional a trous reconstruction on the Cube.
445    void        ReconCube2D();
446    /// @brief Performs 3-dimensional a trous reconstruction on the Cube.
447    void        ReconCube3D();
448
449    // in Cubes/CubicSearch.cc
450    /// @brief Front-end to the cubic searching routine.
451    void        CubicSearch();
452
453    // in Cubes/smoothCube.cc
454    /// @brief Smooth the cube with the requested method.
455    void        SmoothCube();
456    /// @brief Front-end to the smoothing and searching functions.
457    void        SmoothSearch();
458    /// @brief A function to spatially smooth the cube and search the result.
459    void        SpatialSmoothNSearch();
460    /// @brief A function to Hanning-smooth the cube.
461    void        SpectralSmooth();
462    /// @brief A function to spatially-smooth the cube.
463    void        SpatialSmooth();
464
465    void        Simple3DSearch(){
466      /// @brief Basic front-end to the simple 3d searching function -- does
467      /// nothing more.
468      ///
469      /// @details This function just runs the search3DArraySimple function,
470      /// storing the results in the Cube::objectList vector. No stats
471      /// are calculated beforehand, and no logging or detection map
472      /// updating is done.
473      *objectList = search3DArray(axisDim,array,par,Stats);
474    };
475
476    void        Simple3DSearchRecon(){
477      /// @brief Basic front-end to the 3d searching function used in the
478      /// reconstruction case -- does nothing more.
479      ///
480      /// @details This function just runs the searchReconArraySimple
481      /// function, storing the results in the Cube::objectList
482      /// vector. No stats are calculated beforehand, and no logging
483      /// or detection map updating is done. The recon array is
484      /// assumed to have been defined already.
485
486      *objectList = searchReconArray(axisDim,array,recon,par,Stats);
487    };
488
489    void        Simple3DSearchSmooth(){
490      /// @brief Basic front-end to the simple 3d searching function
491      /// run on the smoothed array -- does nothing more.
492      ///
493      /// @details This function just runs the search3DArraySimple
494      /// function on the recon array (which contains the smoothed
495      /// array), storing the results in the Cube::objectList
496      /// vector. No stats are calculated beforehand, and no logging
497      /// or detection map updating is done. The recon array is
498      /// assumed to have been defined already.
499
500      *objectList = search3DArray(axisDim,recon,par,Stats);
501    };
502
503    // in Cubes/Merger.cc
504    /// @brief Merge all objects in the detection list so that only distinct ones are left.
505    void        ObjectMerger();
506    /// @brief Grow the sources out to the secondary threshold
507    void        growSources(std::vector <Detection> &currentList);
508
509    // in Cubes/existingDetections.cc
510    /// @brief Read a previously-created log file to get the detections without searching
511    OUTCOME     getExistingDetections();
512
513    //-------------------------------------
514    // Text outputting of detected objects.
515    //   in Cubes/detectionIO.cc
516    //
517
518    void        outputCatalogue();
519
520    /// @brief Set up the output file with parameters and stats.
521    void        prepareOutputFile();
522
523    /// @brief Write the statistical information to the output file.
524    void        outputStats();
525
526    /// @brief Output detections to the output file and standard output.
527    void        outputDetectionList();
528
529    /// @brief Prepare the log file for output.
530    void        prepareLogFile(int argc, char *argv[]);
531
532    /// @brief Output detections to the log file.
533    void        logDetectionList(bool calcFluxes=true);
534
535    void        logSummary();
536
537    /// @brief Write set of detections and metadata to a binary catalogue
538    void        writeBinaryCatalogue();
539    OUTCOME     readBinaryCatalogue();
540
541
542    /// @brief Output detections to a Karma annotation file.
543    void        outputDetectionsKarma();
544
545    /// @brief Output detections to a DS9 annotation file.
546    void        outputDetectionsDS9();
547
548    /// @brief Output detections to a CASA region file.
549    void        outputDetectionsCasa();
550
551    /// @brief Write annotation files
552    void        outputAnnotations();
553
554    /// @brief Output detections to a VOTable.
555    void        outputDetectionsVOTable();
556
557
558    // ----------------------------------
559    // Calculation of overall moment maps
560
561    /// @brief Return a moment-0 map plus a map of where the object pixels are
562    std::vector<bool> getMomentMap(float *momentMap);
563    /// @brief Return a moment-0 map formatted for logarithmic greyscale plotting, with greyscale limits
564    void       getMomentMapForPlot(float *momentMap, float &z1, float &z2);
565
566    // ----------------------------------
567    // Graphical plotting of the cube and the detections.
568    //
569    //  in Cubes/plotting.cc
570    /// @brief Plot a spatial map of detections based on number of detected channels.
571    void        plotDetectionMap(std::string pgDestination);
572
573    /// @brief Plot a spatial map of detections based on 0th moment map of each object.
574    void        plotMomentMap(std::string pgDestination);
575
576    /// @brief Plot a spatial map of detections based on 0th moment map of each object to a number of PGPLOT devices.
577    void        plotMomentMap(std::vector<std::string> pgDestination);
578
579    /// @brief Draw WCS axes over a PGPLOT map.
580    void        plotWCSaxes(){duchamp::plotWCSaxes(head.getWCS(),axisDim);};
581
582    //  in Cubes/outputSpectra.cc
583    /// @brief Print spectra of each detected object.
584    void        outputSpectra();
585
586    /// @brief Write out text file of all spectra.
587    void        writeSpectralData();
588
589    /// @brief Print spectrum of a single object
590    void        plotSpectrum(int objNum, Plot::SpectralPlot &plot);
591    /// @brief Plot the image cutout for a single object
592    void        plotSource(Detection obj, Plot::CutoutPlot &plot);
593
594    /// @brief Get the spectral arrays
595    void        getSpectralArrays(int objNumber, float *specx, float *specy, float *specRecon, float *specBase);
596
597    //  in Cubes/drawMomentCutout.cc
598    /// @brief Draw the 0th moment map for a single object.
599    void        drawMomentCutout(Detection &object);
600
601    /// @brief Draw a scale bar indicating angular size of the cutout.
602    void        drawScale(float xstart,float ystart,float channel);
603
604    /// @brief Draw a yellow line around the edge of the spatial extent of pixels.
605    void        drawFieldEdge();
606
607  private:
608    short int   numNondegDim;     ///< Number of non-degenerate dimensions (ie. with size>1)
609    float      *recon;            ///< reconstructed array - used when doing a trous reconstruction.
610    bool        reconExists;      ///< flag saying whether there is a reconstruction
611    short      *detectMap;        ///< "moment map" - x,y locations of detected pixels
612    float      *baseline;         ///< array of spectral baseline values.
613                             
614    bool        reconAllocated;   ///< have we allocated memory for the recon array?
615    bool        baselineAllocated;///< have we allocated memory for the baseline array?
616    FitsHeader  head;             ///< the WCS and other header information.
617    Catalogues::CatalogueSpecification fullCols;    ///< the list of all columns as printed in the results file
618  };
619
620
621  //============================================================================
622
623  ///  @brief A DataArray object limited to two dimensions, and with some additional
624  ///   special functions.
625  ///
626  ///  @details It is used primarily for searching a 1- or 2-D array with
627  ///   lutz_detect() and spectrumDetect().
628
629  class Image : public DataArray
630  {
631  public:
632    Image(){numPixels=0; numDim=2; minSize=2;};
633    Image(size_t nPix);
634    Image(size_t *dimensions);
635    virtual ~Image(){};
636    Image(const Image &i);
637    Image& operator=(const Image &i);
638
639    //--------------------
640    // Defining the array
641    //
642    /// @brief Save an external array to the Cube's pixel array
643    void      saveArray(float *input, size_t size);
644
645    /// @brief Extract a spectrum from an array and save to the local pixel array.
646    void      extractSpectrum(float *Array, size_t *dim, size_t pixel);
647
648    /// @brief Extract an image from an array and save to the local pixel array.
649    void      extractImage(float *Array, size_t *dim, size_t channel);
650
651    /// @brief Extract a spectrum from a cube and save to the local pixel array.
652    void      extractSpectrum(Cube &cube, size_t pixel);
653
654    /// @brief Extract an image from a cube and save to the local pixel array.
655    void      extractImage(Cube &cube, size_t channel);
656
657    //--------------------
658    // Accessing the data.
659    //
660    float     getPixValue(size_t pos){ return array[pos]; };
661    float     getPixValue(size_t x, size_t y){return array[y*axisDim[0] + x];};
662    // the next few should have checks against array overflow...
663    void      setPixValue(size_t pos, float f){array[pos] = f;};
664    void      setPixValue(size_t x, size_t y, float f){array[y*axisDim[0] + x] = f;};
665    bool      isBlank(int vox){return par.isBlank(array[vox]);};
666    bool      isBlank(size_t x,size_t y){return par.isBlank(array[y*axisDim[0]+x]);};
667
668    //-----------------------
669    // Detection-related
670    //
671    /// @brief Detect objects in a 2-D image
672    std::vector<PixelInfo::Object2D> findSources2D();
673
674    /// @brief Detect objects in a 1-D spectrum
675    std::vector<PixelInfo::Scan> findSources1D();
676
677    unsigned int getMinSize(){return minSize;};
678    void         setMinSize(int i){minSize=i;};
679
680    /// @brief  A detection test for a pixel location. 
681    bool      isDetection(size_t x, size_t y){
682      /// @details Test whether a pixel (x,y) is a statistically
683      /// significant detection, according to the set of statistics in
684      /// the local StatsContainer object.
685
686      size_t voxel = y*axisDim[0] + x;
687      if(isBlank(x,y)) return false;
688      else return Stats.isDetection(array[voxel]);
689    }; 
690
691    /// @brief Blank out a set of channels marked as being Milky Way channels
692    void      removeMW();
693
694  private:
695    unsigned int minSize;    ///< the minimum number of pixels for a detection to be accepted.
696  };
697
698
699}
700
701#endif
Note: See TracBrowser for help on using the repository browser.