1 | #ifndef DETECTION_H |
---|
2 | #define DETECTION_H |
---|
3 | |
---|
4 | #include <iostream> |
---|
5 | #include <string> |
---|
6 | #include <vector> |
---|
7 | #include <param.hh> |
---|
8 | #include <PixelMap/Voxel.hh> |
---|
9 | #include <PixelMap/Scan.hh> |
---|
10 | #include <PixelMap/Object2D.hh> |
---|
11 | #include <PixelMap/Object3D.hh> |
---|
12 | #include <Detection/columns.hh> |
---|
13 | #include <Utils/utils.hh> |
---|
14 | |
---|
15 | using namespace Column; |
---|
16 | using namespace PixelInfo; |
---|
17 | |
---|
18 | //========================================================================== |
---|
19 | |
---|
20 | /** |
---|
21 | * Class to represent a contiguous set of detected voxels. |
---|
22 | * This is a detected object, which features: |
---|
23 | * a vector of voxels, centroid positions, total & peak fluxes, |
---|
24 | * the possibility of WCS-calculated parameters (RA, Dec, velocity, |
---|
25 | * related widths). |
---|
26 | * Also many functions with which to manipulate the Detections. |
---|
27 | */ |
---|
28 | |
---|
29 | class Detection |
---|
30 | { |
---|
31 | public: |
---|
32 | Detection(){ |
---|
33 | flagWCS=false; negSource = false; flagText=""; |
---|
34 | totalFlux = peakFlux = 0.; |
---|
35 | }; |
---|
36 | Detection(const Detection& d); |
---|
37 | Detection& operator= (const Detection& d); |
---|
38 | virtual ~Detection(){}; |
---|
39 | //------------------------------ |
---|
40 | // These are functions in detection.cc. |
---|
41 | // |
---|
42 | /** Add all voxels of one object to another. */ |
---|
43 | friend Detection operator+ (Detection lhs, Detection rhs); |
---|
44 | friend Detection operator+= (Detection lhs, Detection rhs){ |
---|
45 | lhs = lhs + rhs; |
---|
46 | return lhs; |
---|
47 | } |
---|
48 | |
---|
49 | /** Provides a reference to the StatsContainer. */ |
---|
50 | Object3D& pixels(){ Object3D &rpix = this->pixelArray; return rpix;}; |
---|
51 | |
---|
52 | /** Calculate basic parameters of the Detection. */ |
---|
53 | void calcParams(){pixelArray.calcParams();}; |
---|
54 | |
---|
55 | /** Calculate flux-related parameters of the Detection. */ |
---|
56 | void calcFluxes(float *fluxArray, long *dim); |
---|
57 | |
---|
58 | /** Calculate parameters related to the World Coordinate System. */ |
---|
59 | void calcWCSparams(float *fluxArray, long *dim, FitsHeader &head); |
---|
60 | |
---|
61 | /** Calculate the integrated flux over the entire Detection. */ |
---|
62 | float getIntegFlux(float *fluxArray, long *dim, FitsHeader &head); |
---|
63 | |
---|
64 | /** Set the values of the axis offsets from the cube. */ |
---|
65 | void setOffsets(Param &par); |
---|
66 | |
---|
67 | /** Add the offset values to the pixel locations */ |
---|
68 | void addOffsets(){pixelArray.addOffsets(xSubOffset,ySubOffset,zSubOffset);}; |
---|
69 | |
---|
70 | // |
---|
71 | friend std::ostream& operator<< ( std::ostream& theStream, Detection& obj); |
---|
72 | //--------------------------------- |
---|
73 | // Text Output -- all in Detection/outputDetection.cc |
---|
74 | // |
---|
75 | /** The spectral output label that contains info on the WCS position |
---|
76 | & velocity.*/ |
---|
77 | std::string outputLabelWCS(); |
---|
78 | |
---|
79 | /** The spectral output label that contains info on the pixel |
---|
80 | location. */ |
---|
81 | std::string outputLabelPix(); |
---|
82 | |
---|
83 | /** The spectral output label that contains info on widths & fluxes |
---|
84 | of the Detection. */ |
---|
85 | std::string outputLabelInfo(); |
---|
86 | |
---|
87 | /** Prints the column headers. */ |
---|
88 | void outputDetectionTextHeader(std::ostream &stream, std::vector<Col> columns); |
---|
89 | |
---|
90 | /** Prints the full set of columns, including the WCS |
---|
91 | information. */ |
---|
92 | void outputDetectionTextWCS(std::ostream &stream, std::vector<Col> columns); |
---|
93 | |
---|
94 | /** Prints a limited set of columns, excluding any WCS |
---|
95 | information. */ |
---|
96 | void outputDetectionText(std::ostream &stream, std::vector<Col> columns, int idNumber); |
---|
97 | //---------------------------------- |
---|
98 | // For plotting routines... in Cubes/drawMomentCutout.cc |
---|
99 | // |
---|
100 | /** Draw spatial borders for a particular Detection. */ |
---|
101 | void drawBorders(int xoffset, int yoffset); |
---|
102 | // |
---|
103 | /** Sort the pixels by central z-value. */ |
---|
104 | void SortByZ(){pixelArray.order();}; |
---|
105 | // |
---|
106 | //---------------------------------- |
---|
107 | // Basic functions |
---|
108 | // |
---|
109 | /** Delete all pixel information from Detection. Does not clear |
---|
110 | other parameters. */ |
---|
111 | // void clearDetection(){this->pix.clear();}; |
---|
112 | |
---|
113 | /** Add a single voxel to the pixel list.*/ |
---|
114 | void addPixel(long x, long y, long z){pixelArray.addPixel(x,y,z);}; |
---|
115 | void addPixel(Voxel point){ |
---|
116 | /** This one adds the pixel to the pixelArray, and updates the |
---|
117 | fluxes according to the Voxel's flux information */ |
---|
118 | pixelArray.addPixel(point); |
---|
119 | totalFlux += point.getF(); |
---|
120 | if(point.getF()>peakFlux){ |
---|
121 | peakFlux = point.getF(); |
---|
122 | xpeak = point.getX(); ypeak = point.getY(); zpeak = point.getZ(); |
---|
123 | } |
---|
124 | }; |
---|
125 | |
---|
126 | /** Return a single voxel. */ |
---|
127 | Voxel getPixel(int i){return pixelArray.getPixel(i);}; |
---|
128 | |
---|
129 | /** How many voxels are in the Detection? */ |
---|
130 | int getSize(){return pixelArray.getSize();}; |
---|
131 | |
---|
132 | /** How many distinct spatial pixels are there? */ |
---|
133 | int getSpatialSize(){return pixelArray.getSpatialSize();}; |
---|
134 | |
---|
135 | /** How many channels does the Detection have? */ |
---|
136 | long getNumChannels(){return pixelArray.getNumDistinctZ();}; |
---|
137 | |
---|
138 | /** Is there at least the acceptable minimum number of channels in |
---|
139 | the Detection? */ |
---|
140 | bool hasEnoughChannels(int minNumber); |
---|
141 | |
---|
142 | //----------------------------------- |
---|
143 | // Basic accessor functions for private members follow... |
---|
144 | // |
---|
145 | long getXOffset(){return xSubOffset;}; |
---|
146 | void setXOffset(long o){xSubOffset = o;}; |
---|
147 | long getYOffset(){return ySubOffset;}; |
---|
148 | void setYOffset(long o){ySubOffset = o;}; |
---|
149 | long getZOffset(){return zSubOffset;}; |
---|
150 | void setZOffset(long o){zSubOffset = o;}; |
---|
151 | // |
---|
152 | float getXcentre(){return pixelArray.getXcentre();}; |
---|
153 | float getYcentre(){return pixelArray.getYcentre();}; |
---|
154 | float getZcentre(){return pixelArray.getZcentre();}; |
---|
155 | float getTotalFlux(){return totalFlux;}; |
---|
156 | void setTotalFlux(float f){totalFlux=f;}; |
---|
157 | float getIntegFlux(){return intFlux;}; |
---|
158 | void setIntegFlux(float f){intFlux=f;}; |
---|
159 | float getPeakFlux(){return peakFlux;}; |
---|
160 | void setPeakFlux(float f){peakFlux=f;}; |
---|
161 | long getXPeak(){return xpeak;}; |
---|
162 | long getYPeak(){return ypeak;}; |
---|
163 | long getZPeak(){return zpeak;}; |
---|
164 | float getPeakSNR(){return peakSNR;}; |
---|
165 | void setPeakSNR(float f){peakSNR = f;}; |
---|
166 | bool isNegative(){return negSource;}; |
---|
167 | void setNegative(bool f){negSource = f;}; |
---|
168 | std::string getFlagText(){return flagText;}; |
---|
169 | void setFlagText(std::string s){flagText = s;}; |
---|
170 | void addToFlagText(std::string s){flagText += s;}; |
---|
171 | // |
---|
172 | long getXmin(){return pixelArray.getXmin();}; |
---|
173 | long getYmin(){return pixelArray.getYmin();}; |
---|
174 | long getZmin(){return pixelArray.getZmin();}; |
---|
175 | long getXmax(){return pixelArray.getXmax();}; |
---|
176 | long getYmax(){return pixelArray.getYmax();}; |
---|
177 | long getZmax(){return pixelArray.getZmax();}; |
---|
178 | // |
---|
179 | /** Is the WCS good enough to be used? |
---|
180 | \return Detection::flagWCS = True/False */ |
---|
181 | bool isWCS(){return flagWCS;}; |
---|
182 | std::string getName(){return name;}; |
---|
183 | void setName(std::string s){name=s;}; |
---|
184 | std::string getRAs(){return raS;}; |
---|
185 | std::string getDecs(){return decS;}; |
---|
186 | float getRA(){return ra;}; |
---|
187 | float getDec(){return dec;}; |
---|
188 | float getRAWidth(){return raWidth;}; |
---|
189 | float getDecWidth(){return decWidth;}; |
---|
190 | float getVel(){return vel;}; |
---|
191 | float getVelWidth(){return velWidth;}; |
---|
192 | float getVelMin(){return velMin;}; |
---|
193 | float getVelMax(){return velMax;}; |
---|
194 | int getID(){return id;}; |
---|
195 | void setID(int i){id = i;}; |
---|
196 | // |
---|
197 | int getPosPrec(){return posPrec;}; |
---|
198 | void setPosPrec(int i){posPrec=i;}; |
---|
199 | int getXYZPrec(){return xyzPrec;}; |
---|
200 | void setXYZPrec(int i){xyzPrec=i;}; |
---|
201 | int getFintPrec(){return fintPrec;}; |
---|
202 | void setFintPrec(int i){fintPrec=i;}; |
---|
203 | int getFpeakPrec(){return fpeakPrec;}; |
---|
204 | void setFpeakPrec(int i){fpeakPrec=i;}; |
---|
205 | int getVelPrec(){return velPrec;}; |
---|
206 | void setVelPrec(int i){velPrec=i;}; |
---|
207 | int getSNRPrec(){return snrPrec;}; |
---|
208 | void setSNRPrec(int i){snrPrec=i;}; |
---|
209 | // |
---|
210 | private: |
---|
211 | Object3D pixelArray; ///< The pixel locations |
---|
212 | // Subsection offsets |
---|
213 | long xSubOffset; ///< The x-offset, from subsectioned cube |
---|
214 | long ySubOffset; ///< The y-offset, from subsectioned cube |
---|
215 | long zSubOffset; ///< The z-offset, from subsectioned cube |
---|
216 | // Flux related |
---|
217 | float totalFlux; ///< sum of the fluxes of all the pixels |
---|
218 | float intFlux; ///< integrated flux : involves |
---|
219 | /// integration over velocity. |
---|
220 | float peakFlux; ///< maximum flux over all the pixels |
---|
221 | long xpeak; ///< x-pixel location of peak flux |
---|
222 | long ypeak; ///< y-pixel location of peak flux |
---|
223 | long zpeak; ///< z-pixel location of peak flux |
---|
224 | float peakSNR; ///< signal-to-noise ratio at peak |
---|
225 | bool negSource; ///< is the source a negative feature? |
---|
226 | std::string flagText; ///< any warning flags about the |
---|
227 | /// quality of the detection. |
---|
228 | // WCS related |
---|
229 | int id; ///< ID -- generally number in list |
---|
230 | std::string name; ///< IAU-style name (based on position) |
---|
231 | bool flagWCS; ///< A flag indicating whether the |
---|
232 | /// WCS parameters have been set. |
---|
233 | std::string raS; ///< Central Right Ascension (or |
---|
234 | /// Longitude) in form 12:34:23 |
---|
235 | std::string decS; ///< Central Declination(or |
---|
236 | /// Latitude), in form -12:23:34 |
---|
237 | float ra; ///< Central Right Ascension in degrees |
---|
238 | float dec; ///< Central Declination in degrees |
---|
239 | float raWidth; ///< Width of detection in RA |
---|
240 | /// direction in arcmin |
---|
241 | float decWidth; ///< Width of detection in Dec |
---|
242 | /// direction in arcmin |
---|
243 | std::string specUnits; ///< Units of the spectral dimension |
---|
244 | std::string fluxUnits; ///< Units of flux |
---|
245 | std::string intFluxUnits; ///< Units of integrated flux |
---|
246 | std::string lngtype; ///< Type of longitude axis (RA/GLON) |
---|
247 | std::string lattype; ///< Type of latitude axis (DEC/GLAT) |
---|
248 | float vel; ///< Central velocity (from zCentre) |
---|
249 | float velWidth; ///< Full velocity width |
---|
250 | float velMin; ///< Minimum velocity |
---|
251 | float velMax; ///< Maximum velocity |
---|
252 | // The next six are the precision of values printed in the headers |
---|
253 | // of the spectral plots |
---|
254 | int posPrec; ///< Precision of WCS positional values |
---|
255 | int xyzPrec; ///< Precision of pixel positional |
---|
256 | /// values |
---|
257 | int fintPrec; ///< Precision of F_int/F_tot values |
---|
258 | int fpeakPrec; ///< Precision of F_peak values |
---|
259 | int velPrec; ///< Precision of velocity values. |
---|
260 | int snrPrec; ///< Precision of S/N_max values. |
---|
261 | |
---|
262 | }; |
---|
263 | |
---|
264 | //========================================================================== |
---|
265 | |
---|
266 | ////////////////////////////////////////////////////// |
---|
267 | // Prototypes for functions that use above classes |
---|
268 | ////////////////////////////////////////////////////// |
---|
269 | |
---|
270 | //---------------- |
---|
271 | // These are in sorting.cc |
---|
272 | // |
---|
273 | /** Sort a list of Detections by Z-pixel value. */ |
---|
274 | void SortByZ(std::vector <Detection> &inputList); |
---|
275 | |
---|
276 | /** Sort a list of Detections by Velocity.*/ |
---|
277 | void SortByVel(std::vector <Detection> &inputList); |
---|
278 | |
---|
279 | //---------------- |
---|
280 | // This is in areClose.cc |
---|
281 | // |
---|
282 | /** Determine whether two objects are close according to set parameters.*/ |
---|
283 | bool areClose(Detection &object1, Detection &object2, Param &par); |
---|
284 | |
---|
285 | //---------------- |
---|
286 | // This is in mergeIntoList.cc |
---|
287 | // |
---|
288 | /** Add an object into a list, combining with adjacent objects if need be. */ |
---|
289 | void mergeIntoList(Detection &object, std::vector <Detection> &objList, |
---|
290 | Param &par); |
---|
291 | |
---|
292 | //---------------- |
---|
293 | // These are in Cubes/Merger.cc |
---|
294 | // |
---|
295 | /** Merge a list of Detections so that all adjacent voxels are in the same Detection. */ |
---|
296 | void mergeList(std::vector<Detection> &objList, Param &par); |
---|
297 | /** Culls a list of Detections that do not meet minimum requirements. */ |
---|
298 | void finaliseList(std::vector<Detection> &objList, Param &par); |
---|
299 | /** Manage both the merging and the cleaning up of the list. */ |
---|
300 | void ObjectMerger(std::vector<Detection> &objList, Param &par); |
---|
301 | |
---|
302 | |
---|
303 | #endif |
---|