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

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

Continuing Ticket #162 -- moving to the use of CatalogueSpecification?. Also fixing a bug where the VOTable column ID string was not being set (identified via the verification script!).

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