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

Last change on this file since 570 was 570, checked in by MatthewWhiting, 15 years ago

Merging the pixelmap-refactor changes back into the trunk.

File size: 12.9 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    /// @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 UNKNOWN:
248      default:
249        break;
250      };
251  }
252  //--------------------------------------------------------------------
253
254  std::string Detection::outputLabelWCS()
255  {
256    /// @details
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    /// @details
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    std::stringstream ss;
296    ss.setf(std::ios::fixed);
297    if(this->flagWCS){
298      ss << std::setprecision(this->fintPrec);
299      ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits;
300      ss << std::setprecision(this->fpeakPrec);
301      ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits;
302      ss << std::setprecision(this->snrPrec);
303      ss << ", S/N\\dmax\\u=" << this->peakSNR;
304    }
305    else{
306      ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
307      ss << std::setprecision(this->fintPrec);
308      ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
309      ss << std::setprecision(this->fpeakPrec);
310      ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
311      ss << std::setprecision(this->snrPrec);
312      ss << ", S/N\\dmax\\u=" << this->peakSNR;
313    }
314    std::string output = ss.str();
315
316    return output;
317  }
318  //--------------------------------------------------------------------
319
320  std::string Detection::outputLabelWidths()
321  {
322    /// @details
323    ///  Prints to a std::string the widths of the object in position
324    ///  and velocity.
325    ///  Assumes the WCS parameters of the object have been calculated.
326    ///  If they have not (given by the isWCS() function), then a string of
327    ///   length 0 is returned.
328    ///  \returns The string.
329
330    std::string output;
331    if(this->flagWCS){
332      std::stringstream ss;
333      ss.setf(std::ios::fixed);
334      ss << std::setprecision(this->posPrec);
335      ss << "W\\d"              << this->lngtype  <<"\\u=" << this->raWidth;
336      ss << ", W\\d"            << this->lattype  <<"\\u=" << this->decWidth;
337      if(this->specOK){
338        ss << std::setprecision(this->velPrec);
339        ss << ", W\\d50\\u="    << this->w50      << " "   << this->specUnits;
340        ss << ", W\\d20\\u="    << this->w20      << " "   << this->specUnits;
341        ss << ", W\\dVel\\u="   << this->velWidth << " "   << this->specUnits;
342      }
343      output = ss.str();
344    }
345    else output = this->outputLabelFluxes();
346
347    return output;
348  }
349  //--------------------------------------------------------------------
350
351  std::string Detection::outputLabelPix()
352  {
353    /// @details
354    ///  Prints to a std::string the pixel centres and extents of a
355    ///  detected object.  Returns the string.
356
357    std::stringstream ss;
358    ss.setf(std::ios::fixed);
359    ss << "Centre: ";
360    ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
361    ss <<"("       << this->getXcentre() + this->xSubOffset;
362    ss <<", "      << this->getYcentre() + this->ySubOffset;
363    ss <<", "      << this->getZcentre() + this->zSubOffset << ")";
364//     ss <<", Size: "<< this->pixelArray.getSize() << " voxels,  ";
365    ss <<", Size: "<< this->getSize() << " voxels,  ";
366    ss <<"Range: [";
367    ss <<             this->getXmin() + this->xSubOffset
368       <<":"       << this->getXmax() + this->xSubOffset;
369    ss <<", "      << this->getYmin() + this->ySubOffset
370       <<":"       << this->getYmax() + this->ySubOffset;
371    if(this->specOK){
372      ss <<", "      << this->getZmin() + this->zSubOffset
373         <<":"       << this->getZmax() + this->zSubOffset;
374    }
375    ss<< "]";
376 
377    return ss.str();
378  }
379
380
381}
Note: See TracBrowser for help on using the repository browser.