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

Last change on this file since 1153 was 1153, checked in by MatthewWhiting, 11 years ago

Ticket #173 - Doing the same for the error on the total flux. Also fixing the interface with the VOTable output, and improving the way the catalogue specification handles deleted columns.

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