source: tags/release-1.1.4/src/Detection/detection.hh @ 1441

Last change on this file since 1441 was 418, checked in by MatthewWhiting, 16 years ago

A range of changes from CONRAD development:

  • Improved output for Object3D & Scan, and ordering for Object3D
  • == and match function for Voxel, implemented in Detection functions
  • Additional WCS & flux calculations for Cube using vectors of Voxels
  • Fixed setupColumns, removing the extra call to calcObjWCSparams.
  • New function prepareLogFile to wrap up the code to start a log file. Implemented in mainDuchamp.
File size: 15.8 KB
Line 
1// -----------------------------------------------------------------------
2// detection.hh: Definition of the Detection class.
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 DETECTION_H
29#define DETECTION_H
30
31#include <iostream>
32#include <string>
33#include <vector>
34#include <duchamp/param.hh>
35#include <duchamp/PixelMap/Voxel.hh>
36#include <duchamp/PixelMap/Object3D.hh>
37#include <duchamp/Detection/columns.hh>
38
39namespace duchamp
40{
41
42
43  /**
44   * Class to represent a contiguous set of detected voxels.
45   *  This is a detected object, which features:
46   *   a vector of voxels, average and centroid positions, total & peak fluxes,
47   *   the possibility of WCS-calculated parameters (RA, Dec, velocity,
48   *     related widths).
49   *  Also many functions with which to manipulate the Detections.
50   */
51
52  class Detection
53  {
54  public:
55    Detection();
56    Detection(const Detection& d);
57    Detection& operator= (const Detection& d);
58    virtual ~Detection(){};
59    //------------------------------
60    // These are functions in detection.cc.
61    //
62    /** Add all voxels of one object to another. */
63    friend Detection operator+ (Detection lhs, Detection rhs);
64    friend Detection operator+= (Detection lhs, Detection rhs){
65      lhs = lhs + rhs;
66      return lhs;
67    }
68
69    /** Provides a reference to the pixel array. */
70    PixelInfo::Object3D& pixels(){
71      PixelInfo::Object3D &rpix = this->pixelArray;
72      return rpix;
73    };
74
75    /** Calculate basic parameters of the Detection. */
76    void   calcParams(){pixelArray.calcParams();};
77
78    /** Test whether voxel lists match */
79    bool voxelListsMatch(std::vector<PixelInfo::Voxel> voxelList);
80
81    /** Calculate flux-related parameters of the Detection. */
82    void   calcFluxes(float *fluxArray, long *dim);
83    /** Calculate flux-related parameters of the Detection. */
84    void   calcFluxes(std::vector<PixelInfo::Voxel> voxelList);
85
86    /** Calculate parameters related to the World Coordinate System. */
87    //    void   calcWCSparams(float *fluxArray, long *dim, FitsHeader &head);
88    void   calcWCSparams(FitsHeader &head);
89
90    /** Calculate the integrated flux over the entire Detection. */
91    void   calcIntegFlux(float *fluxArray, long *dim, FitsHeader &head);
92    /** Calculate the integrated flux over the entire Detection. */
93    void   calcIntegFlux(std::vector<PixelInfo::Voxel> voxelList, FitsHeader &head);
94
95    /** Set the values of the axis offsets from the cube. */
96    void   setOffsets(Param &par);
97
98    /** Add the offset values to the pixel locations */
99    void   addOffsets(){
100      pixelArray.addOffsets(xSubOffset,ySubOffset,zSubOffset);
101    };
102
103    //
104    friend std::ostream& operator<< ( std::ostream& theStream, Detection& obj);
105    //---------------------------------
106    // Text Output -- all in Detection/outputDetection.cc
107    //
108    /** The spectral output label that contains info on the WCS position
109        & velocity.*/
110    std::string outputLabelWCS(); 
111
112    /** The spectral output label that contains info on the pixel
113        location. */
114    std::string outputLabelPix();
115
116    /** The spectral output label that contains info on fluxes of the
117        Detection. */
118    std::string outputLabelFluxes();
119
120    /** The spectral output label that contains info on widths of the
121        Detection. */
122    std::string outputLabelWidths();
123
124    /** Prints the column headers, except for the different pixel centres. */
125    void   outputDetectionTextHeader(std::ostream &stream,
126                                     std::vector<Column::Col> columns);
127
128    /** Prints all the column headers. */
129    void   outputDetectionTextHeaderFull(std::ostream &stream,
130                                         std::vector<Column::Col> columns);
131
132    /** Prints the full set of columns, including the WCS
133        information, but not the different pixel centres. */
134    void   outputDetectionTextWCS(std::ostream &stream,
135                                  std::vector<Column::Col> columns);
136
137    /** Prints the full set of columns, including the WCS
138        information. */
139    void   outputDetectionTextWCSFull(std::ostream &stream,
140                                      std::vector<Column::Col> columns);
141
142    /** Prints a limited set of columns, excluding any WCS
143        information. */
144    void   outputDetectionText(std::ostream &stream,
145                               std::vector<Column::Col> columns,
146                               int idNumber);
147    //----------------------------------
148    // For plotting routines... in Cubes/drawMomentCutout.cc
149    //
150    /** Draw spatial borders for a particular Detection. */
151    void   drawBorders(int xoffset, int yoffset);
152    //
153    /** Sort the pixels by central z-value. */
154    void   SortByZ(){pixelArray.order();};
155    //
156    //----------------------------------
157    // Basic functions
158    //
159    /** Delete all pixel information from Detection. Does not clear
160        other parameters. */
161    //  void   clearDetection(){this->pix.clear();};
162
163    /** Add a single voxel to the pixel list.*/
164    void   addPixel(long x, long y, long z){pixelArray.addPixel(x,y,z);};
165    /** Add a single voxel to the pixel list.*/
166    void   addPixel(PixelInfo::Voxel point){
167      /** This one adds the pixel to the pixelArray, and updates the
168          fluxes according to the Voxel's flux information */
169      pixelArray.addPixel(point);
170      totalFlux += point.getF();
171      if(point.getF()>peakFlux){
172        peakFlux = point.getF();
173        xpeak = point.getX(); ypeak = point.getY(); zpeak = point.getZ();
174      }
175    };
176
177    /** Return a single voxel. */
178    PixelInfo::Voxel getPixel(int i){return pixelArray.getPixel(i);};
179
180    /** Return the set of voxels. */
181    std::vector<PixelInfo::Voxel> getPixelSet(){return pixelArray.getPixelSet();};
182
183    /** How many voxels are in the Detection? */
184    int    getSize(){return pixelArray.getSize();};
185
186    /** How many distinct spatial pixels are there? */
187    int    getSpatialSize(){return pixelArray.getSpatialSize();};
188
189    /** How many channels does the Detection have? */
190    long   getNumChannels(){return pixelArray.getNumDistinctZ();};
191
192    /** Is there at least the acceptable minimum number of channels in
193        the Detection?  */
194    bool   hasEnoughChannels(int minNumber);
195 
196    //-----------------------------------
197    // Basic accessor functions for private members follow...
198    //
199    long        getXOffset(){return xSubOffset;};
200    void        setXOffset(long o){xSubOffset = o;};
201    long        getYOffset(){return ySubOffset;};
202    void        setYOffset(long o){ySubOffset = o;};
203    long        getZOffset(){return zSubOffset;};
204    void        setZOffset(long o){zSubOffset = o;};
205    //       
206    float       getXcentre(){
207      if(centreType=="peak") return xpeak;
208      else if(centreType=="average") return pixelArray.getXcentre();
209      else return xCentroid;
210    };
211    float       getYcentre(){
212      if(centreType=="peak") return ypeak;
213      else if(centreType=="average") return pixelArray.getYcentre();
214      else return yCentroid;
215    };
216    float       getZcentre(){
217      if(centreType=="peak") return zpeak;
218      else if(centreType=="average") return pixelArray.getZcentre();
219      else return zCentroid;
220    };
221    float       getXAverage(){return pixelArray.getXcentre();};
222    float       getYAverage(){return pixelArray.getYcentre();};
223    float       getZAverage(){return pixelArray.getZcentre();};
224    float       getTotalFlux(){return totalFlux;};
225    void        setTotalFlux(float f){totalFlux=f;};
226    double      getIntegFlux(){return intFlux;};
227    void        setIntegFlux(double f){intFlux=f;};
228    float       getPeakFlux(){return peakFlux;};
229    void        setPeakFlux(float f){peakFlux=f;};
230    long        getXPeak(){return xpeak;};
231    long        getYPeak(){return ypeak;};
232    long        getZPeak(){return zpeak;};
233    float       getPeakSNR(){return peakSNR;};
234    void        setPeakSNR(float f){peakSNR = f;};
235    float       getXCentroid(){return xCentroid;};
236    float       getYCentroid(){return yCentroid;};
237    float       getZCentroid(){return zCentroid;};
238    std::string getCentreType(){return centreType;};
239    void        setCentreType(std::string s){centreType=s;};
240    bool        isNegative(){return negSource;};
241    void        setNegative(bool f){negSource = f;};
242    std::string getFlagText(){return flagText;};
243    void        setFlagText(std::string s){flagText = s;};
244    void        addToFlagText(std::string s){flagText += s;};
245    //       
246    long        getXmin(){return pixelArray.getXmin();};
247    long        getYmin(){return pixelArray.getYmin();};
248    long        getZmin(){return pixelArray.getZmin();};
249    long        getXmax(){return pixelArray.getXmax();};
250    long        getYmax(){return pixelArray.getYmax();};
251    long        getZmax(){return pixelArray.getZmax();};
252    //
253    /** Is the WCS good enough to be used?
254        \return Detection::flagWCS =  True/False */
255    bool        isWCS(){return flagWCS;};
256    bool        isSpecOK(){return specOK;};
257    void        setSpecOK(bool b){specOK=b;};
258    std::string getName(){return name;};
259    void        setName(std::string s){name=s;};
260    std::string getRAs(){return raS;};
261    std::string getDecs(){return decS;};
262    float       getRA(){return ra;};
263    float       getDec(){return dec;};
264    float       getRAWidth(){return raWidth;};
265    float       getDecWidth(){return decWidth;};
266    float       getVel(){return vel;};
267    float       getVelWidth(){return velWidth;};
268    float       getVelMin(){return velMin;};
269    float       getVelMax(){return velMax;};
270    int         getID(){return id;};
271    void        setID(int i){id = i;};
272    //
273    int         getPosPrec(){return posPrec;};
274    void        setPosPrec(int i){posPrec=i;};
275    int         getXYZPrec(){return xyzPrec;};
276    void        setXYZPrec(int i){xyzPrec=i;};
277    int         getFintPrec(){return fintPrec;};
278    void        setFintPrec(int i){fintPrec=i;};
279    int         getFpeakPrec(){return fpeakPrec;};
280    void        setFpeakPrec(int i){fpeakPrec=i;};
281    int         getVelPrec(){return velPrec;};
282    void        setVelPrec(int i){velPrec=i;};
283    int         getSNRPrec(){return snrPrec;};
284    void        setSNRPrec(int i){snrPrec=i;};
285    //
286  private:
287    PixelInfo::Object3D pixelArray;     ///< The pixel locations
288    // Subsection offsets
289    long           xSubOffset;     ///< The x-offset, from subsectioned cube
290    long           ySubOffset;     ///< The y-offset, from subsectioned cube
291    long           zSubOffset;     ///< The z-offset, from subsectioned cube
292    // Flux related
293    float          totalFlux;      ///< sum of the fluxes of all the pixels
294    double         intFlux;        ///< integrated flux : involves
295    ///    integration over velocity.
296    float          peakFlux;       ///< maximum flux over all the pixels
297    long           xpeak;          ///< x-pixel location of peak flux
298    long           ypeak;          ///< y-pixel location of peak flux
299    long           zpeak;          ///< z-pixel location of peak flux
300    float          peakSNR;        ///< signal-to-noise ratio at peak
301    float          xCentroid;      ///< x-pixel location of centroid
302    float          yCentroid;      ///< y-pixel location of centroid
303    float          zCentroid;      ///< z-pixel location of centroid
304    std::string    centreType;     ///< which type of pixel centre to
305    ///   report: "average", "centroid", or
306    ///   "peak" (flux)
307    bool           negSource;      ///< is the source a negative feature?
308    std::string    flagText;       ///< any warning flags about the
309    ///    quality of the detection.
310    // WCS related
311    int            id;             ///< ID -- generally number in list
312    std::string    name;                 ///< IAU-style name (based on position)
313    bool           flagWCS;        ///< A flag indicating whether the
314    ///    WCS parameters have been set.
315    std::string    raS;          ///< Central Right Ascension (or
316                                 ///    Longitude) in form 12:34:23
317    std::string    decS;                 ///< Central Declination(or
318    ///    Latitude), in form -12:23:34
319    float          ra;           ///< Central Right Ascension in degrees
320    float          dec;          ///< Central Declination in degrees
321    float          raWidth;        ///< Width of detection in RA
322    ///   direction in arcmin
323    float          decWidth;       ///< Width of detection in Dec
324    ///   direction in arcmin
325    bool           specOK;         ///< Is the spectral dimension valid?
326    std::string    specUnits;      ///< Units of the spectral dimension
327    std::string    fluxUnits;      ///< Units of flux
328    std::string    intFluxUnits;   ///< Units of integrated flux
329    std::string    lngtype;        ///< Type of longitude axis (RA/GLON)
330    std::string    lattype;        ///< Type of latitude axis (DEC/GLAT)
331    float          vel;          ///< Central velocity (from zCentre)
332    float          velWidth;       ///< Full velocity width
333    float          velMin;         ///< Minimum velocity
334    float          velMax;         ///< Maximum velocity
335    //  The next six are the precision of values printed in the headers
336    //  of the spectral plots
337    int            posPrec;        ///< Precision of WCS positional values
338    int            xyzPrec;        ///< Precision of pixel positional
339    ///   values
340    int            fintPrec;       ///< Precision of F_int/F_tot values
341    int            fpeakPrec;      ///< Precision of F_peak values
342    int            velPrec;        ///< Precision of velocity values.
343    int            snrPrec;        ///< Precision of S/N_max values.
344
345  };
346
347  //==========================================================================
348
349  //////////////////////////////////////////////////////
350  // Prototypes for functions that use above classes
351  //////////////////////////////////////////////////////
352
353  //----------------
354  // These are in sorting.cc
355  //
356  /** Sort a list of Detections by Z-pixel value. */
357  void SortByZ(std::vector <Detection> &inputList);
358
359  /** Sort a list of Detections by Velocity.*/
360  void SortByVel(std::vector <Detection> &inputList);
361
362  //----------------
363  // This is in areClose.cc
364  //
365  /** Determine whether two objects are close according to set parameters.*/
366  bool areClose(Detection &object1, Detection &object2, Param &par);
367
368  //----------------
369  // This is in mergeIntoList.cc
370  //
371  /** Add an object into a list, combining with adjacent objects if need be. */
372  void mergeIntoList(Detection &object, std::vector <Detection> &objList,
373                     Param &par);
374
375  //----------------
376  // These are in Cubes/Merger.cc
377  //
378  /** Merge a list of Detections so that all adjacent voxels are in the same Detection. */
379  void mergeList(std::vector<Detection> &objList, Param &par);   
380  /** Culls a list of Detections that do not meet minimum requirements. */
381  void finaliseList(std::vector<Detection> &objList, Param &par);
382  /** Manage both the merging and the cleaning up of the list. */
383  void ObjectMerger(std::vector<Detection> &objList, Param &par);
384
385}
386
387#endif
Note: See TracBrowser for help on using the repository browser.