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