source: tags/release-1.1.5/src/Detection/outputDetection.cc @ 1441

Last change on this file since 1441 was 441, checked in by MatthewWhiting, 16 years ago

Cleaning up, and commenting.

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