1 | // ----------------------------------------------------------------------- |
---|
2 | // outputDetection.cc: Different ways of printing inforamtion about |
---|
3 | // the Detections. |
---|
4 | // ----------------------------------------------------------------------- |
---|
5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
6 | // |
---|
7 | // This program is free software; you can redistribute it and/or modify it |
---|
8 | // under the terms of the GNU General Public License as published by the |
---|
9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
10 | // option) any later version. |
---|
11 | // |
---|
12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
15 | // for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License |
---|
18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
20 | // |
---|
21 | // Correspondence concerning Duchamp may be directed to: |
---|
22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
23 | // Postal address: Dr. Matthew Whiting |
---|
24 | // Australia Telescope National Facility, CSIRO |
---|
25 | // PO Box 76 |
---|
26 | // Epping NSW 1710 |
---|
27 | // AUSTRALIA |
---|
28 | // ----------------------------------------------------------------------- |
---|
29 | #include <iostream> |
---|
30 | #include <sstream> |
---|
31 | #include <fstream> |
---|
32 | #include <iomanip> |
---|
33 | #include <string> |
---|
34 | #include <vector> |
---|
35 | #include <duchamp/duchamp.hh> |
---|
36 | #include <duchamp/Detection/detection.hh> |
---|
37 | #include <duchamp/Cubes/cubes.hh> |
---|
38 | #include <duchamp/Utils/utils.hh> |
---|
39 | #include <duchamp/Detection/columns.hh> |
---|
40 | #include <duchamp/Utils/feedback.hh> |
---|
41 | |
---|
42 | namespace duchamp |
---|
43 | { |
---|
44 | |
---|
45 | using namespace Column; |
---|
46 | |
---|
47 | void outputTableHeader(std::ostream &stream, std::vector<Column::Col> columns, std::string tableType, bool flagWCS) |
---|
48 | { |
---|
49 | /// @details |
---|
50 | /// Prints the header row for a table of detections. The columns |
---|
51 | /// that are included depend on the value of tableType, according |
---|
52 | /// to the Column::doCol() function. The format is a row of |
---|
53 | /// dashes, a row with column names, a row with column units, and |
---|
54 | /// another row of dashes. |
---|
55 | /// \param stream Where the output is written |
---|
56 | /// \param columns The vector list of Column objects |
---|
57 | /// \param tableType A string saying what format to use: one of |
---|
58 | /// "file", "log", "screen" or "votable" (although the latter |
---|
59 | /// shouldn't be used with this function). |
---|
60 | /// \param flagWCS A flag for use with Column::doCol(), specifying |
---|
61 | /// whether to use FINT or FTOT. |
---|
62 | |
---|
63 | std::vector<Column::Col>::iterator col; |
---|
64 | for(col=columns.begin();col<columns.end();col++) |
---|
65 | if(col->doCol(tableType,flagWCS)) col->printDash(stream); |
---|
66 | stream << "\n"; |
---|
67 | for(col=columns.begin();col<columns.end();col++) |
---|
68 | if(col->doCol(tableType,flagWCS)) col->printTitle(stream); |
---|
69 | stream << "\n"; |
---|
70 | for(col=columns.begin();col<columns.end();col++) |
---|
71 | if(col->doCol(tableType,flagWCS)) col->printUnits(stream); |
---|
72 | stream << "\n"; |
---|
73 | for(col=columns.begin();col<columns.end();col++) |
---|
74 | if(col->doCol(tableType,flagWCS)) col->printDash(stream); |
---|
75 | stream << "\n"; |
---|
76 | |
---|
77 | } |
---|
78 | //-------------------------------------------------------------------- |
---|
79 | |
---|
80 | void Detection::printTableRow(std::ostream &stream, std::vector<Column::Col> columns, std::string tableType) |
---|
81 | { |
---|
82 | /// @details |
---|
83 | /// Print a row of values for the current Detection into an output |
---|
84 | /// table. Columns are printed according to the tableType string, |
---|
85 | /// using the Column::doCol() function as a determinant. |
---|
86 | /// \param stream Where the output is written |
---|
87 | /// \param columns The vector list of Column objects |
---|
88 | /// \param tableType A string saying what format to use: one of |
---|
89 | /// "file", "log", "screen" or "votable" (although the latter |
---|
90 | /// shouldn't be used with this function). |
---|
91 | |
---|
92 | stream.setf(std::ios::fixed); |
---|
93 | std::vector<Column::Col>::iterator col; |
---|
94 | for(col=columns.begin();col<columns.end();col++) |
---|
95 | if(col->doCol(tableType,this->flagWCS)) this->printTableEntry(stream, *col); |
---|
96 | |
---|
97 | stream << "\n"; |
---|
98 | |
---|
99 | } |
---|
100 | //-------------------------------------------------------------------- |
---|
101 | |
---|
102 | void Detection::printTableEntry(std::ostream &stream, Column::Col column) |
---|
103 | { |
---|
104 | /// @details |
---|
105 | /// Print a single value into an output table. The Detection's |
---|
106 | /// correct value is extracted according to the Column::COLNAME |
---|
107 | /// key in the column given. |
---|
108 | /// \param stream Where the output is written |
---|
109 | /// \param column The Column object defining the formatting. |
---|
110 | |
---|
111 | switch(column.getType()) |
---|
112 | { |
---|
113 | case NUM: |
---|
114 | column.printEntry(stream,this->id); |
---|
115 | break; |
---|
116 | case NAME: |
---|
117 | column.printEntry(stream,this->name); |
---|
118 | break; |
---|
119 | case X: |
---|
120 | column.printEntry(stream,this->getXcentre() + this->xSubOffset); |
---|
121 | break; |
---|
122 | case Y: |
---|
123 | column.printEntry(stream,this->getYcentre() + this->ySubOffset); |
---|
124 | break; |
---|
125 | case Z: |
---|
126 | column.printEntry(stream,this->getZcentre() + this->zSubOffset); |
---|
127 | break; |
---|
128 | case RA: |
---|
129 | if(this->flagWCS) column.printEntry(stream,this->raS); |
---|
130 | else column.printBlank(stream); |
---|
131 | break; |
---|
132 | case DEC: |
---|
133 | if(this->flagWCS) column.printEntry(stream,this->decS); |
---|
134 | else column.printBlank(stream); |
---|
135 | break; |
---|
136 | case RAJD: |
---|
137 | if(this->flagWCS) column.printEntry(stream,this->ra); |
---|
138 | else column.printBlank(stream); |
---|
139 | break; |
---|
140 | case DECJD: |
---|
141 | if(this->flagWCS) column.printEntry(stream,this->dec); |
---|
142 | else column.printBlank(stream); |
---|
143 | break; |
---|
144 | case VEL: |
---|
145 | if(this->flagWCS) { |
---|
146 | if(this->specOK) column.printEntry(stream,this->vel); |
---|
147 | else column.printEntry(stream,0.); |
---|
148 | } |
---|
149 | else column.printBlank(stream); |
---|
150 | break; |
---|
151 | case WRA: |
---|
152 | if(this->flagWCS) column.printEntry(stream,this->raWidth); |
---|
153 | else column.printBlank(stream); |
---|
154 | break; |
---|
155 | case WDEC: |
---|
156 | if(this->flagWCS) column.printEntry(stream,this->decWidth); |
---|
157 | else column.printBlank(stream); |
---|
158 | break; |
---|
159 | case W50: |
---|
160 | // if(this->flagWCS) { |
---|
161 | if(this->specOK) column.printEntry(stream,this->w50); |
---|
162 | else column.printEntry(stream,0.); |
---|
163 | // } |
---|
164 | // else column.printBlank(stream); |
---|
165 | break; |
---|
166 | case W20: |
---|
167 | // if(this->flagWCS) { |
---|
168 | if(this->specOK) column.printEntry(stream,this->w20); |
---|
169 | else column.printEntry(stream,0.); |
---|
170 | // } |
---|
171 | // else column.printBlank(stream); |
---|
172 | break; |
---|
173 | case WVEL: |
---|
174 | // if(this->flagWCS) { |
---|
175 | if(this->specOK) column.printEntry(stream,this->velWidth); |
---|
176 | else column.printEntry(stream,0.); |
---|
177 | // } |
---|
178 | // else column.printBlank(stream); |
---|
179 | break; |
---|
180 | case FINT: |
---|
181 | column.printEntry(stream,this->intFlux); |
---|
182 | break; |
---|
183 | case FTOT: |
---|
184 | column.printEntry(stream,this->totalFlux); |
---|
185 | break; |
---|
186 | case FPEAK: |
---|
187 | column.printEntry(stream,this->peakFlux); |
---|
188 | break; |
---|
189 | case SNRPEAK: |
---|
190 | column.printEntry(stream,this->peakSNR); |
---|
191 | break; |
---|
192 | case X1: |
---|
193 | column.printEntry(stream,this->getXmin() + this->xSubOffset); |
---|
194 | break; |
---|
195 | case X2: |
---|
196 | column.printEntry(stream,this->getXmax() + this->xSubOffset); |
---|
197 | break; |
---|
198 | case Y1: |
---|
199 | column.printEntry(stream,this->getYmin() + this->ySubOffset); |
---|
200 | break; |
---|
201 | case Y2: |
---|
202 | column.printEntry(stream,this->getYmax() + this->ySubOffset); |
---|
203 | break; |
---|
204 | case Z1: |
---|
205 | column.printEntry(stream,this->getZmin() + this->zSubOffset); |
---|
206 | break; |
---|
207 | case Z2: |
---|
208 | column.printEntry(stream,this->getZmax() + this->zSubOffset); |
---|
209 | break; |
---|
210 | case NPIX: |
---|
211 | // column.printEntry(stream,int(this->pixelArray.getSize())); |
---|
212 | column.printEntry(stream,int(this->getSize())); |
---|
213 | break; |
---|
214 | case FLAG: |
---|
215 | column.printEntry(stream,this->flagText); |
---|
216 | break; |
---|
217 | case XAV: |
---|
218 | // column.printEntry(stream,this->getXAverage() + this->xSubOffset); |
---|
219 | column.printEntry(stream,this->getXaverage() + this->xSubOffset); |
---|
220 | break; |
---|
221 | case YAV: |
---|
222 | // column.printEntry(stream,this->getYAverage() + this->ySubOffset); |
---|
223 | column.printEntry(stream,this->getYaverage() + this->ySubOffset); |
---|
224 | break; |
---|
225 | case ZAV: |
---|
226 | // column.printEntry(stream,this->getZAverage() + this->zSubOffset); |
---|
227 | column.printEntry(stream,this->getZaverage() + this->zSubOffset); |
---|
228 | break; |
---|
229 | case XCENT: |
---|
230 | column.printEntry(stream,this->getXCentroid() + this->xSubOffset); |
---|
231 | break; |
---|
232 | case YCENT: |
---|
233 | column.printEntry(stream,this->getYCentroid() + this->ySubOffset); |
---|
234 | break; |
---|
235 | case ZCENT: |
---|
236 | column.printEntry(stream,this->getZCentroid() + this->zSubOffset); |
---|
237 | break; |
---|
238 | case XPEAK: |
---|
239 | column.printEntry(stream,this->getXPeak() + this->xSubOffset); |
---|
240 | break; |
---|
241 | case YPEAK: |
---|
242 | column.printEntry(stream,this->getYPeak() + this->ySubOffset); |
---|
243 | break; |
---|
244 | case ZPEAK: |
---|
245 | column.printEntry(stream,this->getZPeak() + this->zSubOffset); |
---|
246 | break; |
---|
247 | case NUMCH: |
---|
248 | column.printEntry(stream,this->getMaxAdjacentChannels()); |
---|
249 | break; |
---|
250 | case SPATSIZE: |
---|
251 | column.printEntry(stream,int(this->getSpatialSize())); |
---|
252 | break; |
---|
253 | case UNKNOWN: |
---|
254 | default: |
---|
255 | break; |
---|
256 | }; |
---|
257 | } |
---|
258 | //-------------------------------------------------------------------- |
---|
259 | |
---|
260 | std::string Detection::outputLabelWCS() |
---|
261 | { |
---|
262 | /// @details |
---|
263 | /// Prints to a std::string the WCS position and velocity |
---|
264 | /// information of the Detection, as well as the ID number and any |
---|
265 | /// flags. |
---|
266 | /// Assumes the WCS parameters of the object have been calculated. |
---|
267 | /// If they have not (given by the isWCS() function), then the |
---|
268 | /// WCS-related outputs are left blank. |
---|
269 | /// Returns the string. |
---|
270 | |
---|
271 | std::stringstream ss; |
---|
272 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
273 | ss << this->name ; |
---|
274 | if(this->getFlagText()!="-") |
---|
275 | ss << " [" << this->getFlagText() << "] "; |
---|
276 | else ss<< " "; |
---|
277 | ss << std::setfill(' '); |
---|
278 | ss << this->raS << ", "; |
---|
279 | ss << this->decS; |
---|
280 | if(this->specOK){ |
---|
281 | ss << std::setprecision(this->velPrec); |
---|
282 | ss.setf(std::ios::fixed); |
---|
283 | ss << ", " << this->vel << " " << this->specUnits; |
---|
284 | } |
---|
285 | |
---|
286 | return ss.str(); |
---|
287 | |
---|
288 | } |
---|
289 | //-------------------------------------------------------------------- |
---|
290 | |
---|
291 | std::string Detection::outputLabelFluxes() |
---|
292 | { |
---|
293 | /// @details |
---|
294 | /// Prints to a std::string the fluxes of the object, both |
---|
295 | /// integrated/total and peak, as well as the peak S/N value. |
---|
296 | /// Assumes the WCS parameters of the object have been calculated. |
---|
297 | /// If they have not (given by the isWCS() function), then the ID |
---|
298 | /// number and the total/peak/SNR values are returned. |
---|
299 | /// /return The string. |
---|
300 | |
---|
301 | std::stringstream ss; |
---|
302 | ss.setf(std::ios::fixed); |
---|
303 | if(this->flagWCS){ |
---|
304 | ss << std::setprecision(this->fintPrec); |
---|
305 | ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits; |
---|
306 | ss << std::setprecision(this->fpeakPrec); |
---|
307 | ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits; |
---|
308 | ss << std::setprecision(this->snrPrec); |
---|
309 | ss << ", S/N\\dmax\\u=" << this->peakSNR; |
---|
310 | } |
---|
311 | else{ |
---|
312 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
313 | ss << std::setprecision(this->fintPrec); |
---|
314 | ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits; |
---|
315 | ss << std::setprecision(this->fpeakPrec); |
---|
316 | ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits; |
---|
317 | ss << std::setprecision(this->snrPrec); |
---|
318 | ss << ", S/N\\dmax\\u=" << this->peakSNR; |
---|
319 | } |
---|
320 | std::string output = ss.str(); |
---|
321 | |
---|
322 | return output; |
---|
323 | } |
---|
324 | //-------------------------------------------------------------------- |
---|
325 | |
---|
326 | std::string Detection::outputLabelWidths() |
---|
327 | { |
---|
328 | /// @details |
---|
329 | /// Prints to a std::string the widths of the object in position |
---|
330 | /// and velocity. |
---|
331 | /// Assumes the WCS parameters of the object have been calculated. |
---|
332 | /// If they have not (given by the isWCS() function), then a string of |
---|
333 | /// length 0 is returned. |
---|
334 | /// \returns The string. |
---|
335 | |
---|
336 | std::string output; |
---|
337 | if(this->flagWCS){ |
---|
338 | std::stringstream ss; |
---|
339 | ss.setf(std::ios::fixed); |
---|
340 | ss << std::setprecision(this->posPrec); |
---|
341 | ss << "W\\d" << this->lngtype <<"\\u=" << this->raWidth; |
---|
342 | ss << ", W\\d" << this->lattype <<"\\u=" << this->decWidth; |
---|
343 | if(this->specOK){ |
---|
344 | ss << std::setprecision(this->velPrec); |
---|
345 | ss << ", W\\d50\\u=" << this->w50 << " " << this->specUnits; |
---|
346 | ss << ", W\\d20\\u=" << this->w20 << " " << this->specUnits; |
---|
347 | ss << ", W\\d"<<this->specType<<"\\u=" << this->velWidth << " " << this->specUnits; |
---|
348 | } |
---|
349 | output = ss.str(); |
---|
350 | } |
---|
351 | else output = this->outputLabelFluxes(); |
---|
352 | |
---|
353 | return output; |
---|
354 | } |
---|
355 | //-------------------------------------------------------------------- |
---|
356 | |
---|
357 | std::string Detection::outputLabelPix() |
---|
358 | { |
---|
359 | /// @details |
---|
360 | /// Prints to a std::string the pixel centres and extents of a |
---|
361 | /// detected object. Returns the string. |
---|
362 | |
---|
363 | std::stringstream ss; |
---|
364 | ss.setf(std::ios::fixed); |
---|
365 | ss << "Centre: "; |
---|
366 | ss << std::setprecision(this->xyzPrec) << std::setfill(' '); |
---|
367 | ss <<"(" << this->getXcentre() + this->xSubOffset; |
---|
368 | ss <<", " << this->getYcentre() + this->ySubOffset; |
---|
369 | ss <<", " << this->getZcentre() + this->zSubOffset << ")"; |
---|
370 | // ss <<", Size: "<< this->pixelArray.getSize() << " voxels, "; |
---|
371 | ss <<", Size: "<< this->getSize() << " voxels, "; |
---|
372 | ss <<"Range: ["; |
---|
373 | ss << this->getXmin() + this->xSubOffset |
---|
374 | <<":" << this->getXmax() + this->xSubOffset; |
---|
375 | ss <<", " << this->getYmin() + this->ySubOffset |
---|
376 | <<":" << this->getYmax() + this->ySubOffset; |
---|
377 | if(this->specOK){ |
---|
378 | ss <<", " << this->getZmin() + this->zSubOffset |
---|
379 | <<":" << this->getZmax() + this->zSubOffset; |
---|
380 | } |
---|
381 | ss<< "]"; |
---|
382 | |
---|
383 | return ss.str(); |
---|
384 | } |
---|
385 | |
---|
386 | |
---|
387 | } |
---|