source: tags/release-1.1.7/src/Detection/detection.hh @ 1391

Last change on this file since 1391 was 538, checked in by MatthewWhiting, 15 years ago

Changing all uints in header files to unsigned ints.

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