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