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