source: trunk/src/Detection/outputDetection.cc

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

Expanding the VOTable output so that it includes almost all of what is in the results file (not the string RA/DEC nor the Ftot/eFtot). Also adding in Nchan & Nspatpix, and renaming Npix to Nvoxels (and removing the units string [pix] for Nvoxels).

File size: 12.0 KB
RevLine 
[301]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// -----------------------------------------------------------------------
[3]29#include <iostream>
30#include <sstream>
31#include <fstream>
32#include <iomanip>
33#include <string>
[103]34#include <vector>
[393]35#include <duchamp/duchamp.hh>
36#include <duchamp/Detection/detection.hh>
37#include <duchamp/Cubes/cubes.hh>
38#include <duchamp/Utils/utils.hh>
[1061]39#include <duchamp/Outputs/columns.hh>
[1064]40#include <duchamp/Outputs/CatalogueSpecification.hh>
[393]41#include <duchamp/Utils/feedback.hh>
[3]42
[378]43namespace duchamp
[3]44{
45
[1064]46  void Detection::printTableRow(std::ostream &stream, Catalogues::CatalogueSpecification columns, Catalogues::DESTINATION tableType)
[440]47  {
[528]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
[1061]54    /// \param tableType A Catalogues::DESTINATION label saying what format to use: one of
[1047]55    /// FILE, LOG, SCREEN or VOTABLE (although the latter
[528]56    /// shouldn't be used with this function).
[439]57
[440]58    stream.setf(std::ios::fixed); 
[1064]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    }
[440]62    stream << "\n";
63
64  }
[441]65  //--------------------------------------------------------------------
[440]66
[1061]67  void Detection::printTableEntry(std::ostream &stream, Catalogues::Column column)
[440]68  {
[528]69    /// @details
70    ///  Print a single value into an output table. The Detection's
[1061]71    ///  correct value is extracted according to the Catalogues::COLNAME
[528]72    ///  key in the column given.
73    /// \param stream Where the output is written
74    /// \param column The Column object defining the formatting.
[440]75
[1061]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);
[1042]102        else column.printEntry(stream,0.);
[1061]103      }
104      else column.printBlank(stream);
105    }
[1131]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);
[1061]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);
[1152]130    else if(type=="FINTERR") column.printEntry(stream,this->eIntFlux);
[1061]131    else if(type=="FTOT") column.printEntry(stream,this->totalFlux);
[1153]132    else if(type=="FTOTERR") column.printEntry(stream,this->eTotalFlux);
[1061]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);
[1273]141    else if(type=="NVOX") column.printEntry(stream,int(this->getSize()));
142    else if(type=="NUMCH") column.printEntry(stream,this->getMaxAdjacentChannels());
143    else if(type=="SPATSIZE") column.printEntry(stream,int(this->getSpatialSize()));
[1061]144    else if(type=="FLAG") column.printEntry(stream,this->flagText);
145    else if(type=="XAV") column.printEntry(stream,this->getXaverage() + this->xSubOffset);
146    else if(type=="YAV") column.printEntry(stream,this->getYaverage() + this->ySubOffset);
147    else if(type=="ZAV") column.printEntry(stream,this->getZaverage() + this->zSubOffset);
148    else if(type=="XCENT") column.printEntry(stream,this->getXCentroid() + this->xSubOffset);
149    else if(type=="YCENT") column.printEntry(stream,this->getYCentroid() + this->ySubOffset);
150    else if(type=="ZCENT") column.printEntry(stream,this->getZCentroid() + this->zSubOffset);
151    else if(type=="XPEAK") column.printEntry(stream,this->getXPeak() + this->xSubOffset);
152    else if(type=="YPEAK") column.printEntry(stream,this->getYPeak() + this->ySubOffset);
153    else if(type=="ZPEAK") column.printEntry(stream,this->getZPeak() + this->zSubOffset);
154
[440]155  }
[378]156  //--------------------------------------------------------------------
[265]157
[378]158  std::string Detection::outputLabelWCS()
159  {
[528]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
[378]169    std::stringstream ss;
170    ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
171    ss << this->name ;
[511]172    if(this->getFlagText()!="-")
[378]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    }
[300]183
[378]184    return ss.str();
[300]185
[378]186  }
187  //--------------------------------------------------------------------
[265]188
[378]189  std::string Detection::outputLabelFluxes()
190  {
[528]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.
[378]198
199    std::stringstream ss;
200    ss.setf(std::ios::fixed);
[265]201    if(this->flagWCS){
[378]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;
[1158]206      if(this->peakSNR>0.){
207          ss << std::setprecision(this->snrPrec);
208          ss << ", S/N\\dmax\\u=" << this->peakSNR;
209      }
[265]210    }
[378]211    else{
212      ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
213      ss << std::setprecision(this->fintPrec);
214      ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
215      ss << std::setprecision(this->fpeakPrec);
216      ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
[1158]217      if(this->peakSNR>0.){
218          ss << std::setprecision(this->snrPrec);
219          ss << ", S/N\\dmax\\u=" << this->peakSNR;
220      }
[378]221    }
222    std::string output = ss.str();
[265]223
[378]224    return output;
[367]225  }
[378]226  //--------------------------------------------------------------------
[3]227
[1133]228  std::string Detection::outputLabelWidths(FitsHeader &head)
[378]229  {
[528]230    /// @details
231    ///  Prints to a std::string the widths of the object in position
232    ///  and velocity.
233    ///  Assumes the WCS parameters of the object have been calculated.
234    ///  If they have not (given by the isWCS() function), then a string of
235    ///   length 0 is returned.
236    ///  \returns The string.
[3]237
[378]238    std::string output;
239    if(this->flagWCS){
240      std::stringstream ss;
241      ss.setf(std::ios::fixed);
242      ss << std::setprecision(this->posPrec);
[1131]243      // ss << "W\\d"              << this->lngtype  <<"\\u=" << this->raWidth;
244      // ss << ", W\\d"            << this->lattype  <<"\\u=" << this->decWidth;
[1133]245      std::string pgunits,units=head.getShapeUnits();
246      if(units=="deg") pgunits="\\(0718)";
247      else if(units=="arcmin") pgunits="\\(0716)";
248      else if(units=="arcsec") pgunits="\\(0717)";
249      else pgunits="";
250      ss << this->majorAxis<<pgunits<<char(215)<<this->minorAxis<<pgunits;
[1131]251      ss <<", PA="<<this->posang<<"\\(0718)";
[378]252      if(this->specOK){
253        ss << std::setprecision(this->velPrec);
[464]254        ss << ", W\\d50\\u="    << this->w50      << " "   << this->specUnits;
255        ss << ", W\\d20\\u="    << this->w20      << " "   << this->specUnits;
[947]256        ss << ", W\\d"<<this->specType<<"\\u="   << this->velWidth << " "   << this->specUnits;
[378]257      }
258      output = ss.str();
259    }
260    else output = this->outputLabelFluxes();
[3]261
[378]262    return output;
[103]263  }
[378]264  //--------------------------------------------------------------------
[103]265
[378]266  std::string Detection::outputLabelPix()
267  {
[528]268    /// @details
269    ///  Prints to a std::string the pixel centres and extents of a
270    ///  detected object.  Returns the string.
[103]271
[282]272    std::stringstream ss;
273    ss.setf(std::ios::fixed);
[378]274    ss << "Centre: ";
275    ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
276    ss <<"("       << this->getXcentre() + this->xSubOffset;
277    ss <<", "      << this->getYcentre() + this->ySubOffset;
278    ss <<", "      << this->getZcentre() + this->zSubOffset << ")";
[570]279    ss <<", Size: "<< this->getSize() << " voxels,  ";
[378]280    ss <<"Range: [";
281    ss <<             this->getXmin() + this->xSubOffset
282       <<":"       << this->getXmax() + this->xSubOffset;
283    ss <<", "      << this->getYmin() + this->ySubOffset
284       <<":"       << this->getYmax() + this->ySubOffset;
[356]285    if(this->specOK){
[378]286      ss <<", "      << this->getZmin() + this->zSubOffset
287         <<":"       << this->getZmax() + this->zSubOffset;
[282]288    }
[378]289    ss<< "]";
290 
291    return ss.str();
[282]292  }
293
294
[3]295}
Note: See TracBrowser for help on using the repository browser.