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

Last change on this file since 1062 was 1061, checked in by MatthewWhiting, 12 years ago

Ticket #162 - A large refactoring of the Column-related code. Columns have moved to Outputs, and in a new namespace Catalogues. The interface has changed, using strings to record the type rather
than the enum. Also included is a new class CatalogueSpecification?, that is designed to hold a collection of Columns. This is not yet implemented - everything still uses the full & log column
vectors, and the code still passes the verification script.

File size: 12.8 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/Outputs/columns.hh>
40#include <duchamp/Utils/feedback.hh>
41
42namespace duchamp
43{
44
45  void outputTableHeader(std::ostream &stream, std::vector<Catalogues::Column> columns, Catalogues::DESTINATION tableType, bool flagWCS)
46  {
47    /// @details
48    ///  Prints the header row for a table of detections. The columns
49    ///  that are included depend on the value of tableType, according
50    ///  to the Column::doCol() function. The format is a row of
51    ///  dashes, a row with column names, a row with column units, and
52    ///  another row of dashes.
53    /// \param stream Where the output is written
54    /// \param columns The vector list of Column objects
55    /// \param tableType A string saying what format to use: one of
56    /// "file", "log", "screen" or "votable" (although the latter
57    /// shouldn't be used with this function).
58    /// \param flagWCS A flag for use with Column::doCol(), specifying
59    /// whether to use FINT or FTOT.
60
61    std::vector<Catalogues::Column>::iterator col;
62    for(col=columns.begin();col<columns.end();col++)
63      if(col->doCol(tableType,flagWCS)) col->printDash(stream);
64    stream << "\n";
65    for(col=columns.begin();col<columns.end();col++)
66      if(col->doCol(tableType,flagWCS)) col->printTitle(stream);
67    stream << "\n";
68    for(col=columns.begin();col<columns.end();col++)
69      if(col->doCol(tableType,flagWCS)) col->printUnits(stream);
70    stream << "\n";
71    for(col=columns.begin();col<columns.end();col++)
72      if(col->doCol(tableType,flagWCS)) col->printDash(stream);
73    stream << "\n";
74
75  }
76  //--------------------------------------------------------------------
77
78  void Detection::printTableRow(std::ostream &stream, std::vector<Catalogues::Column> columns, Catalogues::DESTINATION tableType)
79  {
80    /// @details
81    ///  Print a row of values for the current Detection into an output
82    ///  table. Columns are printed according to the tableType string,
83    ///  using the Column::doCol() function as a determinant.
84    /// \param stream Where the output is written
85    /// \param columns The vector list of Column objects
86    /// \param tableType A Catalogues::DESTINATION label saying what format to use: one of
87    /// FILE, LOG, SCREEN or VOTABLE (although the latter
88    /// shouldn't be used with this function).
89
90    stream.setf(std::ios::fixed); 
91    std::vector<Catalogues::Column>::iterator col;
92    for(col=columns.begin();col<columns.end();col++)
93      if(col->doCol(tableType,this->flagWCS)) this->printTableEntry(stream, *col);
94     
95    stream << "\n";
96
97  }
98  //--------------------------------------------------------------------
99
100  void Detection::printTableEntry(std::ostream &stream, Catalogues::Column column)
101  {
102    /// @details
103    ///  Print a single value into an output table. The Detection's
104    ///  correct value is extracted according to the Catalogues::COLNAME
105    ///  key in the column given.
106    /// \param stream Where the output is written
107    /// \param column The Column object defining the formatting.
108
109    std::string type=column.type();
110
111    if(type=="NUM") column.printEntry(stream,this->id);
112    else if(type=="NAME") column.printEntry(stream,this->name);
113    else if(type=="X") column.printEntry(stream,this->getXcentre() + this->xSubOffset);
114    else if(type=="Y") column.printEntry(stream,this->getYcentre() + this->ySubOffset);
115    else if(type=="Z") column.printEntry(stream,this->getZcentre() + this->zSubOffset);
116    else if(type=="RA"){
117      if(this->flagWCS) column.printEntry(stream,this->raS);
118      else column.printBlank(stream);
119    }
120    else if(type=="DEC"){
121      if(this->flagWCS) column.printEntry(stream,this->decS);
122      else column.printBlank(stream);
123    }
124    else if(type=="RAJD"){
125      if(this->flagWCS) column.printEntry(stream,this->ra);
126      else column.printBlank(stream);
127    }
128    else if(type=="DECJD"){
129      if(this->flagWCS) column.printEntry(stream,this->dec);
130      else column.printBlank(stream);
131    }
132    else if(type=="VEL"){
133      if(this->flagWCS) {
134        if(this->specOK) column.printEntry(stream,this->vel);
135        else column.printEntry(stream,0.);
136      }
137      else column.printBlank(stream);
138    }
139    else if(type=="WRA"){
140      if(this->flagWCS) column.printEntry(stream,this->raWidth);
141      else column.printBlank(stream);
142    }
143    else if(type=="WDEC"){
144      if(this->flagWCS) column.printEntry(stream,this->decWidth);
145      else column.printBlank(stream);
146    }
147    else if(type=="W50"){
148      if(this->specOK) column.printEntry(stream,this->w50);
149      else column.printEntry(stream,0.);
150    }
151    else if(type=="W20"){
152      if(this->specOK) column.printEntry(stream,this->w20);
153      else column.printEntry(stream,0.);
154    }
155    else if(type=="WVEL"){
156      if(this->specOK) column.printEntry(stream,this->velWidth);
157      else column.printEntry(stream,0.);
158    }
159    else if(type=="FINT") column.printEntry(stream,this->intFlux);
160    else if(type=="FTOT") column.printEntry(stream,this->totalFlux);
161    else if(type=="FPEAK") column.printEntry(stream,this->peakFlux);
162    else if(type=="SNRPEAK") column.printEntry(stream,this->peakSNR);
163    else if(type=="X1") column.printEntry(stream,this->getXmin() + this->xSubOffset);
164    else if(type=="X2") column.printEntry(stream,this->getXmax() + this->xSubOffset);
165    else if(type=="Y1") column.printEntry(stream,this->getYmin() + this->ySubOffset);
166    else if(type=="Y2") column.printEntry(stream,this->getYmax() + this->ySubOffset);
167    else if(type=="Z1") column.printEntry(stream,this->getZmin() + this->zSubOffset);
168    else if(type=="Z2") column.printEntry(stream,this->getZmax() + this->zSubOffset);
169    else if(type=="NPIX") column.printEntry(stream,int(this->getSize()));
170    else if(type=="FLAG") column.printEntry(stream,this->flagText);
171    else if(type=="XAV") column.printEntry(stream,this->getXaverage() + this->xSubOffset);
172    else if(type=="YAV") column.printEntry(stream,this->getYaverage() + this->ySubOffset);
173    else if(type=="ZAV") column.printEntry(stream,this->getZaverage() + this->zSubOffset);
174    else if(type=="XCENT") column.printEntry(stream,this->getXCentroid() + this->xSubOffset);
175    else if(type=="YCENT") column.printEntry(stream,this->getYCentroid() + this->ySubOffset);
176    else if(type=="ZCENT") column.printEntry(stream,this->getZCentroid() + this->zSubOffset);
177    else if(type=="XPEAK") column.printEntry(stream,this->getXPeak() + this->xSubOffset);
178    else if(type=="YPEAK") column.printEntry(stream,this->getYPeak() + this->ySubOffset);
179    else if(type=="ZPEAK") column.printEntry(stream,this->getZPeak() + this->zSubOffset);
180    else if(type=="NUMCH") column.printEntry(stream,this->getMaxAdjacentChannels());
181    else if(type=="SPATSIZE") column.printEntry(stream,int(this->getSpatialSize()));
182
183  }
184  //--------------------------------------------------------------------
185
186  std::string Detection::outputLabelWCS()
187  {
188    /// @details
189    ///  Prints to a std::string the WCS position and velocity
190    ///  information of the Detection, as well as the ID number and any
191    ///  flags.
192    ///  Assumes the WCS parameters of the object have been calculated.
193    ///  If they have not (given by the isWCS() function), then the
194    ///  WCS-related outputs are left blank.
195    ///  Returns the string.
196
197    std::stringstream ss;
198    ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
199    ss << this->name ;
200    if(this->getFlagText()!="-")
201      ss << " [" << this->getFlagText() << "]   ";
202    else ss<< "   ";
203    ss << std::setfill(' ');
204    ss << this->raS << ", ";
205    ss << this->decS;
206    if(this->specOK){
207      ss << std::setprecision(this->velPrec);
208      ss.setf(std::ios::fixed);
209      ss << ", " << this->vel << " " << this->specUnits;
210    }
211
212    return ss.str();
213
214  }
215  //--------------------------------------------------------------------
216
217  std::string Detection::outputLabelFluxes()
218  {
219    /// @details
220    ///  Prints to a std::string the fluxes of the object, both
221    ///  integrated/total and peak, as well as the peak S/N value.
222    ///  Assumes the WCS parameters of the object have been calculated.
223    ///  If they have not (given by the isWCS() function), then the ID
224    ///  number and the total/peak/SNR values are returned.
225    ///  /return The string.
226
227    std::stringstream ss;
228    ss.setf(std::ios::fixed);
229    if(this->flagWCS){
230      ss << std::setprecision(this->fintPrec);
231      ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits;
232      ss << std::setprecision(this->fpeakPrec);
233      ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits;
234      ss << std::setprecision(this->snrPrec);
235      ss << ", S/N\\dmax\\u=" << this->peakSNR;
236    }
237    else{
238      ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
239      ss << std::setprecision(this->fintPrec);
240      ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
241      ss << std::setprecision(this->fpeakPrec);
242      ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
243      ss << std::setprecision(this->snrPrec);
244      ss << ", S/N\\dmax\\u=" << this->peakSNR;
245    }
246    std::string output = ss.str();
247
248    return output;
249  }
250  //--------------------------------------------------------------------
251
252  std::string Detection::outputLabelWidths()
253  {
254    /// @details
255    ///  Prints to a std::string the widths of the object in position
256    ///  and velocity.
257    ///  Assumes the WCS parameters of the object have been calculated.
258    ///  If they have not (given by the isWCS() function), then a string of
259    ///   length 0 is returned.
260    ///  \returns The string.
261
262    std::string output;
263    if(this->flagWCS){
264      std::stringstream ss;
265      ss.setf(std::ios::fixed);
266      ss << std::setprecision(this->posPrec);
267      ss << "W\\d"              << this->lngtype  <<"\\u=" << this->raWidth;
268      ss << ", W\\d"            << this->lattype  <<"\\u=" << this->decWidth;
269      if(this->specOK){
270        ss << std::setprecision(this->velPrec);
271        ss << ", W\\d50\\u="    << this->w50      << " "   << this->specUnits;
272        ss << ", W\\d20\\u="    << this->w20      << " "   << this->specUnits;
273        ss << ", W\\d"<<this->specType<<"\\u="   << this->velWidth << " "   << this->specUnits;
274      }
275      output = ss.str();
276    }
277    else output = this->outputLabelFluxes();
278
279    return output;
280  }
281  //--------------------------------------------------------------------
282
283  std::string Detection::outputLabelPix()
284  {
285    /// @details
286    ///  Prints to a std::string the pixel centres and extents of a
287    ///  detected object.  Returns the string.
288
289    std::stringstream ss;
290    ss.setf(std::ios::fixed);
291    ss << "Centre: ";
292    ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
293    ss <<"("       << this->getXcentre() + this->xSubOffset;
294    ss <<", "      << this->getYcentre() + this->ySubOffset;
295    ss <<", "      << this->getZcentre() + this->zSubOffset << ")";
296//     ss <<", Size: "<< this->pixelArray.getSize() << " voxels,  ";
297    ss <<", Size: "<< this->getSize() << " voxels,  ";
298    ss <<"Range: [";
299    ss <<             this->getXmin() + this->xSubOffset
300       <<":"       << this->getXmax() + this->xSubOffset;
301    ss <<", "      << this->getYmin() + this->ySubOffset
302       <<":"       << this->getYmax() + this->ySubOffset;
303    if(this->specOK){
304      ss <<", "      << this->getZmin() + this->zSubOffset
305         <<":"       << this->getZmax() + this->zSubOffset;
306    }
307    ss<< "]";
308 
309    return ss.str();
310  }
311
312
313}
Note: See TracBrowser for help on using the repository browser.