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

Last change on this file since 1152 was 1152, checked in by MatthewWhiting, 11 years ago

Ticket #173 - Largely implemented. Added Detection::eIntFlux and associated accessors, together with calculations thereof (from within Cube::calcObjectWCSparams()). Also included in the output (except not for the case of a specified threshold, since we don't calculate the noise then - now also treat S/Nmax in this way too). eIntFlux is not printed to the screen in normal output, but is written to the results file.

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