source: tags/release-1.1.4/src/Detection/outputDetection.cc @ 1441

Last change on this file since 1441 was 393, checked in by MatthewWhiting, 17 years ago

Fixed up headers for trunk as well.

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