source: tags/release-1.1.12/src/Detection/detection.hh

Last change on this file was 770, checked in by MatthewWhiting, 14 years ago

A large bunch of changes related to #102. The starting point was fixing the way the merging worked, to avoid using erase() and do the addition of sources in-place. This led on to optimising the testing functions that look at whether objects should be merged, and a number of new in-class functions were created to do this more transparently. The file areClose.cc now doesn't contain anything useful, and can be deleted. Code is a lot quicker now :)

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