source: tags/release-1.2.2/src/Cubes/cubes.hh

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

Enabling the output of DS9 region files in addition to the Karma annotation files. Also adding this to the verification script. Still to do documentation.

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