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

Last change on this file since 1391 was 392, checked in by MatthewWhiting, 17 years ago

Fixed up headers -- should have been done before tagging.

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