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

Last change on this file since 221 was 221, checked in by Matthew Whiting, 17 years ago

More documentation being added to source code, with a new file (src/Utils/Hanning.cc) added as well.

File size: 8.7 KB
Line 
1#include <iostream>
2#include <sstream>
3#include <fstream>
4#include <iomanip>
5#include <string>
6#include <vector>
7#include <duchamp.hh>
8#include <param.hh>
9#include <Detection/detection.hh>
10#include <Cubes/cubes.hh>
11#include <Utils/utils.hh>
12#include <Detection/columns.hh>
13
14using namespace Column;
15
16void Detection::outputDetectionTextHeader(std::ostream &stream,
17                                          vector<Col> columns)
18{
19  /**
20   *  Prints to a stream the column headers to match the output
21   *  generated by outputDetectionText or outputDetectionTextWCS
22   *  The exact columns depend on the vector<Col>.
23   * \param stream Where to print.
24   * \param columns The set of Columns::Col objects that define the columns to be printed.
25   */
26
27  vector<Col> local = columns;
28  if(local.size()==Column::numColumns){
29    vector <Col>::iterator iter;
30    if(this->flagWCS) iter = local.begin() + FTOT;
31    else iter = local.begin() + FINT;
32    local.erase(iter);
33  }
34
35  stream << std::setfill(' ');
36  for(int i=0;i<local.size();i++) local[i].printDash(stream);
37  stream << std::endl;
38  for(int i=0;i<local.size();i++) local[i].printTitle(stream);
39  stream << std::endl;
40  for(int i=0;i<local.size();i++) local[i].printUnits(stream);
41  stream << std::endl;
42  for(int i=0;i<local.size();i++) local[i].printDash(stream);
43  stream << std::endl;
44}
45//--------------------------------------------------------------------
46
47void Detection::outputDetectionTextWCS(std::ostream &stream,
48                                       vector<Col> columns)
49{
50  /**
51   * outputDetectionTextWCS
52   *  Prints to a stream the relevant details of a detected object,
53   *  including the WCS parameters, which need to have been calculated.
54   *  If they have not (given by the isWCS() function), then the
55   *  WCS-related outputs are left blank.
56   * \param stream Where to print.
57   * \param columns The set of Columns::Col objects that define the columns to be printed.
58   */
59
60  if(columns.size()!=Column::numColumns){
61    std::stringstream errmsg;
62    errmsg << "columnSet used has wrong number of columns ("
63           << columns.size() << ")\nshould be "
64           << Column::numColumns << ".\n";
65    duchampError("outputDetectionTextWCS",errmsg.str());
66  }
67  else{
68    stream.setf(std::ios::fixed); 
69    columns[NUM].printEntry(stream,this->id);
70    columns[NAME].printEntry(stream,this->name);
71    columns[X].printEntry(stream,this->xcentre + this->xSubOffset);
72    columns[Y].printEntry(stream,this->ycentre + this->ySubOffset);
73    columns[Z].printEntry(stream,this->zcentre + this->zSubOffset);
74    if(this->flagWCS){
75      columns[RA].printEntry(stream,this->raS);
76      columns[DEC].printEntry(stream,this->decS);
77      columns[VEL].printEntry(stream,this->vel);
78      columns[WRA].printEntry(stream,this->raWidth);
79      columns[WDEC].printEntry(stream,this->decWidth);
80      columns[WVEL].printEntry(stream,this->velWidth);
81    }
82    else for(int i=RA;i<=WVEL;i++) columns[i].printBlank(stream);
83    if(this->flagWCS) columns[FINT].printEntry(stream,this->intFlux);
84    else columns[FTOT].printEntry(stream,this->totalFlux);
85    columns[FPEAK].printEntry(stream,this->peakFlux);
86    columns[SNRPEAK].printEntry(stream,this->peakSNR);
87    columns[X1].printEntry(stream,this->xmin + this->xSubOffset);
88    columns[X2].printEntry(stream,this->xmax + this->xSubOffset);
89    columns[Y1].printEntry(stream,this->ymin + this->ySubOffset);
90    columns[Y2].printEntry(stream,this->ymax + this->ySubOffset);
91    columns[Z1].printEntry(stream,this->zmin + this->zSubOffset);
92    columns[Z2].printEntry(stream,this->zmax + this->zSubOffset);
93    columns[NPIX].printEntry(stream,int(this->pix.size()));
94    columns[FLAG].printEntry(stream,this->flagText);
95    stream << std::endl;
96  }
97}
98//--------------------------------------------------------------------
99
100void Detection::outputDetectionText(std::ostream &stream,
101                                    vector<Col> columns, int idNumber)
102{
103  /**
104   * outputDetectionText
105   *  Print to a stream the relevant details of a detected object.
106   *  This does not include any WCS parameters, only pixel positions & extent,
107   *    and flux info (including peak SNR).
108   *  Also prints a counter, provided as an input.
109   * \param stream Where to print.
110   * \param columns The set of Columns::Col objects that define the columns to be printed.
111   * \param idNumber The number that acts as a counter in the first column.
112   */
113
114  if(columns.size()!=Column::numColumnsLog){
115    std::stringstream errmsg;
116    errmsg << "columnSet used has wrong number of columns ("
117           << columns.size() << ")\nshould be "
118           << Column::numColumnsLog <<".\n";
119    duchampError("outputDetectionText",errmsg.str());
120  }
121  else{
122   stream << std::setfill(' ');
123   stream.setf(std::ios::fixed); 
124   columns[lNUM].printEntry(stream,idNumber);
125   columns[lX].printEntry(stream,this->xcentre + this->xSubOffset);
126   columns[lY].printEntry(stream,this->ycentre + this->ySubOffset);
127   columns[lZ].printEntry(stream,this->zcentre + this->zSubOffset);
128   columns[lFTOT].printEntry(stream,this->totalFlux);
129   columns[lFPEAK].printEntry(stream,this->peakFlux);
130   columns[lSNRPEAK].printEntry(stream,this->peakSNR);
131   columns[lX1].printEntry(stream,this->xmin + this->xSubOffset);
132   columns[lX2].printEntry(stream,this->xmax + this->xSubOffset);
133   columns[lY1].printEntry(stream,this->ymin + this->ySubOffset);
134   columns[lY2].printEntry(stream,this->ymax + this->ySubOffset);
135   columns[lZ1].printEntry(stream,this->zmin + this->zSubOffset);
136   columns[lZ2].printEntry(stream,this->zmax + this->zSubOffset);
137   columns[lNPIX].printEntry(stream,this->pix.size());
138   stream<<std::endl;
139  }
140}
141//--------------------------------------------------------------------
142
143string Detection::outputLabelWCS()
144{
145  /**
146   *  Prints to a string the WCS position and velocity information of the
147   *   Detection, as well as the ID number and any flags.
148   *  Assumes the WCS parameters of the object have been calculated.
149   *  If they have not (given by the isWCS() function), then the WCS-related
150   *   outputs are left blank.
151   *  Returns the string.
152   */
153  std::stringstream ss;
154  ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
155  ss << this->name ;
156  if(this->getFlagText()!="")
157    ss << " [" << this->getFlagText() << "]   ";
158  else ss<< "   ";
159  ss << std::setfill(' ');
160  ss << this->raS << ", ";
161  ss << this->decS;
162  ss << std::setprecision(this->velPrec);
163  ss.setf(std::ios::fixed);
164  ss << ", " << this->vel << " " << this->specUnits;
165
166  return ss.str();
167
168}
169//--------------------------------------------------------------------
170
171string Detection::outputLabelInfo()
172{
173  /**
174   *  Prints to a string the widths of the object (in position and velocity),
175   *  as well as the flux information.
176   *  Assumes the WCS parameters of the object have been calculated.
177   *  If they have not (given by the isWCS() function), then the WCS-related
178   *   outputs are left blank.
179   *  Returns the string.
180   */
181
182  std::stringstream ss;
183  ss.setf(std::ios::fixed);
184  if(this->flagWCS){
185    ss << std::setprecision(this->posPrec);
186    ss << "w_"          << this->lngtype  <<"="    << this->raWidth;
187    ss << ", w_"        << this->lattype  <<"="    << this->decWidth;
188    ss << std::setprecision(this->velPrec);
189    ss << ", w_Vel="    << this->velWidth << " " << this->specUnits;
190    ss << std::setprecision(this->fintPrec);
191    ss << ", F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits;
192    ss << std::setprecision(this->fpeakPrec);
193    ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits;
194    ss << std::setprecision(this->snrPrec);
195    ss << ", S/N\\dmax\\u=" << this->peakSNR;
196  }
197  else{
198    ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
199    ss << std::setprecision(this->fintPrec);
200    ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
201    ss << std::setprecision(this->fpeakPrec);
202    ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
203    ss << std::setprecision(this->snrPrec);
204    ss << ", S/N\\dmax\\u=" << this->peakSNR;
205  }
206  string output = ss.str();
207
208  return output;
209}
210//--------------------------------------------------------------------
211
212string Detection::outputLabelPix()
213{
214  /**
215   *  Prints to a string the pixel centres and extents of a detected object.
216   *  Returns the string.
217   */
218
219  std::stringstream ss;
220  ss.setf(std::ios::fixed);
221  ss << "Centre: ";
222  ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
223  ss <<"("  << this->xcentre + this->xSubOffset;
224  ss <<", " << this->ycentre + this->ySubOffset;
225  ss <<", " << this->zcentre + this->zSubOffset << ")";
226  ss <<", Size: " << this->pix.size() << " voxels,  ";
227  ss <<"Range: ["<< this->xmin + this->xSubOffset
228     <<":"<< this->xmax + this->xSubOffset;
229  ss <<", "      << this->ymin + this->ySubOffset
230     <<":"<< this->ymax + this->ySubOffset;
231  ss <<", "      << this->zmin + this->zSubOffset
232     <<":"<< this->zmax + this->zSubOffset << "]";
233 
234  return ss.str();
235}
236
237
Note: See TracBrowser for help on using the repository browser.