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

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