source: trunk/src/Detection/detection.hh

Last change on this file was 1425, checked in by MatthewWhiting, 7 years ago

Applying patches from the ASKAPsoft development. This adds additional
options to the Detection class to support enhanced parameterisation,
particularly of 3D (HI/spectral-line) sources. Additions include Z50 &
Z20 min/max values, provision of a bounding subsection string, and
better comments describing the setOffsets function.
ASKAPSDP revision r7646

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