source: tags/release-1.1/src/Detection/outputDetection.cc @ 1323

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

Minor corrections.

File size: 15.6 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.hh>
36#include <Detection/detection.hh>
37#include <Cubes/cubes.hh>
38#include <Utils/utils.hh>
39#include <Detection/columns.hh>
40
41using namespace Column;
42
43void Detection::outputDetectionTextHeader(std::ostream &stream,
44                                          std::vector<Column::Col> columns)
45{
46  /**
47   *  Prints to a stream the column headers to match the output
48   *  generated by outputDetectionText or outputDetectionTextWCS
49   *  The exact columns depend on the std::vector<Col>.
50   *
51   *  If the WCS is good, it will print the FINT column, otherwise the
52   *  FTOT column.
53   *
54   *  NOTE: It does not print out the 9 columns containing the three
55   *  different pixel centre options -- it stops after the FLAG
56   *  column.
57   *
58   * \param stream Where to print.
59   * \param columns The set of Columns::Col objects that define the
60   *                columns to be printed.
61   */
62
63  std::vector<Col> local = columns;
64  if(local.size()==Column::numColumns){
65    std::vector <Col>::iterator iter;
66    if(this->flagWCS)
67      iter = local.begin() + FTOT;
68    else
69      iter = local.begin() + FINT;
70    local.erase(iter);
71  }
72 
73  int size = local.size();
74  if(int(FLAG)<size) size = int(FLAG);
75
76  stream << std::setfill(' ');
77  for(int i=0;i<size;i++) local[i].printDash(stream);
78  stream << std::endl;
79  for(int i=0;i<size;i++) local[i].printTitle(stream);
80  stream << std::endl;
81  for(int i=0;i<size;i++) local[i].printUnits(stream);
82  stream << std::endl;
83  for(int i=0;i<size;i++) local[i].printDash(stream);
84  stream << std::endl;
85}
86//--------------------------------------------------------------------
87
88void Detection::outputDetectionTextWCS(std::ostream &stream,
89                                       std::vector<Column::Col> columns)
90{
91  /**
92   *  Prints to a stream the relevant details of a detected object,
93   *  including the WCS parameters, which need to have been
94   *  calculated.  If they have not (given by the isWCS() function),
95   *  then the WCS-related outputs are left blank.
96   *
97   *  Also, if the WCS is good, we print the FINT column, else the
98   *  FTOT column.
99   *
100   * \param stream Where to print.
101   * \param columns The set of Columns::Col objects that define the
102   *                columns to be printed.
103   */
104
105  if(columns.size()!=Column::numColumns){
106    std::stringstream errmsg;
107    errmsg << "columnSet used has wrong number of columns ("
108           << columns.size() << ")\nshould be "
109           << Column::numColumns << ".\n";
110    duchampError("outputDetectionTextWCS",errmsg.str());
111  }
112  else{
113    stream.setf(std::ios::fixed); 
114    columns[NUM].printEntry(stream,this->id);
115    columns[NAME].printEntry(stream,this->name);
116    columns[X].printEntry(stream,this->getXcentre() + this->xSubOffset);
117    columns[Y].printEntry(stream,this->getYcentre() + this->ySubOffset);
118    columns[Z].printEntry(stream,this->getZcentre() + this->zSubOffset);
119    if(this->flagWCS){
120      columns[RA].printEntry(stream,this->raS);
121      columns[DEC].printEntry(stream,this->decS);
122      columns[VEL].printEntry(stream,this->vel);
123      columns[WRA].printEntry(stream,this->raWidth);
124      columns[WDEC].printEntry(stream,this->decWidth);
125      columns[WVEL].printEntry(stream,this->velWidth);
126    }
127    else for(int i=RA;i<=WVEL;i++) columns[i].printBlank(stream);
128    if(this->flagWCS)
129      columns[FINT].printEntry(stream,this->intFlux);
130    else
131      columns[FTOT].printEntry(stream,this->totalFlux);
132    columns[FPEAK].printEntry(stream,this->peakFlux);
133    columns[SNRPEAK].printEntry(stream,this->peakSNR);
134    columns[X1].printEntry(stream,this->getXmin() + this->xSubOffset);
135    columns[X2].printEntry(stream,this->getXmax() + this->xSubOffset);
136    columns[Y1].printEntry(stream,this->getYmin() + this->ySubOffset);
137    columns[Y2].printEntry(stream,this->getYmax() + this->ySubOffset);
138    columns[Z1].printEntry(stream,this->getZmin() + this->zSubOffset);
139    columns[Z2].printEntry(stream,this->getZmax() + this->zSubOffset);
140    columns[NPIX].printEntry(stream,int(this->pixelArray.getSize()));
141    columns[FLAG].printEntry(stream,this->flagText);
142    stream << std::endl;
143  }
144}
145//--------------------------------------------------------------------
146
147void Detection::outputDetectionText(std::ostream &stream,
148                                    std::vector<Column::Col> columns,
149                                    int idNumber)
150{
151  /**
152   *  Print to a stream the relevant details of a detected object.
153   *  This does not include any WCS parameters, only pixel positions & extent,
154   *    and flux info (FTOT, FPEAK, SNRPEAK).
155   *  Also prints a counter, provided as an input.
156   *
157   * \param stream Where to print.
158   * \param columns The set of Columns::Col objects that define the
159   *    columns to be printed.
160   * \param idNumber The number that acts as a counter in the first column.
161   */
162
163  if(columns.size()!=Column::numColumnsLog){
164    std::stringstream errmsg;
165    errmsg << "columnSet used has wrong number of columns ("
166           << columns.size() << ")\nshould be "
167           << Column::numColumnsLog <<".\n";
168    duchampError("outputDetectionText",errmsg.str());
169  }
170  else{
171   stream << std::setfill(' ');
172   stream.setf(std::ios::fixed); 
173   columns[lNUM].printEntry(stream,idNumber);
174   columns[lX].printEntry(stream,this->getXcentre() + this->xSubOffset);
175   columns[lY].printEntry(stream,this->getYcentre() + this->ySubOffset);
176   columns[lZ].printEntry(stream,this->getZcentre() + this->zSubOffset);
177   columns[lFTOT].printEntry(stream,this->totalFlux);
178   columns[lFPEAK].printEntry(stream,this->peakFlux);
179   columns[lSNRPEAK].printEntry(stream,this->peakSNR);
180   columns[lX1].printEntry(stream,this->getXmin() + this->xSubOffset);
181   columns[lX2].printEntry(stream,this->getXmax() + this->xSubOffset);
182   columns[lY1].printEntry(stream,this->getYmin() + this->ySubOffset);
183   columns[lY2].printEntry(stream,this->getYmax() + this->ySubOffset);
184   columns[lZ1].printEntry(stream,this->getZmin() + this->zSubOffset);
185   columns[lZ2].printEntry(stream,this->getZmax() + this->zSubOffset);
186   columns[lNPIX].printEntry(stream,this->pixelArray.getSize());
187   stream<<std::endl;
188  }
189}
190//--------------------------------------------------------------------
191
192void Detection::outputDetectionTextHeaderFull(std::ostream &stream,
193                                              std::vector<Column::Col> columns)
194{
195  /**
196   *  Prints to a stream the column headers to match the output
197   *  generated by outputDetectionText or outputDetectionTextWCS
198   *  The exact columns depend on the std::vector<Col>.
199   *
200   *  NOTE: It prints all columns, including all the different pixel
201   *  centre options and all FLUX columns.
202   *
203   * \param stream Where to print.
204   * \param columns The set of Columns::Col objects that define the
205   * columns to be printed.
206   */
207
208  stream << std::setfill(' ');
209  for(int i=0;i<columns.size();i++) columns[i].printDash(stream);
210  stream << std::endl;
211  for(int i=0;i<columns.size();i++) columns[i].printTitle(stream);
212  stream << std::endl;
213  for(int i=0;i<columns.size();i++) columns[i].printUnits(stream);
214  stream << std::endl;
215  for(int i=0;i<columns.size();i++) columns[i].printDash(stream);
216  stream << std::endl;
217}
218//--------------------------------------------------------------------
219
220void Detection::outputDetectionTextWCSFull(std::ostream &stream,
221                                           std::vector<Column::Col> columns)
222{
223  /**
224   *  Prints to a stream the relevant details of a detected object,
225   *  including the WCS parameters, which need to have been calculated.
226   *  If they have not (given by the isWCS() function), then the
227   *  WCS-related outputs are left blank.
228   *  This function prints all the different versions of the centre
229   *  pixel values, and all different flux quantities.
230   * \param stream Where to print.
231   * \param columns The set of Columns::Col objects that define the
232   * columns to be printed.
233   */
234
235  if(columns.size()!=Column::numColumns){
236    std::stringstream errmsg;
237    errmsg << "columnSet used has wrong number of columns ("
238           << columns.size() << ")\nshould be "
239           << Column::numColumns << ".\n";
240    duchampError("outputDetectionTextWCS",errmsg.str());
241  }
242  else{
243    stream.setf(std::ios::fixed); 
244    columns[NUM].printEntry(stream,this->id);
245    columns[NAME].printEntry(stream,this->name);
246    columns[X].printEntry(stream,this->getXcentre() + this->xSubOffset);
247    columns[Y].printEntry(stream,this->getYcentre() + this->ySubOffset);
248    columns[Z].printEntry(stream,this->getZcentre() + this->zSubOffset);
249    if(this->flagWCS){
250      columns[RA].printEntry(stream,this->raS);
251      columns[DEC].printEntry(stream,this->decS);
252      columns[VEL].printEntry(stream,this->vel);
253      columns[WRA].printEntry(stream,this->raWidth);
254      columns[WDEC].printEntry(stream,this->decWidth);
255      columns[WVEL].printEntry(stream,this->velWidth);
256    }
257    else for(int i=RA;i<=WVEL;i++) columns[i].printBlank(stream);
258    columns[FINT].printEntry(stream,this->intFlux);
259    columns[FTOT].printEntry(stream,this->totalFlux);
260    columns[FPEAK].printEntry(stream,this->peakFlux);
261    columns[SNRPEAK].printEntry(stream,this->peakSNR);
262    columns[X1].printEntry(stream,this->getXmin() + this->xSubOffset);
263    columns[X2].printEntry(stream,this->getXmax() + this->xSubOffset);
264    columns[Y1].printEntry(stream,this->getYmin() + this->ySubOffset);
265    columns[Y2].printEntry(stream,this->getYmax() + this->ySubOffset);
266    columns[Z1].printEntry(stream,this->getZmin() + this->zSubOffset);
267    columns[Z2].printEntry(stream,this->getZmax() + this->zSubOffset);
268    columns[NPIX].printEntry(stream,int(this->pixelArray.getSize()));
269    columns[FLAG].printEntry(stream,this->flagText);
270    columns[XAV].printEntry(stream,this->getXAverage() + this->xSubOffset);
271    columns[YAV].printEntry(stream,this->getYAverage() + this->ySubOffset);
272    columns[ZAV].printEntry(stream,this->getZAverage() + this->zSubOffset);
273    columns[XCENT].printEntry(stream,this->getXCentroid() + this->xSubOffset);
274    columns[YCENT].printEntry(stream,this->getYCentroid() + this->ySubOffset);
275    columns[ZCENT].printEntry(stream,this->getZCentroid() + this->zSubOffset);
276    columns[XPEAK].printEntry(stream,this->getXPeak() + this->xSubOffset);
277    columns[YPEAK].printEntry(stream,this->getYPeak() + this->ySubOffset);
278    columns[ZPEAK].printEntry(stream,this->getZPeak() + this->zSubOffset);
279    stream << std::endl;
280  }
281}
282//--------------------------------------------------------------------
283
284std::string Detection::outputLabelWCS()
285{
286  /**
287   *  Prints to a std::string the WCS position and velocity
288   *  information of the Detection, as well as the ID number and any
289   *  flags.
290   *  Assumes the WCS parameters of the object have been calculated.
291   *  If they have not (given by the isWCS() function), then the
292   *  WCS-related outputs are left blank.
293   *  Returns the string.
294   */
295  std::stringstream ss;
296  ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
297  ss << this->name ;
298  if(this->getFlagText()!="")
299    ss << " [" << this->getFlagText() << "]   ";
300  else ss<< "   ";
301  ss << std::setfill(' ');
302  ss << this->raS << ", ";
303  ss << this->decS;
304  ss << std::setprecision(this->velPrec);
305  ss.setf(std::ios::fixed);
306  ss << ", " << this->vel << " " << this->specUnits;
307
308  return ss.str();
309
310}
311//--------------------------------------------------------------------
312
313std::string Detection::outputLabelFluxes()
314{
315  /**
316   *  Prints to a std::string the fluxes of the object, both
317   *  integrated/total and peak, as well as the peak S/N value.
318   *  Assumes the WCS parameters of the object have been calculated.
319   *  If they have not (given by the isWCS() function), then the ID
320   *  number and the total/peak/SNR values are returned.
321   *  /return The string.
322   */
323
324  std::stringstream ss;
325  ss.setf(std::ios::fixed);
326  if(this->flagWCS){
327    ss << std::setprecision(this->fintPrec);
328    ss << "F\\dint\\u=" << this->intFlux << " " << this->intFluxUnits;
329    ss << std::setprecision(this->fpeakPrec);
330    ss << ", F\\dpeak\\u=" << this->peakFlux << " " << this->fluxUnits;
331    ss << std::setprecision(this->snrPrec);
332    ss << ", S/N\\dmax\\u=" << this->peakSNR;
333  }
334  else{
335    ss << "#" << std::setfill('0') << std::setw(3) << this->id << ": ";
336    ss << std::setprecision(this->fintPrec);
337    ss << "F\\dtot\\u=" << this->totalFlux << this->fluxUnits;
338    ss << std::setprecision(this->fpeakPrec);
339    ss << ", F\\dpeak\\u=" << this->peakFlux << this->fluxUnits;
340    ss << std::setprecision(this->snrPrec);
341    ss << ", S/N\\dmax\\u=" << this->peakSNR;
342  }
343  std::string output = ss.str();
344
345  return output;
346}
347//--------------------------------------------------------------------
348
349std::string Detection::outputLabelWidths()
350{
351  /**
352   *  Prints to a std::string the widths of the object in position
353   *  and velocity.
354   *  Assumes the WCS parameters of the object have been calculated.
355   *  If they have not (given by the isWCS() function), then a string of
356   *   length 0 is returned.
357   *  \returns The string.
358   */
359
360  std::string output;
361  if(this->flagWCS){
362    std::stringstream ss;
363    ss.setf(std::ios::fixed);
364    ss << std::setprecision(this->posPrec);
365    ss << "w_"          << this->lngtype  <<"="    << this->raWidth;
366    ss << ", w_"        << this->lattype  <<"="    << this->decWidth;
367    if(this->numAxes>2){
368      ss << std::setprecision(this->velPrec);
369      ss << ", w_Vel="    << this->velWidth << " " << this->specUnits;
370    }
371    output = ss.str();
372  }
373  else output = this->outputLabelFluxes();
374
375  return output;
376}
377//--------------------------------------------------------------------
378
379std::string Detection::outputLabelPix()
380{
381  /**
382   *  Prints to a std::string the pixel centres and extents of a
383   *  detected object.  Returns the string.
384   */
385
386  std::stringstream ss;
387  ss.setf(std::ios::fixed);
388  ss << "Centre: ";
389  ss << std::setprecision(this->xyzPrec) << std::setfill(' ');
390  ss <<"("       << this->getXcentre() + this->xSubOffset;
391  ss <<", "      << this->getYcentre() + this->ySubOffset;
392  ss <<", "      << this->getZcentre() + this->zSubOffset << ")";
393  ss <<", Size: "<< this->pixelArray.getSize() << " voxels,  ";
394  ss <<"Range: ["<< this->getXmin() + this->xSubOffset
395     <<":"       << this->getXmax() + this->xSubOffset;
396  ss <<", "      << this->getYmin() + this->ySubOffset
397     <<":"       << this->getYmax() + this->ySubOffset;
398  ss <<", "      << this->getZmin() + this->zSubOffset
399     <<":"       << this->getZmax() + this->zSubOffset << "]";
400 
401  return ss.str();
402}
403
404
Note: See TracBrowser for help on using the repository browser.