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/Outputs/columns.hh> |
---|
40 | #include <duchamp/Outputs/CatalogueSpecification.hh> |
---|
41 | #include <duchamp/Utils/feedback.hh> |
---|
42 | |
---|
43 | namespace duchamp |
---|
44 | { |
---|
45 | |
---|
46 | void outputTableHeader(std::ostream &stream, Catalogues::CatalogueSpecification columns, Catalogues::DESTINATION tableType, bool flagWCS) |
---|
47 | { |
---|
48 | /// @details |
---|
49 | /// Prints the header row for a table of detections. The columns |
---|
50 | /// that are included depend on the value of tableType, according |
---|
51 | /// to the Column::doCol() function. The format is a row of |
---|
52 | /// dashes, a row with column names, a row with column units, and |
---|
53 | /// another row of dashes. |
---|
54 | /// \param stream Where the output is written |
---|
55 | /// \param columns The vector list of Column objects |
---|
56 | /// \param tableType A string saying what format to use: one of |
---|
57 | /// "file", "log", "screen" or "votable" (although the latter |
---|
58 | /// shouldn't be used with this function). |
---|
59 | /// \param flagWCS A flag for use with Column::doCol(), specifying |
---|
60 | /// whether to use FINT or FTOT. |
---|
61 | |
---|
62 | for(size_t i=0;i<columns.size();i++) |
---|
63 | if(columns.column(i).doCol(tableType,flagWCS)) columns.column(i).printDash(stream); |
---|
64 | stream << "\n"; |
---|
65 | for(size_t i=0;i<columns.size();i++) |
---|
66 | if(columns.column(i).doCol(tableType,flagWCS)) columns.column(i).printTitle(stream); |
---|
67 | stream << "\n"; |
---|
68 | for(size_t i=0;i<columns.size();i++) |
---|
69 | if(columns.column(i).doCol(tableType,flagWCS)) columns.column(i).printUnits(stream); |
---|
70 | stream << "\n"; |
---|
71 | for(size_t i=0;i<columns.size();i++) |
---|
72 | if(columns.column(i).doCol(tableType,flagWCS)) columns.column(i).printDash(stream); |
---|
73 | stream << "\n"; |
---|
74 | |
---|
75 | } |
---|
76 | //-------------------------------------------------------------------- |
---|
77 | |
---|
78 | void Detection::printTableRow(std::ostream &stream, Catalogues::CatalogueSpecification columns, Catalogues::DESTINATION tableType) |
---|
79 | { |
---|
80 | /// @details |
---|
81 | /// Print a row of values for the current Detection into an output |
---|
82 | /// table. Columns are printed according to the tableType string, |
---|
83 | /// using the Column::doCol() function as a determinant. |
---|
84 | /// \param stream Where the output is written |
---|
85 | /// \param columns The vector list of Column objects |
---|
86 | /// \param tableType A Catalogues::DESTINATION label saying what format to use: one of |
---|
87 | /// FILE, LOG, SCREEN or VOTABLE (although the latter |
---|
88 | /// shouldn't be used with this function). |
---|
89 | |
---|
90 | stream.setf(std::ios::fixed); |
---|
91 | for(size_t i=0;i<columns.size();i++){ |
---|
92 | if(columns.column(i).doCol(tableType,this->flagWCS)) this->printTableEntry(stream, columns.column(i)); |
---|
93 | } |
---|
94 | stream << "\n"; |
---|
95 | |
---|
96 | } |
---|
97 | //-------------------------------------------------------------------- |
---|
98 | |
---|
99 | void Detection::printTableEntry(std::ostream &stream, Catalogues::Column column) |
---|
100 | { |
---|
101 | /// @details |
---|
102 | /// Print a single value into an output table. The Detection's |
---|
103 | /// correct value is extracted according to the Catalogues::COLNAME |
---|
104 | /// key in the column given. |
---|
105 | /// \param stream Where the output is written |
---|
106 | /// \param column The Column object defining the formatting. |
---|
107 | |
---|
108 | std::string type=column.type(); |
---|
109 | |
---|
110 | if(type=="NUM") column.printEntry(stream,this->id); |
---|
111 | else if(type=="NAME") column.printEntry(stream,this->name); |
---|
112 | else if(type=="X") column.printEntry(stream,this->getXcentre() + this->xSubOffset); |
---|
113 | else if(type=="Y") column.printEntry(stream,this->getYcentre() + this->ySubOffset); |
---|
114 | else if(type=="Z") column.printEntry(stream,this->getZcentre() + this->zSubOffset); |
---|
115 | else if(type=="RA"){ |
---|
116 | if(this->flagWCS) column.printEntry(stream,this->raS); |
---|
117 | else column.printBlank(stream); |
---|
118 | } |
---|
119 | else if(type=="DEC"){ |
---|
120 | if(this->flagWCS) column.printEntry(stream,this->decS); |
---|
121 | else column.printBlank(stream); |
---|
122 | } |
---|
123 | else if(type=="RAJD"){ |
---|
124 | if(this->flagWCS) column.printEntry(stream,this->ra); |
---|
125 | else column.printBlank(stream); |
---|
126 | } |
---|
127 | else if(type=="DECJD"){ |
---|
128 | if(this->flagWCS) column.printEntry(stream,this->dec); |
---|
129 | else column.printBlank(stream); |
---|
130 | } |
---|
131 | else if(type=="VEL"){ |
---|
132 | if(this->flagWCS) { |
---|
133 | if(this->specOK) column.printEntry(stream,this->vel); |
---|
134 | else column.printEntry(stream,0.); |
---|
135 | } |
---|
136 | else column.printBlank(stream); |
---|
137 | } |
---|
138 | else if(type=="WRA"){ |
---|
139 | if(this->flagWCS) column.printEntry(stream,this->raWidth); |
---|
140 | else column.printBlank(stream); |
---|
141 | } |
---|
142 | else if(type=="WDEC"){ |
---|
143 | if(this->flagWCS) column.printEntry(stream,this->decWidth); |
---|
144 | else column.printBlank(stream); |
---|
145 | } |
---|
146 | else if(type=="W50"){ |
---|
147 | if(this->specOK) column.printEntry(stream,this->w50); |
---|
148 | else column.printEntry(stream,0.); |
---|
149 | } |
---|
150 | else if(type=="W20"){ |
---|
151 | if(this->specOK) column.printEntry(stream,this->w20); |
---|
152 | else column.printEntry(stream,0.); |
---|
153 | } |
---|
154 | else if(type=="WVEL"){ |
---|
155 | if(this->specOK) column.printEntry(stream,this->velWidth); |
---|
156 | else column.printEntry(stream,0.); |
---|
157 | } |
---|
158 | else if(type=="FINT") column.printEntry(stream,this->intFlux); |
---|
159 | else if(type=="FTOT") column.printEntry(stream,this->totalFlux); |
---|
160 | else if(type=="FPEAK") column.printEntry(stream,this->peakFlux); |
---|
161 | else if(type=="SNRPEAK") column.printEntry(stream,this->peakSNR); |
---|
162 | else if(type=="X1") column.printEntry(stream,this->getXmin() + this->xSubOffset); |
---|
163 | else if(type=="X2") column.printEntry(stream,this->getXmax() + this->xSubOffset); |
---|
164 | else if(type=="Y1") column.printEntry(stream,this->getYmin() + this->ySubOffset); |
---|
165 | else if(type=="Y2") column.printEntry(stream,this->getYmax() + this->ySubOffset); |
---|
166 | else if(type=="Z1") column.printEntry(stream,this->getZmin() + this->zSubOffset); |
---|
167 | else if(type=="Z2") column.printEntry(stream,this->getZmax() + this->zSubOffset); |
---|
168 | else if(type=="NPIX") column.printEntry(stream,int(this->getSize())); |
---|
169 | else if(type=="FLAG") column.printEntry(stream,this->flagText); |
---|
170 | else if(type=="XAV") column.printEntry(stream,this->getXaverage() + this->xSubOffset); |
---|
171 | else if(type=="YAV") column.printEntry(stream,this->getYaverage() + this->ySubOffset); |
---|
172 | else if(type=="ZAV") column.printEntry(stream,this->getZaverage() + this->zSubOffset); |
---|
173 | else if(type=="XCENT") column.printEntry(stream,this->getXCentroid() + this->xSubOffset); |
---|
174 | else if(type=="YCENT") column.printEntry(stream,this->getYCentroid() + this->ySubOffset); |
---|
175 | else if(type=="ZCENT") column.printEntry(stream,this->getZCentroid() + this->zSubOffset); |
---|
176 | else if(type=="XPEAK") column.printEntry(stream,this->getXPeak() + this->xSubOffset); |
---|
177 | else if(type=="YPEAK") column.printEntry(stream,this->getYPeak() + this->ySubOffset); |
---|
178 | else if(type=="ZPEAK") column.printEntry(stream,this->getZPeak() + this->zSubOffset); |
---|
179 | else if(type=="NUMCH") column.printEntry(stream,this->getMaxAdjacentChannels()); |
---|
180 | else if(type=="SPATSIZE") column.printEntry(stream,int(this->getSpatialSize())); |
---|
181 | |
---|
182 | } |
---|
183 | //-------------------------------------------------------------------- |
---|
184 | |
---|
185 | std::string Detection::outputLabelWCS() |
---|
186 | { |
---|
187 | /// @details |
---|
188 | /// Prints to a std::string the WCS position and velocity |
---|
189 | /// information of the Detection, as well as the ID number and any |
---|
190 | /// flags. |
---|
191 | /// Assumes the WCS parameters of the object have been calculated. |
---|
192 | /// If they have not (given by the isWCS() function), then the |
---|
193 | /// WCS-related outputs are left blank. |
---|
194 | /// Returns the string. |
---|
195 | |
---|
196 | std::stringstream ss; |
---|
197 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
198 | ss << this->name ; |
---|
199 | if(this->getFlagText()!="-") |
---|
200 | ss << " [" << this->getFlagText() << "] "; |
---|
201 | else ss<< " "; |
---|
202 | ss << std::setfill(' '); |
---|
203 | ss << this->raS << ", "; |
---|
204 | ss << this->decS; |
---|
205 | if(this->specOK){ |
---|
206 | ss << std::setprecision(this->velPrec); |
---|
207 | ss.setf(std::ios::fixed); |
---|
208 | ss << ", " << this->vel << " " << this->specUnits; |
---|
209 | } |
---|
210 | |
---|
211 | return ss.str(); |
---|
212 | |
---|
213 | } |
---|
214 | //-------------------------------------------------------------------- |
---|
215 | |
---|
216 | std::string Detection::outputLabelFluxes() |
---|
217 | { |
---|
218 | /// @details |
---|
219 | /// Prints to a std::string the fluxes of the object, both |
---|
220 | /// integrated/total and peak, as well as the peak S/N value. |
---|
221 | /// Assumes the WCS parameters of the object have been calculated. |
---|
222 | /// If they have not (given by the isWCS() function), then the ID |
---|
223 | /// number and the total/peak/SNR values are returned. |
---|
224 | /// /return The string. |
---|
225 | |
---|
226 | std::stringstream ss; |
---|
227 | ss.setf(std::ios::fixed); |
---|
228 | if(this->flagWCS){ |
---|
229 | ss << std::setprecision(this->fintPrec); |
---|
230 | ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits; |
---|
231 | ss << std::setprecision(this->fpeakPrec); |
---|
232 | ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits; |
---|
233 | ss << std::setprecision(this->snrPrec); |
---|
234 | ss << ", S/N\\dmax\\u=" << this->peakSNR; |
---|
235 | } |
---|
236 | else{ |
---|
237 | ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": "; |
---|
238 | ss << std::setprecision(this->fintPrec); |
---|
239 | ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits; |
---|
240 | ss << std::setprecision(this->fpeakPrec); |
---|
241 | ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits; |
---|
242 | ss << std::setprecision(this->snrPrec); |
---|
243 | ss << ", S/N\\dmax\\u=" << this->peakSNR; |
---|
244 | } |
---|
245 | std::string output = ss.str(); |
---|
246 | |
---|
247 | return output; |
---|
248 | } |
---|
249 | //-------------------------------------------------------------------- |
---|
250 | |
---|
251 | std::string Detection::outputLabelWidths() |
---|
252 | { |
---|
253 | /// @details |
---|
254 | /// Prints to a std::string the widths of the object in position |
---|
255 | /// and velocity. |
---|
256 | /// Assumes the WCS parameters of the object have been calculated. |
---|
257 | /// If they have not (given by the isWCS() function), then a string of |
---|
258 | /// length 0 is returned. |
---|
259 | /// \returns The string. |
---|
260 | |
---|
261 | std::string output; |
---|
262 | if(this->flagWCS){ |
---|
263 | std::stringstream ss; |
---|
264 | ss.setf(std::ios::fixed); |
---|
265 | ss << std::setprecision(this->posPrec); |
---|
266 | ss << "W\\d" << this->lngtype <<"\\u=" << this->raWidth; |
---|
267 | ss << ", W\\d" << this->lattype <<"\\u=" << this->decWidth; |
---|
268 | if(this->specOK){ |
---|
269 | ss << std::setprecision(this->velPrec); |
---|
270 | ss << ", W\\d50\\u=" << this->w50 << " " << this->specUnits; |
---|
271 | ss << ", W\\d20\\u=" << this->w20 << " " << this->specUnits; |
---|
272 | ss << ", W\\d"<<this->specType<<"\\u=" << this->velWidth << " " << this->specUnits; |
---|
273 | } |
---|
274 | output = ss.str(); |
---|
275 | } |
---|
276 | else output = this->outputLabelFluxes(); |
---|
277 | |
---|
278 | return output; |
---|
279 | } |
---|
280 | //-------------------------------------------------------------------- |
---|
281 | |
---|
282 | std::string Detection::outputLabelPix() |
---|
283 | { |
---|
284 | /// @details |
---|
285 | /// Prints to a std::string the pixel centres and extents of a |
---|
286 | /// detected object. Returns the string. |
---|
287 | |
---|
288 | std::stringstream ss; |
---|
289 | ss.setf(std::ios::fixed); |
---|
290 | ss << "Centre: "; |
---|
291 | ss << std::setprecision(this->xyzPrec) << std::setfill(' '); |
---|
292 | ss <<"(" << this->getXcentre() + this->xSubOffset; |
---|
293 | ss <<", " << this->getYcentre() + this->ySubOffset; |
---|
294 | ss <<", " << this->getZcentre() + this->zSubOffset << ")"; |
---|
295 | ss <<", Size: "<< this->getSize() << " voxels, "; |
---|
296 | ss <<"Range: ["; |
---|
297 | ss << this->getXmin() + this->xSubOffset |
---|
298 | <<":" << this->getXmax() + this->xSubOffset; |
---|
299 | ss <<", " << this->getYmin() + this->ySubOffset |
---|
300 | <<":" << this->getYmax() + this->ySubOffset; |
---|
301 | if(this->specOK){ |
---|
302 | ss <<", " << this->getZmin() + this->zSubOffset |
---|
303 | <<":" << this->getZmax() + this->zSubOffset; |
---|
304 | } |
---|
305 | ss<< "]"; |
---|
306 | |
---|
307 | return ss.str(); |
---|
308 | } |
---|
309 | |
---|
310 | |
---|
311 | } |
---|