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

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

A large set of changes aimed at making the use of indexing variables consistent. We have moved to size_t as much as possible to represent the location in memory. This includes making the dimension array within DataArray? and derived classes an array of size_t variables. Still plenty of compilation warnings (principally comparing signed and unsigned variables) - these will need to be cleaned up.

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