source: tags/release-1.1.7/src/Detection/outputDetection.cc @ 1455

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

Changing the documentation comments to match the askapsoft style. Also have split ChanMap? and Object3D into separate files.

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