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

Last change on this file since 872 was 863, checked in by MatthewWhiting, 13 years ago

Adding in versions of the parametrisation functions that take std:maps of Voxels (suggested in #123).

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