source: trunk/src/Detection/outputDetection.cc @ 521

Last change on this file since 521 was 511, checked in by MatthewWhiting, 16 years ago

following on from [510], making sure the blank flags "-" are not written to the spectra plots

File size: 12.6 KB
Line 
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
42namespace 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    /**
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
64    std::vector<Column::Col>::iterator col;
65    for(col=columns.begin();col<columns.end();col++)
66      if(col->doCol(tableType,flagWCS)) col->printDash(stream);
67    stream << "\n";
68    for(col=columns.begin();col<columns.end();col++)
69      if(col->doCol(tableType,flagWCS)) col->printTitle(stream);
70    stream << "\n";
71    for(col=columns.begin();col<columns.end();col++)
72      if(col->doCol(tableType,flagWCS)) col->printUnits(stream);
73    stream << "\n";
74    for(col=columns.begin();col<columns.end();col++)
75      if(col->doCol(tableType,flagWCS)) col->printDash(stream);
76    stream << "\n";
77
78  }
79  //--------------------------------------------------------------------
80
81  void Detection::printTableRow(std::ostream &stream, std::vector<Column::Col> columns, std::string tableType)
82  {
83    /**
84     *  Print a row of values for the current Detection into an output
85     *  table. Columns are printed according to the tableType string,
86     *  using the Column::doCol() function as a determinant.
87     * \param stream Where the output is written
88     * \param columns The vector list of Column objects
89     * \param tableType A string saying what format to use: one of
90     * "file", "log", "screen" or "votable" (although the latter
91     * shouldn't be used with this function).
92     */
93
94    stream.setf(std::ios::fixed); 
95    std::vector<Column::Col>::iterator col;
96    for(col=columns.begin();col<columns.end();col++)
97      if(col->doCol(tableType,this->flagWCS)) this->printTableEntry(stream, *col);
98     
99    stream << "\n";
100
101  }
102  //--------------------------------------------------------------------
103
104  void Detection::printTableEntry(std::ostream &stream, Column::Col column)
105  {
106    /**
107     *  Print a single value into an output table. The Detection's
108     *  correct value is extracted according to the Column::COLNAME
109     *  key in the column given.
110     * \param stream Where the output is written
111     * \param column The Column object defining the formatting.
112     */
113
114
115    switch(column.getType())
116      {
117      case NUM:
118        column.printEntry(stream,this->id);
119        break;
120      case NAME:
121        column.printEntry(stream,this->name);
122        break;
123      case X:
124        column.printEntry(stream,this->getXcentre() + this->xSubOffset);
125        break;
126      case Y:
127        column.printEntry(stream,this->getYcentre() + this->ySubOffset);
128        break;
129      case Z:
130        column.printEntry(stream,this->getZcentre() + this->zSubOffset);
131        break;
132      case RA:
133        if(this->flagWCS) column.printEntry(stream,this->raS);
134        else column.printBlank(stream);
135        break;
136      case DEC:
137        if(this->flagWCS) column.printEntry(stream,this->decS);
138        else column.printBlank(stream);
139        break;
140      case RAJD:
141        if(this->flagWCS) column.printEntry(stream,this->ra);
142        else column.printBlank(stream);
143        break;
144      case DECJD:
145        if(this->flagWCS) column.printEntry(stream,this->dec);
146        else column.printBlank(stream);
147        break;
148      case VEL:
149        if(this->flagWCS) {
150          if(this->specOK) column.printEntry(stream,this->vel);
151          else column.printEntry(stream,0.);
152        }
153        else column.printBlank(stream);
154        break;
155      case WRA:
156        if(this->flagWCS) column.printEntry(stream,this->raWidth);
157        else column.printBlank(stream);
158        break;
159      case WDEC:
160        if(this->flagWCS) column.printEntry(stream,this->decWidth);
161        else column.printBlank(stream);
162        break;
163      case W50:
164        if(this->flagWCS) {
165          if(this->specOK) column.printEntry(stream,this->w50);
166          else column.printEntry(stream,0.);
167        }
168        else column.printBlank(stream);
169        break;
170      case W20:
171        if(this->flagWCS) {
172          if(this->specOK) column.printEntry(stream,this->w20);
173          else column.printEntry(stream,0.);
174        }
175        else column.printBlank(stream);
176        break;
177      case WVEL:
178        if(this->flagWCS) {
179          if(this->specOK) column.printEntry(stream,this->velWidth);
180          else column.printEntry(stream,0.);
181        }
182        else column.printBlank(stream);
183        break;
184      case FINT:
185        column.printEntry(stream,this->intFlux);
186        break;
187      case FTOT:
188        column.printEntry(stream,this->totalFlux);
189        break;
190      case FPEAK:
191        column.printEntry(stream,this->peakFlux);
192        break;
193      case SNRPEAK:
194        column.printEntry(stream,this->peakSNR);
195        break;
196      case X1:
197        column.printEntry(stream,this->getXmin() + this->xSubOffset);
198        break;
199      case X2:
200        column.printEntry(stream,this->getXmax() + this->xSubOffset);
201        break;
202      case Y1:
203        column.printEntry(stream,this->getYmin() + this->ySubOffset);
204        break;
205      case Y2:
206        column.printEntry(stream,this->getYmax() + this->ySubOffset);
207        break;
208      case Z1:
209        column.printEntry(stream,this->getZmin() + this->zSubOffset);
210        break;
211      case Z2:
212        column.printEntry(stream,this->getZmax() + this->zSubOffset);
213        break;
214      case NPIX:
215        column.printEntry(stream,int(this->pixelArray.getSize()));
216        break;
217      case FLAG:
218        column.printEntry(stream,this->flagText);
219        break;
220      case XAV:
221        column.printEntry(stream,this->getXAverage() + this->xSubOffset);
222        break;
223      case YAV:
224        column.printEntry(stream,this->getYAverage() + this->ySubOffset);
225        break;
226      case ZAV:
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 UNKNOWN:
248      default:
249        break;
250      };
251  }
252  //--------------------------------------------------------------------
253
254  std::string Detection::outputLabelWCS()
255  {
256    /**
257     *  Prints to a std::string the WCS position and velocity
258     *  information of the Detection, as well as the ID number and any
259     *  flags.
260     *  Assumes the WCS parameters of the object have been calculated.
261     *  If they have not (given by the isWCS() function), then the
262     *  WCS-related outputs are left blank.
263     *  Returns the string.
264     */
265    std::stringstream ss;
266    ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
267    ss << this->name ;
268    if(this->getFlagText()!="-")
269      ss << " [" << this->getFlagText() << "]   ";
270    else ss<< "   ";
271    ss << std::setfill(' ');
272    ss << this->raS << ", ";
273    ss << this->decS;
274    if(this->specOK){
275      ss << std::setprecision(this->velPrec);
276      ss.setf(std::ios::fixed);
277      ss << ", " << this->vel << " " << this->specUnits;
278    }
279
280    return ss.str();
281
282  }
283  //--------------------------------------------------------------------
284
285  std::string Detection::outputLabelFluxes()
286  {
287    /**
288     *  Prints to a std::string the fluxes of the object, both
289     *  integrated/total and peak, as well as the peak S/N value.
290     *  Assumes the WCS parameters of the object have been calculated.
291     *  If they have not (given by the isWCS() function), then the ID
292     *  number and the total/peak/SNR values are returned.
293     *  /return The string.
294     */
295
296    std::stringstream ss;
297    ss.setf(std::ios::fixed);
298    if(this->flagWCS){
299      ss << std::setprecision(this->fintPrec);
300      ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits;
301      ss << std::setprecision(this->fpeakPrec);
302      ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits;
303      ss << std::setprecision(this->snrPrec);
304      ss << ", S/N\\dmax\\u=" << this->peakSNR;
305    }
306    else{
307      ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
308      ss << std::setprecision(this->fintPrec);
309      ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
310      ss << std::setprecision(this->fpeakPrec);
311      ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
312      ss << std::setprecision(this->snrPrec);
313      ss << ", S/N\\dmax\\u=" << this->peakSNR;
314    }
315    std::string output = ss.str();
316
317    return output;
318  }
319  //--------------------------------------------------------------------
320
321  std::string Detection::outputLabelWidths()
322  {
323    /**
324     *  Prints to a std::string the widths of the object in position
325     *  and velocity.
326     *  Assumes the WCS parameters of the object have been calculated.
327     *  If they have not (given by the isWCS() function), then a string of
328     *   length 0 is returned.
329     *  \returns The string.
330     */
331
332    std::string output;
333    if(this->flagWCS){
334      std::stringstream ss;
335      ss.setf(std::ios::fixed);
336      ss << std::setprecision(this->posPrec);
337      ss << "W\\d"              << this->lngtype  <<"\\u=" << this->raWidth;
338      ss << ", W\\d"            << this->lattype  <<"\\u=" << this->decWidth;
339      if(this->specOK){
340        ss << std::setprecision(this->velPrec);
341        ss << ", W\\d50\\u="    << this->w50      << " "   << this->specUnits;
342        ss << ", W\\d20\\u="    << this->w20      << " "   << this->specUnits;
343        ss << ", W\\dVel\\u="   << this->velWidth << " "   << this->specUnits;
344      }
345      output = ss.str();
346    }
347    else output = this->outputLabelFluxes();
348
349    return output;
350  }
351  //--------------------------------------------------------------------
352
353  std::string Detection::outputLabelPix()
354  {
355    /**
356     *  Prints to a std::string the pixel centres and extents of a
357     *  detected object.  Returns the string.
358     */
359
360    std::stringstream ss;
361    ss.setf(std::ios::fixed);
362    ss << "Centre: ";
363    ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
364    ss <<"("       << this->getXcentre() + this->xSubOffset;
365    ss <<", "      << this->getYcentre() + this->ySubOffset;
366    ss <<", "      << this->getZcentre() + this->zSubOffset << ")";
367    ss <<", Size: "<< this->pixelArray.getSize() << " voxels,  ";
368    ss <<"Range: [";
369    ss <<             this->getXmin() + this->xSubOffset
370       <<":"       << this->getXmax() + this->xSubOffset;
371    ss <<", "      << this->getYmin() + this->ySubOffset
372       <<":"       << this->getYmax() + this->ySubOffset;
373    if(this->specOK){
374      ss <<", "      << this->getZmin() + this->zSubOffset
375         <<":"       << this->getZmax() + this->zSubOffset;
376    }
377    ss<< "]";
378 
379    return ss.str();
380  }
381
382
383}
Note: See TracBrowser for help on using the repository browser.