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

Last change on this file since 1062 was 1061, checked in by MatthewWhiting, 12 years ago

Ticket #162 - A large refactoring of the Column-related code. Columns have moved to Outputs, and in a new namespace Catalogues. The interface has changed, using strings to record the type rather
than the enum. Also included is a new class CatalogueSpecification?, that is designed to hold a collection of Columns. This is not yet implemented - everything still uses the full & log column
vectors, and the code still passes the verification script.

File size: 28.7 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/Cubes/plots.hh>
41#include <duchamp/Utils/Statistics.hh>
42#include <duchamp/PixelMap/Scan.hh>
43#include <duchamp/PixelMap/Object2D.hh>
44
45
46namespace duchamp
47{
48
49
50  /// @brief Search a reconstructed array for significant detections.
51  std::vector <Detection> searchReconArray(size_t *dim, float *originalArray, float *reconArray,
52                                           Param &par, Statistics::StatsContainer<float> &stats);
53  std::vector <Detection> searchReconArraySpectral(size_t *dim, float *originalArray, float *reconArray,
54                                                   Param &par, Statistics::StatsContainer<float> &stats);
55  std::vector <Detection> searchReconArraySpatial(size_t *dim, float *originalArray, float *reconArray,
56                                                  Param &par, Statistics::StatsContainer<float> &stats);
57
58  /// @brief Search a 3-dimensional array for significant detections.
59  std::vector <Detection> search3DArray(size_t *dim, float *Array, Param &par,
60                                        Statistics::StatsContainer<float> &stats);
61  std::vector <Detection> search3DArraySpectral(size_t *dim, float *Array, Param &par,
62                                                Statistics::StatsContainer<float> &stats);
63  std::vector <Detection> search3DArraySpatial(size_t *dim, float *Array, Param &par,
64                                               Statistics::StatsContainer<float> &stats);
65
66  //=========================================================================
67
68  /// An enumeration allowing us to refer to a particular array within functions
69  enum ARRAYREF {ARRAY=0, RECON, BASELINE};
70
71
72  /// @brief Base class for the image container.
73  ///
74  /// @details Definition of an n-dimensional data array: array of
75  ///     pixel values, size & dimensions array of Detection objects
76
77  class DataArray
78  {
79  public:
80    DataArray();  ///< Basic DataArray constructor
81    DataArray(short int nDim); ///< Basic nDim-dimensional DataArray constructor
82    DataArray(short int nDim, size_t size);///< Basic nDim-dimensional DataArray constructor, specifying size.
83    DataArray(short int nDim, size_t *dimensions); ///< Basic nDim-dimensional DataArray constructor, specifying size of dimensions.
84    virtual ~DataArray(); ///< Basic DataArray constructor
85    DataArray(const DataArray &d);
86    DataArray& operator=(const DataArray &d);
87
88    //-----------------------------------------
89    // Obvious inline accessor functions.
90    //
91    size_t             getDimX(){if(numDim>0) return axisDim[0];else return 0;};
92    size_t             getDimY(){if(numDim>1) return axisDim[1];else return 1;};
93    size_t             getDimZ(){if(numDim>2) return axisDim[2];else return 1;};
94    size_t             getSize(){ return numPixels; };
95    short int          getNumDim(){ return numDim; };
96    virtual float      getPixValue(size_t pos){ return array[pos]; };
97    virtual void       setPixValue(size_t pos, float f){array[pos] = f;};
98    Detection          getObject(size_t number){ return objectList->at(number); };
99    Detection *        pObject(size_t number){ return &(objectList->at(number));};
100    std::vector <Detection> getObjectList(){ return *objectList; };
101    std::vector <Detection> *pObjectList(){ return objectList; };
102    std::vector <Detection> &ObjectList(){ std::vector<Detection> &rlist = *objectList; return rlist; };
103    size_t              getNumObj(){ return objectList->size(); };
104
105    /// @brief Delete all objects from the list of detections.
106    void               clearDetectionList(){
107      //objectList->clear();
108      delete objectList;
109      objectList = new std::vector<Detection>;
110    };
111
112    /// @brief Read a parameter set from file.
113    OUTCOME readParam(std::string paramfile){
114      /// @brief
115      ///  Uses Param::readParams() to read parameters from a file.
116      ///  \param paramfile The file to be read.
117       
118      return par.readParams(paramfile);
119    };
120
121    //-----------------------------------------
122    // Related to the various arrays
123    //
124    /// @brief  Return first three dimensional axes.
125    void               getDim(size_t &x, size_t &y, size_t &z);
126    /// @brief Return array of dimensional sizes.
127    void               getDimArray(size_t *output);
128    size_t *           getDimArray(){return axisDim;};
129
130    /// @brief Return pixel value array.
131    void               getArray(float *output);
132    float *            getArray(){return array;};
133
134    /// @brief Save pixel value array.
135    virtual void       saveArray(float *input, size_t size);
136
137    //-----------------------------------------
138    // Related to the object lists
139    //
140    /// @brief Adds a single detection to the object list.
141    void               addObject(Detection object);
142
143    /// @brief Adds all objects in a detection list to the object list.
144    void               addObjectList(std::vector <Detection> newlist);   
145
146    /// @brief Add pixel offsets to object coordinates.
147    void               addObjectOffsets();
148
149    //-----------------------------------------
150    // Parameter list related.
151    //
152    /// @brief Output the Param set.
153    void               showParam(std::ostream &stream){ stream << par; };
154    /// @brief Return the Param set.
155    Param              getParam(){ return par; };
156    /// @brief Save a Param set to the Cube.
157    void               saveParam(Param &newpar){par = newpar;};
158    /// @brief Provides a reference to the Param set.
159    Param&             pars(){ Param &rpar = par; return rpar; };
160    /// @brief Is the voxel number given by vox a BLANK value?
161    bool               isBlank(int vox){return par.isBlank(array[vox]);};
162
163    // --------------------------------------------
164    // Statistics
165    //
166    /// @brief  Returns the StatsContainer.
167    Statistics::StatsContainer<float> getStats(){ return Stats; };
168
169    /// @brief Provides a reference to the StatsContainer.
170    Statistics::StatsContainer<float>& stats(){
171      Statistics::StatsContainer<float> &rstats = Stats;  return rstats;
172    };
173 
174    /// @brief Save a StatsContainer to the Cube.
175    void saveStats(Statistics::StatsContainer<float> newStats){ Stats = newStats;};
176
177    /// @brief A detection test for value.
178    bool isDetection(float value);
179
180    /// @brief  A detection test for pixel. 
181    bool isDetection(size_t voxel);
182
183
184    /// @brief Output operator for DataArray.
185    friend std::ostream& operator<< (std::ostream& theStream, DataArray &array);
186 
187
188  protected:
189    short int                numDim;     ///< Number of dimensions.
190    size_t                  *axisDim;    ///< Array of axis dimensions of cube
191    bool                     axisDimAllocated; ///< has axisDim been allocated?
192    size_t                   numPixels;  ///< Total number of pixels in cube.
193    float                   *array;      ///< Array of data.
194    bool                     arrayAllocated; ///< has the array been allocated?
195    std::vector <Detection> *objectList; ///< The list of detected objects.
196    Param                    par;        ///< A parameter list.
197    Statistics::StatsContainer<float> Stats; ///< The statistics for the DataArray.
198  };
199
200
201
202  //=========================================================================
203
204  /// @brief Definition of an data-cube object (3D):
205  ///     a DataArray object limited to dim=3
206
207  class Cube : public DataArray
208  {
209  public:
210    Cube();                 ///< Basic Cube constructor.
211    Cube(size_t nPix);        ///< Alternative Cube constructor.
212    Cube(size_t *dimensions); ///< Alternative Cube constructor.
213    virtual ~Cube();        ///< Basic Cube destructor.
214    Cube(const Cube &c);    ///< Copy constructor
215    Cube& operator=(const Cube &c); ///< Copy operator
216
217    /// @brief Return a Cube holding only a subsection of the original
218    Cube* slice(Section subsection);
219   
220
221    short int   nondegDim(){return numNondegDim;};
222    bool        is2D();
223    void        checkDim(){head.set2D(is2D());};
224    void        reportMemorySize(std::ostream &theStream, bool allocateArrays);
225
226    // INLINE functions -- definitions included after class declaration.
227    /// @brief Is the voxel number given by vox a BLANK value?
228    bool        isBlank(size_t vox){ return par.isBlank(array[vox]); };
229
230    /// @brief Is the voxel at (x,y,z) a BLANK value?
231    bool        isBlank(size_t x, size_t y, size_t z){
232      return par.isBlank(array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]); };
233
234    /// @brief Return a bool array masking blank pixels: 1=good, 0=blank
235    bool *      makeBlankMask(){return par.makeBlankMask(array, numPixels);};
236
237    /// @brief Does the Cube::recon array exist?
238    bool        isRecon(){ return reconExists; };
239
240    float       getPixValue(size_t pos){ return array[pos]; };
241    float       getPixValue(size_t x, size_t y, size_t z){
242      return array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
243    short       getDetectMapValue(size_t pos){ return detectMap[pos]; };
244    short       getDetectMapValue(size_t x, size_t y){ return detectMap[y*axisDim[0]+x]; };
245    float       getReconValue(size_t pos){ return recon[pos]; };
246    float       getReconValue(size_t x, size_t y, size_t z){
247      return recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x];};
248    float       getBaselineValue(size_t pos){ return baseline[pos]; };
249    float       getBaselineValue(size_t x, size_t y, size_t z){
250      return baseline[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x]; };
251    void        setPixValue(size_t pos, float f){array[pos] = f;};
252    void        setPixValue(size_t x, size_t y, size_t z, float f){
253      array[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f;};
254    void        setDetectMapValue(size_t pos, short f){ detectMap[pos] = f;};
255    void        setDetectMapValue(size_t x, size_t y, short f){ detectMap[y*axisDim[0] + x] = f;};
256    void        incrementDetectMap(size_t x, size_t y){detectMap[y*axisDim[0]+x]++;};
257    void        incrementDetectMap(size_t pos){detectMap[pos]++;};
258    void        setReconValue(size_t pos, float f){recon[pos] = f;};
259    void        setReconValue(size_t x, size_t y, size_t z, float f){
260      recon[z*axisDim[0]*axisDim[1] + y*axisDim[0] + x] = f; };
261    void        setReconFlag(bool f){reconExists = f;};
262
263    std::vector<Catalogues::Column> getLogCols(){return logCols;};
264    std::vector<Catalogues::Column> *pLogCols(){return &logCols;};
265    void        setLogCols(std::vector<Catalogues::Column> C){logCols=C;};
266    std::vector<Catalogues::Column> getFullCols(){return fullCols;};
267    std::vector<Catalogues::Column> *pFullCols(){return &fullCols;};
268    void        setFullCols(std::vector<Catalogues::Column> C){fullCols=C;};
269
270    // additional functions -- in Cubes/cubes.cc
271    /// @brief Allocate memory correctly, with WCS defining the correct axes.
272    OUTCOME     initialiseCube(size_t *dimensions, bool allocateArrays=true);
273    OUTCOME     initialiseCube(long *dimensions, bool allocateArrays=true);
274
275    /// @brief Read in a FITS file, with subsection correction.
276    OUTCOME     getCube();
277    /// @brief Read in a FITS file, with subsection correction.
278    OUTCOME     getMetadata();
279
280    /// @brief Read in command-line options.
281    //   int         getopts(int argc, char ** argv);
282    int         getopts(int argc, char ** argv, std::string progname="Duchamp"){return par.getopts(argc,argv,progname);};
283
284    /// @brief Read in reconstructed & smoothed arrays from FITS files on disk.
285    void        readSavedArrays();
286
287    /// @brief Save an external array to the Cube's pixel array
288    void        saveArray(float *input, size_t size);
289
290    /// @brief Save an external array to the Cube's pixel array
291    void        saveArray(std::vector<float> &input);
292
293    /// @brief Save an external array to the Cube's reconstructed array.
294    void        saveRecon(float *input, size_t size);
295
296    /// @brief Save reconstructed array to an external array.
297    void        getRecon(float *output);
298    float *     getRecon(){return recon; };
299
300    /// @brief Set Milky Way channels to zero.
301    void        removeMW();
302
303    //------------------------
304    // Statistics for cube
305    //
306
307    /// @brief Calculate the statistics for the Cube (older version).
308    void        setCubeStatsOld();
309
310    /// @brief Calculate the statistics for the Cube.
311    void        setCubeStats();
312
313    /// @brief Set up thresholds for the False Discovery Rate routine.
314    void        setupFDR();
315    /// @brief Set up thresholds for the False Discovery Rate routine using a particular array.
316    void        setupFDR(float *input);
317
318    /// @brief A detection test for a given voxel.
319    bool        isDetection(size_t x, size_t y, size_t z);
320
321    //-----------------------------
322    // Dealing with the detections
323    //
324   
325    /// @brief Get the set of voxels pertaining to the detected objects.
326    std::vector< std::vector<PixelInfo::Voxel> > getObjVoxList();
327
328    /// @brief Calculate the object fluxes
329    void        calcObjectFluxes();
330
331    /// @brief Calculate the WCS parameters for each Cube Detection.
332    void        calcObjectWCSparams();
333    /// @brief Calculate the WCS parameters for each Cube Detection, using flux information in Voxels.
334    void        calcObjectWCSparams(std::vector< std::vector<PixelInfo::Voxel> > bigVoxList);
335    void        calcObjectWCSparams(std::map<PixelInfo::Voxel,float> &voxelMap);
336 
337    /// @brief Sort the list of detections.
338    void        sortDetections();
339
340    short      *getDetectMap(){return detectMap;};
341
342    /// @brief Update the map of detected pixels.
343    void        updateDetectMap();
344
345    /// @brief Update the map of detected pixels for a given Detection.
346    void        updateDetectMap(Detection obj);
347
348    /// @brief Clear the map of detected pixels.
349    void        clearDetectMap(){
350      for(size_t i=0;i<axisDim[0]*axisDim[1];i++) detectMap[i]=0;
351    };
352
353    /// @brief Find the flux enclosed by a Detection.
354    float       enclosedFlux(Detection obj);
355
356    /// @brief Set up the output column definitions for the Cube and its Detection list.
357    void        setupColumns();
358
359    /// @brief Is the object at the edge of the image?
360    bool        objAtSpatialEdge(Detection obj);
361
362    /// @brief Is the object at an end of the spectrum?
363    bool        objAtSpectralEdge(Detection obj);
364
365    /// @brief Is the object next to the MW range?
366    bool        objNextToMW(Detection obj);
367
368    /// @brief Set warning flags for the detections.
369    void        setObjectFlags();
370
371    // ----------------------------
372    // Dealing with the WCS
373    //
374    /// @brief Return the FitsHeader object.
375    FitsHeader  getHead(){ return head; };
376    /// @brief Define the FitsHeader object.
377    void        setHead(FitsHeader F){head = F;};
378    /// @brief Provide a reference to the FitsHeader object.
379    FitsHeader& header(){ FitsHeader &h = head; return h; };
380
381    //-------------------------------------------
382    // FITS-I/O related functions -- not in cubes.cc
383    //
384    /// @brief Function to read in FITS file.
385    OUTCOME     getMetadata(std::string fname);  // in Cubes/getImage.cc
386    OUTCOME     getCube(std::string fname);  // in Cubes/getImage.cc
387
388    /// @brief Convert the flux units to something user-specified.
389    void        convertFluxUnits(std::string oldUnit, std::string newUnit, ARRAYREF whichArray=ARRAY); // in Cubes/getImage.cc
390
391    /// @brief Function to retrieve FITS data array
392    OUTCOME         getFITSdata(std::string fname);   // in FitsIO/dataIO.cc
393    OUTCOME         getFITSdata();   // in FitsIO/dataIO.cc
394    OUTCOME         getFITSdata(fitsfile *fptr);   // in FitsIO/dataIO.cc
395
396    OUTCOME         writeBasicHeader(fitsfile *fptr, int bitpix, bool is2D=false);
397
398    /// @brief Save the moment map to a FITS file
399    OUTCOME        saveMomentMapImage();
400
401    /// @brief Save a mask array to disk.
402    OUTCOME        saveMaskCube();       // in Cubes/saveImage.cc
403
404    /// @brief Save Smoothed array to disk.
405    OUTCOME        saveSmoothedCube();       // in Cubes/saveImage.cc
406
407    /// @brief Save Reconstructed array to disk.
408    OUTCOME        saveReconstructedCube();  // in Cubes/saveImage.cc
409
410    /// @brief Read in reconstructed array from FITS file.
411    OUTCOME        readReconCube();  // in Cubes/readRecon.cc
412 
413    /// @brief Read in Hanning-smoothed array from FITS file.
414    OUTCOME        readSmoothCube();     // in Cubes/readSmooth.cc 
415
416    //-------------------------------------
417    // Functions that act on the cube
418    //
419
420    /// @brief Remove excess BLANK pixels from spatial edge of cube.
421    void        trimCube();         // in Cubes/trimImage.cc
422
423    /// @brief Replace BLANK pixels to spatial edge of cube.
424    void        unTrimCube();       // in Cubes/trimImage.cc
425
426    /// @brief Removes the baselines from the spectra, and stores in Cube::baseline
427    void        removeBaseline();   // in Cubes/baseline.cc
428
429    /// @brief Replace the baselines stored in Cube::baseline
430    void        replaceBaseline();  // in Cubes/baseline.cc
431
432    /// @brief Multiply all pixel values by -1.
433    void        invert();           // in Cubes/invertCube.cc
434
435    /// @brief Undo the inversion, and invert fluxes of all detected objects.
436    void        reInvert();         // in Cubes/invertCube.cc
437
438    //-------------------------------------
439    // Reconstruction, Searching and Merging functions
440    //
441    // in cubes.cc
442    /// @brief A front-end to all the searching functions
443    void        Search();
444
445    // in ATrous/ReconSearch.cc
446    /// @brief Front-end to reconstruction & searching functions.
447    void        ReconSearch();
448    /// @brief Switcher to reconstruction functions
449    void        ReconCube();
450    /// @brief Performs 1-dimensional a trous reconstruction on the Cube.
451    void        ReconCube1D();
452    /// @brief Performs 2-dimensional a trous reconstruction on the Cube.
453    void        ReconCube2D();
454    /// @brief Performs 3-dimensional a trous reconstruction on the Cube.
455    void        ReconCube3D();
456
457    // in Cubes/CubicSearch.cc
458    /// @brief Front-end to the cubic searching routine.
459    void        CubicSearch();
460
461    // in Cubes/smoothCube.cc
462    /// @brief Smooth the cube with the requested method.
463    void        SmoothCube();
464    /// @brief Front-end to the smoothing and searching functions.
465    void        SmoothSearch();
466    /// @brief A function to spatially smooth the cube and search the result.
467    void        SpatialSmoothNSearch();
468    /// @brief A function to Hanning-smooth the cube.
469    void        SpectralSmooth();
470    /// @brief A function to spatially-smooth the cube.
471    void        SpatialSmooth();
472
473    void        Simple3DSearch(){
474      /// @brief Basic front-end to the simple 3d searching function -- does
475      /// nothing more.
476      ///
477      /// @details This function just runs the search3DArraySimple function,
478      /// storing the results in the Cube::objectList vector. No stats
479      /// are calculated beforehand, and no logging or detection map
480      /// updating is done.
481      *objectList = search3DArray(axisDim,array,par,Stats);
482    };
483
484    void        Simple3DSearchRecon(){
485      /// @brief Basic front-end to the 3d searching function used in the
486      /// reconstruction case -- does nothing more.
487      ///
488      /// @details This function just runs the searchReconArraySimple
489      /// function, storing the results in the Cube::objectList
490      /// vector. No stats are calculated beforehand, and no logging
491      /// or detection map updating is done. The recon array is
492      /// assumed to have been defined already.
493
494      *objectList = searchReconArray(axisDim,array,recon,par,Stats);
495    };
496
497    void        Simple3DSearchSmooth(){
498      /// @brief Basic front-end to the simple 3d searching function
499      /// run on the smoothed array -- does nothing more.
500      ///
501      /// @details This function just runs the search3DArraySimple
502      /// function on the recon array (which contains the smoothed
503      /// array), storing the results in the Cube::objectList
504      /// vector. No stats are calculated beforehand, and no logging
505      /// or detection map updating is done. The recon array is
506      /// assumed to have been defined already.
507
508      *objectList = search3DArray(axisDim,recon,par,Stats);
509    };
510
511    // in Cubes/Merger.cc
512    /// @brief Merge all objects in the detection list so that only distinct ones are left.
513    void        ObjectMerger();
514    /// @brief Grow the sources out to the secondary threshold
515    void        growSources(std::vector <Detection> &currentList);
516
517    // in Cubes/existingDetections.cc
518    /// @brief Read a previously-created log file to get the detections without searching
519    OUTCOME     getExistingDetections();
520
521    //-------------------------------------
522    // Text outputting of detected objects.
523    //   in Cubes/detectionIO.cc
524    //
525
526    void        outputCatalogue();
527
528    /// @brief Set up the output file with parameters and stats.
529    void        prepareOutputFile();
530
531    /// @brief Write the statistical information to the output file.
532    void        outputStats();
533
534    /// @brief Output detections to the output file and standard output.
535    void        outputDetectionList();
536
537    /// @brief Prepare the log file for output.
538    void        prepareLogFile(int argc, char *argv[]);
539
540    /// @brief Output detections to the log file.
541    void        logDetectionList(bool calcFluxes=true);
542
543    void        logSummary();
544
545    /// @brief Output a single detection to the log file.
546    void        logDetection(Detection obj, int counter);
547
548    /// @brief Output detections to a Karma annotation file.
549    void        outputDetectionsKarma(std::ostream &stream);
550
551    /// @brief Output detections to a VOTable.
552    void        outputDetectionsVOTable(std::ostream &stream);
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    std::vector<Catalogues::Column> fullCols;    ///< the list of all columns as printed in the results file
616    std::vector<Catalogues::Column> logCols;     ///< the list of columns as printed in the log file
617
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.