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

Last change on this file since 1052 was 1047, checked in by MatthewWhiting, 12 years ago

Using an enumeration rather than strings to handle the selection of the output mode for writing

File size: 12.7 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, Column::DESTINATION 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, Column::DESTINATION 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 Column::DESTINATION label 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->specOK) column.printEntry(stream,this->w50);
161        else column.printEntry(stream,0.);
162        break;
163      case W20:
164        if(this->specOK) column.printEntry(stream,this->w20);
165        else column.printEntry(stream,0.);
166        break;
167      case WVEL:
168        if(this->specOK) column.printEntry(stream,this->velWidth);
169        else column.printEntry(stream,0.);
170        break;
171      case FINT:
172        column.printEntry(stream,this->intFlux);
173        break;
174      case FTOT:
175        column.printEntry(stream,this->totalFlux);
176        break;
177      case FPEAK:
178        column.printEntry(stream,this->peakFlux);
179        break;
180      case SNRPEAK:
181        column.printEntry(stream,this->peakSNR);
182        break;
183      case X1:
184        column.printEntry(stream,this->getXmin() + this->xSubOffset);
185        break;
186      case X2:
187        column.printEntry(stream,this->getXmax() + this->xSubOffset);
188        break;
189      case Y1:
190        column.printEntry(stream,this->getYmin() + this->ySubOffset);
191        break;
192      case Y2:
193        column.printEntry(stream,this->getYmax() + this->ySubOffset);
194        break;
195      case Z1:
196        column.printEntry(stream,this->getZmin() + this->zSubOffset);
197        break;
198      case Z2:
199        column.printEntry(stream,this->getZmax() + this->zSubOffset);
200        break;
201      case NPIX:
202        column.printEntry(stream,int(this->getSize()));
203        break;
204      case FLAG:
205        column.printEntry(stream,this->flagText);
206        break;
207      case XAV:
208        column.printEntry(stream,this->getXaverage() + this->xSubOffset);
209        break;
210      case YAV:
211        column.printEntry(stream,this->getYaverage() + this->ySubOffset);
212        break;
213      case ZAV:
214        column.printEntry(stream,this->getZaverage() + this->zSubOffset);
215        break;
216      case XCENT:
217        column.printEntry(stream,this->getXCentroid() + this->xSubOffset);
218        break;
219      case YCENT:
220        column.printEntry(stream,this->getYCentroid() + this->ySubOffset);
221        break;
222      case ZCENT:
223        column.printEntry(stream,this->getZCentroid() + this->zSubOffset);
224        break;
225      case XPEAK:
226        column.printEntry(stream,this->getXPeak() + this->xSubOffset);
227        break;
228      case YPEAK:
229        column.printEntry(stream,this->getYPeak() + this->ySubOffset);
230        break;
231      case ZPEAK:
232        column.printEntry(stream,this->getZPeak() + this->zSubOffset);
233        break;
234      case NUMCH:
235        column.printEntry(stream,this->getMaxAdjacentChannels());
236        break;
237      case SPATSIZE:
238        column.printEntry(stream,int(this->getSpatialSize()));
239        break;
240      case UNKNOWN:
241      default:
242        break;
243      };
244  }
245  //--------------------------------------------------------------------
246
247  std::string Detection::outputLabelWCS()
248  {
249    /// @details
250    ///  Prints to a std::string the WCS position and velocity
251    ///  information of the Detection, as well as the ID number and any
252    ///  flags.
253    ///  Assumes the WCS parameters of the object have been calculated.
254    ///  If they have not (given by the isWCS() function), then the
255    ///  WCS-related outputs are left blank.
256    ///  Returns the string.
257
258    std::stringstream ss;
259    ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
260    ss << this->name ;
261    if(this->getFlagText()!="-")
262      ss << " [" << this->getFlagText() << "]   ";
263    else ss<< "   ";
264    ss << std::setfill(' ');
265    ss << this->raS << ", ";
266    ss << this->decS;
267    if(this->specOK){
268      ss << std::setprecision(this->velPrec);
269      ss.setf(std::ios::fixed);
270      ss << ", " << this->vel << " " << this->specUnits;
271    }
272
273    return ss.str();
274
275  }
276  //--------------------------------------------------------------------
277
278  std::string Detection::outputLabelFluxes()
279  {
280    /// @details
281    ///  Prints to a std::string the fluxes of the object, both
282    ///  integrated/total and peak, as well as the peak S/N value.
283    ///  Assumes the WCS parameters of the object have been calculated.
284    ///  If they have not (given by the isWCS() function), then the ID
285    ///  number and the total/peak/SNR values are returned.
286    ///  /return The string.
287
288    std::stringstream ss;
289    ss.setf(std::ios::fixed);
290    if(this->flagWCS){
291      ss << std::setprecision(this->fintPrec);
292      ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits;
293      ss << std::setprecision(this->fpeakPrec);
294      ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits;
295      ss << std::setprecision(this->snrPrec);
296      ss << ", S/N\\dmax\\u=" << this->peakSNR;
297    }
298    else{
299      ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
300      ss << std::setprecision(this->fintPrec);
301      ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
302      ss << std::setprecision(this->fpeakPrec);
303      ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
304      ss << std::setprecision(this->snrPrec);
305      ss << ", S/N\\dmax\\u=" << this->peakSNR;
306    }
307    std::string output = ss.str();
308
309    return output;
310  }
311  //--------------------------------------------------------------------
312
313  std::string Detection::outputLabelWidths()
314  {
315    /// @details
316    ///  Prints to a std::string the widths of the object in position
317    ///  and velocity.
318    ///  Assumes the WCS parameters of the object have been calculated.
319    ///  If they have not (given by the isWCS() function), then a string of
320    ///   length 0 is returned.
321    ///  \returns The string.
322
323    std::string output;
324    if(this->flagWCS){
325      std::stringstream ss;
326      ss.setf(std::ios::fixed);
327      ss << std::setprecision(this->posPrec);
328      ss << "W\\d"              << this->lngtype  <<"\\u=" << this->raWidth;
329      ss << ", W\\d"            << this->lattype  <<"\\u=" << this->decWidth;
330      if(this->specOK){
331        ss << std::setprecision(this->velPrec);
332        ss << ", W\\d50\\u="    << this->w50      << " "   << this->specUnits;
333        ss << ", W\\d20\\u="    << this->w20      << " "   << this->specUnits;
334        ss << ", W\\d"<<this->specType<<"\\u="   << this->velWidth << " "   << this->specUnits;
335      }
336      output = ss.str();
337    }
338    else output = this->outputLabelFluxes();
339
340    return output;
341  }
342  //--------------------------------------------------------------------
343
344  std::string Detection::outputLabelPix()
345  {
346    /// @details
347    ///  Prints to a std::string the pixel centres and extents of a
348    ///  detected object.  Returns the string.
349
350    std::stringstream ss;
351    ss.setf(std::ios::fixed);
352    ss << "Centre: ";
353    ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
354    ss <<"("       << this->getXcentre() + this->xSubOffset;
355    ss <<", "      << this->getYcentre() + this->ySubOffset;
356    ss <<", "      << this->getZcentre() + this->zSubOffset << ")";
357//     ss <<", Size: "<< this->pixelArray.getSize() << " voxels,  ";
358    ss <<", Size: "<< this->getSize() << " voxels,  ";
359    ss <<"Range: [";
360    ss <<             this->getXmin() + this->xSubOffset
361       <<":"       << this->getXmax() + this->xSubOffset;
362    ss <<", "      << this->getYmin() + this->ySubOffset
363       <<":"       << this->getYmax() + this->ySubOffset;
364    if(this->specOK){
365      ss <<", "      << this->getZmin() + this->zSubOffset
366         <<":"       << this->getZmax() + this->zSubOffset;
367    }
368    ss<< "]";
369 
370    return ss.str();
371  }
372
373
374}
Note: See TracBrowser for help on using the repository browser.