source: trunk/src/Detection/detection.hh @ 431

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

Changed the way the borders are calculated, and the way the Annotation file is written. Now shows outline of object in same manner as moment map plots.

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    /** Get the location of the spatial borders. */
151    std::vector<int> getVertexSet();
152    //
153    /** Draw spatial borders for a particular Detection. */
154    void   drawBorders(int xoffset, int yoffset);
155    //
156    /** Sort the pixels by central z-value. */
157    void   SortByZ(){pixelArray.order();};
158    //
159    //----------------------------------
160    // Basic functions
161    //
162    /** Delete all pixel information from Detection. Does not clear
163        other parameters. */
164    //  void   clearDetection(){this->pix.clear();};
165
166    /** Add a single voxel to the pixel list.*/
167    void   addPixel(long x, long y, long z){pixelArray.addPixel(x,y,z);};
168    /** Add a single voxel to the pixel list.*/
169    void   addPixel(PixelInfo::Voxel point){
170      /** This one adds the pixel to the pixelArray, and updates the
171          fluxes according to the Voxel's flux information */
172      pixelArray.addPixel(point);
173      totalFlux += point.getF();
174      if(point.getF()>peakFlux){
175        peakFlux = point.getF();
176        xpeak = point.getX(); ypeak = point.getY(); zpeak = point.getZ();
177      }
178    };
179
180    /** Return a single voxel. */
181    PixelInfo::Voxel getPixel(int i){return pixelArray.getPixel(i);};
182
183    /** Return the set of voxels. */
184    std::vector<PixelInfo::Voxel> getPixelSet(){return pixelArray.getPixelSet();};
185
186    /** How many voxels are in the Detection? */
187    int    getSize(){return pixelArray.getSize();};
188
189    /** How many distinct spatial pixels are there? */
190    int    getSpatialSize(){return pixelArray.getSpatialSize();};
191
192    /** How many channels does the Detection have? */
193    long   getNumChannels(){return pixelArray.getNumDistinctZ();};
194
195    /** Is there at least the acceptable minimum number of channels in
196        the Detection?  */
197    bool   hasEnoughChannels(int minNumber);
198 
199    //-----------------------------------
200    // Basic accessor functions for private members follow...
201    //
202    long        getXOffset(){return xSubOffset;};
203    void        setXOffset(long o){xSubOffset = o;};
204    long        getYOffset(){return ySubOffset;};
205    void        setYOffset(long o){ySubOffset = o;};
206    long        getZOffset(){return zSubOffset;};
207    void        setZOffset(long o){zSubOffset = o;};
208    //       
209    float       getXcentre(){
210      if(centreType=="peak") return xpeak;
211      else if(centreType=="average") return pixelArray.getXcentre();
212      else return xCentroid;
213    };
214    float       getYcentre(){
215      if(centreType=="peak") return ypeak;
216      else if(centreType=="average") return pixelArray.getYcentre();
217      else return yCentroid;
218    };
219    float       getZcentre(){
220      if(centreType=="peak") return zpeak;
221      else if(centreType=="average") return pixelArray.getZcentre();
222      else return zCentroid;
223    };
224    float       getXAverage(){return pixelArray.getXcentre();};
225    float       getYAverage(){return pixelArray.getYcentre();};
226    float       getZAverage(){return pixelArray.getZcentre();};
227    float       getTotalFlux(){return totalFlux;};
228    void        setTotalFlux(float f){totalFlux=f;};
229    double      getIntegFlux(){return intFlux;};
230    void        setIntegFlux(double f){intFlux=f;};
231    float       getPeakFlux(){return peakFlux;};
232    void        setPeakFlux(float f){peakFlux=f;};
233    long        getXPeak(){return xpeak;};
234    long        getYPeak(){return ypeak;};
235    long        getZPeak(){return zpeak;};
236    float       getPeakSNR(){return peakSNR;};
237    void        setPeakSNR(float f){peakSNR = f;};
238    float       getXCentroid(){return xCentroid;};
239    float       getYCentroid(){return yCentroid;};
240    float       getZCentroid(){return zCentroid;};
241    std::string getCentreType(){return centreType;};
242    void        setCentreType(std::string s){centreType=s;};
243    bool        isNegative(){return negSource;};
244    void        setNegative(bool f){negSource = f;};
245    std::string getFlagText(){return flagText;};
246    void        setFlagText(std::string s){flagText = s;};
247    void        addToFlagText(std::string s){flagText += s;};
248    //       
249    long        getXmin(){return pixelArray.getXmin();};
250    long        getYmin(){return pixelArray.getYmin();};
251    long        getZmin(){return pixelArray.getZmin();};
252    long        getXmax(){return pixelArray.getXmax();};
253    long        getYmax(){return pixelArray.getYmax();};
254    long        getZmax(){return pixelArray.getZmax();};
255    //
256    /** Is the WCS good enough to be used?
257        \return Detection::flagWCS =  True/False */
258    bool        isWCS(){return flagWCS;};
259    bool        isSpecOK(){return specOK;};
260    void        setSpecOK(bool b){specOK=b;};
261    std::string getName(){return name;};
262    void        setName(std::string s){name=s;};
263    std::string getRAs(){return raS;};
264    std::string getDecs(){return decS;};
265    float       getRA(){return ra;};
266    float       getDec(){return dec;};
267    float       getRAWidth(){return raWidth;};
268    float       getDecWidth(){return decWidth;};
269    float       getVel(){return vel;};
270    float       getVelWidth(){return velWidth;};
271    float       getVelMin(){return velMin;};
272    float       getVelMax(){return velMax;};
273    int         getID(){return id;};
274    void        setID(int i){id = i;};
275    //
276    int         getPosPrec(){return posPrec;};
277    void        setPosPrec(int i){posPrec=i;};
278    int         getXYZPrec(){return xyzPrec;};
279    void        setXYZPrec(int i){xyzPrec=i;};
280    int         getFintPrec(){return fintPrec;};
281    void        setFintPrec(int i){fintPrec=i;};
282    int         getFpeakPrec(){return fpeakPrec;};
283    void        setFpeakPrec(int i){fpeakPrec=i;};
284    int         getVelPrec(){return velPrec;};
285    void        setVelPrec(int i){velPrec=i;};
286    int         getSNRPrec(){return snrPrec;};
287    void        setSNRPrec(int i){snrPrec=i;};
288    //
289  private:
290    PixelInfo::Object3D pixelArray;     ///< The pixel locations
291    // Subsection offsets
292    long           xSubOffset;     ///< The x-offset, from subsectioned cube
293    long           ySubOffset;     ///< The y-offset, from subsectioned cube
294    long           zSubOffset;     ///< The z-offset, from subsectioned cube
295    // Flux related
296    float          totalFlux;      ///< sum of the fluxes of all the pixels
297    double         intFlux;        ///< integrated flux : involves
298    ///    integration over velocity.
299    float          peakFlux;       ///< maximum flux over all the pixels
300    long           xpeak;          ///< x-pixel location of peak flux
301    long           ypeak;          ///< y-pixel location of peak flux
302    long           zpeak;          ///< z-pixel location of peak flux
303    float          peakSNR;        ///< signal-to-noise ratio at peak
304    float          xCentroid;      ///< x-pixel location of centroid
305    float          yCentroid;      ///< y-pixel location of centroid
306    float          zCentroid;      ///< z-pixel location of centroid
307    std::string    centreType;     ///< which type of pixel centre to
308    ///   report: "average", "centroid", or
309    ///   "peak" (flux)
310    bool           negSource;      ///< is the source a negative feature?
311    std::string    flagText;       ///< any warning flags about the
312    ///    quality of the detection.
313    // WCS related
314    int            id;             ///< ID -- generally number in list
315    std::string    name;                 ///< IAU-style name (based on position)
316    bool           flagWCS;        ///< A flag indicating whether the
317    ///    WCS parameters have been set.
318    std::string    raS;          ///< Central Right Ascension (or
319                                 ///    Longitude) in form 12:34:23
320    std::string    decS;                 ///< Central Declination(or
321    ///    Latitude), in form -12:23:34
322    float          ra;           ///< Central Right Ascension in degrees
323    float          dec;          ///< Central Declination in degrees
324    float          raWidth;        ///< Width of detection in RA
325    ///   direction in arcmin
326    float          decWidth;       ///< Width of detection in Dec
327    ///   direction in arcmin
328    bool           specOK;         ///< Is the spectral dimension valid?
329    std::string    specUnits;      ///< Units of the spectral dimension
330    std::string    fluxUnits;      ///< Units of flux
331    std::string    intFluxUnits;   ///< Units of integrated flux
332    std::string    lngtype;        ///< Type of longitude axis (RA/GLON)
333    std::string    lattype;        ///< Type of latitude axis (DEC/GLAT)
334    float          vel;          ///< Central velocity (from zCentre)
335    float          velWidth;       ///< Full velocity width
336    float          velMin;         ///< Minimum velocity
337    float          velMax;         ///< Maximum velocity
338    //  The next six are the precision of values printed in the headers
339    //  of the spectral plots
340    int            posPrec;        ///< Precision of WCS positional values
341    int            xyzPrec;        ///< Precision of pixel positional
342    ///   values
343    int            fintPrec;       ///< Precision of F_int/F_tot values
344    int            fpeakPrec;      ///< Precision of F_peak values
345    int            velPrec;        ///< Precision of velocity values.
346    int            snrPrec;        ///< Precision of S/N_max values.
347
348  };
349
350  //==========================================================================
351
352  //////////////////////////////////////////////////////
353  // Prototypes for functions that use above classes
354  //////////////////////////////////////////////////////
355
356  //----------------
357  // These are in sorting.cc
358  //
359  /** Sort a list of Detections by Z-pixel value. */
360  void SortByZ(std::vector <Detection> &inputList);
361
362  /** Sort a list of Detections by Velocity.*/
363  void SortByVel(std::vector <Detection> &inputList);
364
365  //----------------
366  // This is in areClose.cc
367  //
368  /** Determine whether two objects are close according to set parameters.*/
369  bool areClose(Detection &object1, Detection &object2, Param &par);
370
371  //----------------
372  // This is in mergeIntoList.cc
373  //
374  /** Add an object into a list, combining with adjacent objects if need be. */
375  void mergeIntoList(Detection &object, std::vector <Detection> &objList,
376                     Param &par);
377
378  //----------------
379  // These are in Cubes/Merger.cc
380  //
381  /** Merge a list of Detections so that all adjacent voxels are in the same Detection. */
382  void mergeList(std::vector<Detection> &objList, Param &par);   
383  /** Culls a list of Detections that do not meet minimum requirements. */
384  void finaliseList(std::vector<Detection> &objList, Param &par);
385  /** Manage both the merging and the cleaning up of the list. */
386  void ObjectMerger(std::vector<Detection> &objList, Param &par);
387
388}
389
390#endif
Note: See TracBrowser for help on using the repository browser.